Don't overescape wide strings

This commit is contained in:
Victor Zverovich
2021-08-19 17:25:16 -07:00
parent 11b07a56b2
commit f69a572538

View File

@@ -232,11 +232,11 @@ template <typename Char> inline bool is_printable_ascii(Char c) {
} }
template < template <
typename Char, typename OutputIt, typename Arg, typename Char, typename OutputIt, typename T,
FMT_ENABLE_IF(is_std_string_like<typename std::decay<Arg>::type>::value)> FMT_ENABLE_IF(is_std_string_like<typename std::decay<T>::type>::value)>
OutputIt write_range_entry(OutputIt out, const Arg& v) { OutputIt write_range_entry(OutputIt out, const T& str) {
*out++ = '"'; *out++ = '"';
for (Char c : basic_string_view<Char>(v)) { for (Char c : basic_string_view<Char>(str)) {
switch (c) { switch (c) {
case '\n': case '\n':
*out++ = '\\'; *out++ = '\\';
@@ -257,6 +257,7 @@ OutputIt write_range_entry(OutputIt out, const Arg& v) {
break; break;
default: default:
if (is_printable_ascii(c)) break; if (is_printable_ascii(c)) break;
if (sizeof(Char) != 1 && c >= 0x80) break;
out = format_to(out, "\\x{:02x}", c); out = format_to(out, "\\x{:02x}", c);
continue; continue;
} }