39 void write_string(std::ostream &out,
const std::string &s,
bool json)
44 for (
size_t i = 0; i < s.size(); i++)
46 const uint8_t c = uint8_t(s[i]);
51 if (c < 0x20 || c == 0x7f)
65 else if (c ==
'?' && i > 0 && s[i - 1] ==
'?' && !json)
66 out.put(
'\\').put(
'?');
68 out.put(
'\\').put(
'"');
70 out.put(
'\\').put(
'\\');
71 else if ((c & 0xe0) == 0xc0 &&
73 (s[i + 1] & 0xc0) == 0x80)
82 (uint8_t(s[i + 1]) & 0xa0) == 0xa0
87 else if ((c & 0xf0) == 0xe0 &&
89 (s[i + 1] & 0xc0) == 0x80 &&
90 (s[i + 2] & 0xc0) == 0x80)
96 else if ((c & 0xf8) == 0xf0 &&
98 (s[i + 1] & 0xc0) == 0x80 &&
99 (s[i + 2] & 0xc0) == 0x80 &&
100 (s[i + 3] & 0xc0) == 0x80)