Skip to content

Commit 167d5a3

Browse files
committed
Use new Unicode conversion helper where appropriate
1 parent 724face commit 167d5a3

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

fly/types/string/detail/string_formatter.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,7 @@ void BasicStringFormatter<StringType, ParameterTypes...>::append_string(
601601
using unicode = BasicStringUnicode<string_like_type>;
602602
view_like_type view(value);
603603

604-
auto it = view.cbegin();
605-
const auto end = view.cend();
606-
607-
if (auto converted = unicode::template convert_encoding<StringType>(it, end); converted)
604+
if (auto converted = unicode::template convert_encoding<StringType>(view); converted)
608605
{
609606
m_buffer.append(*std::move(converted), 0, max_width);
610607
}

fly/types/string/detail/string_streamer.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,22 @@ template <typename T>
212212
void BasicStringStreamer<StringType>::stream_string(ostream_type &stream, T &&value)
213213
{
214214
using string_like_type = detail::is_like_supported_string_t<T>;
215-
using string_like_traits = BasicStringTraits<string_like_type>;
216215

217216
if constexpr (std::is_same_v<streamed_type, string_like_type>)
218217
{
219218
stream << value;
220219
}
221220
else
222221
{
222+
using string_like_traits = BasicStringTraits<string_like_type>;
223+
using string_like_view = typename string_like_traits::view_type;
223224
using unicode = BasicStringUnicode<string_like_type>;
224-
using streamer = BasicStringStreamer<streamed_type>;
225225

226-
typename string_like_traits::view_type view(std::forward<T>(value));
227-
auto it = view.cbegin();
228-
const auto end = view.cend();
226+
string_like_view view(std::forward<T>(value));
229227

230-
if (auto converted = unicode::template convert_encoding<streamed_type>(it, end); converted)
228+
if (auto converted = unicode::template convert_encoding<streamed_type>(view); converted)
231229
{
232-
streamer::stream_value(stream, *std::move(converted));
230+
stream << *std::move(converted);
233231
}
234232
}
235233
}

fly/types/string/string.hpp

+3-16
Original file line numberDiff line numberDiff line change
@@ -943,30 +943,17 @@ template <typename StringType>
943943
template <typename T>
944944
std::optional<T> BasicString<StringType>::convert(const StringType &value)
945945
{
946-
using U = std::decay_t<T>;
947-
948-
if constexpr (detail::is_supported_string_v<U>)
946+
if constexpr (detail::is_supported_string_v<T>)
949947
{
950-
auto it = value.cbegin();
951-
const auto end = value.cend();
952-
953-
if (auto result = unicode::template convert_encoding<U>(it, end); result)
954-
{
955-
return static_cast<T>(*result);
956-
}
957-
958-
return std::nullopt;
948+
return unicode::template convert_encoding<T>(value);
959949
}
960950
else if constexpr (std::is_same_v<char_type, char>)
961951
{
962952
return detail::BasicStringConverter<StringType, T>::convert(value);
963953
}
964954
else
965955
{
966-
auto it = value.cbegin();
967-
const auto end = value.cend();
968-
969-
if (auto result = unicode::template convert_encoding<std::string>(it, end); result)
956+
if (auto result = unicode::template convert_encoding<std::string>(value); result)
970957
{
971958
return detail::BasicStringConverter<std::string, T>::convert(*result);
972959
}

0 commit comments

Comments
 (0)