1 #ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H
2 #define SIMDJSON_INTERNAL_JSONFORMATUTILS_H
11 class escape_json_string;
13 inline std::ostream&
operator<<(std::ostream& out,
const escape_json_string &str);
15 class escape_json_string {
17 escape_json_string(std::string_view _str) noexcept : str{_str} {}
18 operator std::string() const noexcept { std::stringstream s; s << *
this;
return s.str(); }
21 friend std::ostream&
operator<<(std::ostream& out,
const escape_json_string &unescaped);
24 inline std::ostream&
operator<<(std::ostream& out,
const escape_json_string &unescaped) {
25 for (
size_t i=0; i<unescaped.str.length(); i++) {
26 switch (unescaped.str[i]) {
49 if (
static_cast<unsigned char>(unescaped.str[i]) <= 0x1F) {
51 std::ios::fmtflags f(out.flags());
52 out <<
"\\u" << std::hex << std::setw(4) << std::setfill(
'0') << int(unescaped.str[i]);
55 out << unescaped.str[i];
We want to support argument-dependent lookup (ADL).
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.