diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-12-11 18:11:49 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-12-19 10:39:23 +0100 |
commit | 68af4cc1213ec6057ac47765985b6704c6be7fd7 (patch) | |
tree | 31667f061130d72694120d6c093cba7f7fa569e7 /qobject/json-parser.c | |
parent | 3ddba9a9e9bedd20a0b60dcdbe86f16223555555 (diff) |
json: Use GString instead of QString to accumulate strings
QString supports modifying its string, but it's quite limited: you can
only append. The remaining callers use it for building an initial
string, never for modifying it later.
Change parse_string() to do build the initial string with GString.
This is another step towards making QString immutable.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201211171152.146877-18-armbru@redhat.com>
Diffstat (limited to 'qobject/json-parser.c')
-rw-r--r-- | qobject/json-parser.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/qobject/json-parser.c b/qobject/json-parser.c index c0f521b56b..d351039b10 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -130,7 +130,7 @@ static int cvt4hex(const char *s) static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) { const char *ptr = token->str; - QString *str; + GString *str; char quote; const char *beg; int cp, trailing; @@ -140,7 +140,7 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) assert(*ptr == '"' || *ptr == '\''); quote = *ptr++; - str = qstring_new(); + str = g_string_new(NULL); while (*ptr != quote) { assert(*ptr); @@ -149,31 +149,31 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) beg = ptr++; switch (*ptr++) { case '"': - qstring_append_chr(str, '"'); + g_string_append_c(str, '"'); break; case '\'': - qstring_append_chr(str, '\''); + g_string_append_c(str, '\''); break; case '\\': - qstring_append_chr(str, '\\'); + g_string_append_c(str, '\\'); break; case '/': - qstring_append_chr(str, '/'); + g_string_append_c(str, '/'); break; case 'b': - qstring_append_chr(str, '\b'); + g_string_append_c(str, '\b'); break; case 'f': - qstring_append_chr(str, '\f'); + g_string_append_c(str, '\f'); break; case 'n': - qstring_append_chr(str, '\n'); + g_string_append_c(str, '\n'); break; case 'r': - qstring_append_chr(str, '\r'); + g_string_append_c(str, '\r'); break; case 't': - qstring_append_chr(str, '\t'); + g_string_append_c(str, '\t'); break; case 'u': cp = cvt4hex(ptr); @@ -200,7 +200,7 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) (int)(ptr - beg), beg); goto out; } - qstring_append(str, utf8_buf); + g_string_append(str, utf8_buf); break; default: parse_error(ctxt, token, "invalid escape sequence in string"); @@ -225,14 +225,14 @@ static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) ptr = end; len = mod_utf8_encode(utf8_buf, sizeof(utf8_buf), cp); assert(len >= 0); - qstring_append(str, utf8_buf); + g_string_append(str, utf8_buf); } } - return str; + return qstring_from_gstring(str); out: - qobject_unref(str); + g_string_free(str, true); return NULL; } |