From 644733c74efb8294d529e5282d4c6eba74bcbc04 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Tue, 26 Jul 2022 09:10:17 -0400 Subject: [PATCH] Add a static JsonEncodeString() method. Right now it just calls fprintf(), but in the future, it will properly encode a string for JSON output. --- src/Json.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Json.c b/src/Json.c index bcf0278..ac21fe9 100644 --- a/src/Json.c +++ b/src/Json.c @@ -248,6 +248,12 @@ JsonValueFree(JsonValue * value) free(value); } +static void +JsonEncodeString(const char * str, FILE * out) +{ + fprintf(out, "\"%s\"", str); +} + static void JsonEncodeValue(JsonValue * value, FILE * out) { @@ -278,7 +284,7 @@ JsonEncodeValue(JsonValue * value, FILE * out) fputc(']', out); break; case JSON_STRING: - fprintf(out, "\"%s\"", value->as.string); + JsonEncodeString(value->as.string, out); break; case JSON_INTEGER: fprintf(out, "%lld", value->as.integer); @@ -328,7 +334,8 @@ JsonEncode(HashMap * object, FILE * out) index = 0; while (HashMapIterate(object, &key, (void **) &value)) { - fprintf(out, "\"%s\":", key); + JsonEncodeString(key, out); + fputc(':', out); JsonEncodeValue(value, out); if (index < count - 1)