39 void write_string(std::ostream &out, std::string_view s,
bool json)
44 for (
size_t i = 0; i < s.size(); i++)
46 const uint8_t c = uint8_t(s[i]);
48 if (c < 0x20 || c == 0x7f)
62 else if (c ==
'?' && i > 0 && s[i - 1] ==
'?' && !json)
63 out.put(
'\\').put(
'?');
65 out.put(
'\\').put(
'"');
67 out.put(
'\\').put(
'\\');
68 else if (c >= 0xc2 && c <= 0xdf &&
70 (s[i + 1] & 0xc0) == 0x80)
75 else if ((c & 0xf0) == 0xe0 &&
77 (c != 0xe0 || uint8_t(s[i + 1]) >= 0xa0) &&
78 (c != 0xed || uint8_t(s[i + 1]) < 0xa0) &&
79 (s[i + 1] & 0xc0) == 0x80 &&
80 (s[i + 2] & 0xc0) == 0x80)
86 else if (c >= 0xf0 && c <= 0xf4 &&
88 (c != 0xf0 || uint8_t(s[i + 1]) >= 0x90) &&
89 (c != 0xf4 || uint8_t(s[i + 1]) < 0x90) &&
90 (s[i + 1] & 0xc0) == 0x80 &&
91 (s[i + 2] & 0xc0) == 0x80 &&
92 (s[i + 3] & 0xc0) == 0x80)