diff options
Diffstat (limited to 'third_party/nix/src/libutil/json.cc')
-rw-r--r-- | third_party/nix/src/libutil/json.cc | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/third_party/nix/src/libutil/json.cc b/third_party/nix/src/libutil/json.cc index 7965f4725ba4..c5f52ae8ef3f 100644 --- a/third_party/nix/src/libutil/json.cc +++ b/third_party/nix/src/libutil/json.cc @@ -7,28 +7,31 @@ namespace nix { void toJSON(std::ostream& str, const char* start, const char* end) { str << '"'; - for (auto i = start; i != end; i++) - if (*i == '\"' || *i == '\\') + for (auto i = start; i != end; i++) { + if (*i == '\"' || *i == '\\') { str << '\\' << *i; - else if (*i == '\n') + } else if (*i == '\n') { str << "\\n"; - else if (*i == '\r') + } else if (*i == '\r') { str << "\\r"; - else if (*i == '\t') + } else if (*i == '\t') { str << "\\t"; - else if (*i >= 0 && *i < 32) + } else if (*i >= 0 && *i < 32) { str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t)*i << std::dec; - else + } else { str << *i; + } + } str << '"'; } void toJSON(std::ostream& str, const char* s) { - if (!s) + if (!s) { str << "null"; - else + } else { toJSON(str, s, s + strlen(s)); + } } template <> |