diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-11-03 20:27:41 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-11-03 20:27:41 +1100 |
| commit | f7499ccf45315a57b65f7c176ba23a8265ae01cf (patch) | |
| tree | f52003b20b462c00e50faa2dee37997eb11bbd17 /src/json.cc | |
| parent | 7577fa1b668ea81eb9b7b9af690a4161187129dd (diff) | |
Add support for 0-padding in format and replace uses of sprintf
Diffstat (limited to 'src/json.cc')
| -rw-r--r-- | src/json.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/json.cc b/src/json.cc index 3661ac80..82fc0f28 100644 --- a/src/json.cc +++ b/src/json.cc @@ -29,7 +29,7 @@ String to_json(StringView str) char buf[7] = {'\\', *next, 0}; if (*next >= 0 and *next <= 0x1F) - sprintf(buf, "\\u%04x", *next); + format_to(buf, "\\u{:04}", hex(*next)); res += buf; it = next+1; @@ -188,4 +188,11 @@ UnitTest test_json_parser{[]() } }}; +UnitTest test_to_json{[]() +{ + kak_assert(to_json(true) == "true"); + kak_assert(to_json(false) == "false"); + kak_assert(to_json(HashMap<String, Vector<int>>{{"foo", {1,2,3}}, {"\033", {3, 4, 5}}}) == R"({"foo": [1, 2, 3],"\u001b": [3, 4, 5]})"); +}}; + } |
