diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-01 14:57:25 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-01 14:57:25 +0100 |
commit | 79423943a8588a8ed6d5bedbc038255111897261 (patch) | |
tree | 5f552242f82c8bf814bcb054b416fabaee487ce3 /json-glib/json-parser.c | |
parent | e711b883dba88d68b6986d87f14a06361cf54be7 (diff) | |
download | json-glib-79423943a8588a8ed6d5bedbc038255111897261.tar.gz |
Swallow the comma earlier in the parser
The comma is used as a member and element separator, so it should be
swallowed by the parser as soon as possible.
Diffstat (limited to 'json-glib/json-parser.c')
-rw-r--r-- | json-glib/json-parser.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c index c3f02c0..51f23e1 100644 --- a/json-glib/json-parser.c +++ b/json-glib/json-parser.c @@ -179,6 +179,13 @@ json_parse_array (JsonParser *parser, JsonNode *node = NULL; GValue value = { 0, }; + if (token == G_TOKEN_COMMA) + { + /* swallow the comma */ + token = g_scanner_get_next_token (scanner); + continue; + } + /* nested object */ if (token == G_TOKEN_LEFT_CURLY) { @@ -239,10 +246,6 @@ json_parse_array (JsonParser *parser, switch (token) { - case G_TOKEN_COMMA: - /* eat the comma and continue */ - break; - case G_TOKEN_INT: g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, scanner->value.v_int); @@ -332,6 +335,13 @@ json_parse_object (JsonParser *parser, gchar *name = NULL; GValue value = { 0, }; + if (token == G_TOKEN_COMMA) + { + /* swallow the comma */ + token = g_scanner_get_next_token (scanner); + continue; + } + if (token == G_TOKEN_STRING) { name = g_strdup (scanner->value.v_string); @@ -386,7 +396,8 @@ json_parse_object (JsonParser *parser, continue; } - else if (token == G_TOKEN_LEFT_BRACE) + + if (token == G_TOKEN_LEFT_BRACE) { JsonNode *old_node = priv->current_node; @@ -419,10 +430,6 @@ json_parse_object (JsonParser *parser, switch (token) { - case G_TOKEN_COMMA: - /* eat the comma and continue */ - break; - case G_TOKEN_INT: g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, scanner->value.v_int); |