[json-glib] parser: Clean up array and object parsing
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] parser: Clean up array and object parsing
- Date: Thu, 18 Mar 2010 15:27:22 +0000 (UTC)
commit f4c57ac4227c4edb8a4cecb784e871fbd5649ad1
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Thu Mar 18 15:24:39 2010 +0000
parser: Clean up array and object parsing
We are doing some of the work twice, especially when dealing with the
trailing commas detection and the unknown tokens after an array element
or an object member definition.
json-glib/json-parser.c | 44 ++++++++++++++++++++++++--------------------
1 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index fc011b9..18a3d34 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -37,6 +37,7 @@
#include "json-types-private.h"
+#include "json-debug.h"
#include "json-marshal.h"
#include "json-parser.h"
#include "json-scanner.h"
@@ -457,7 +458,9 @@ json_parse_array (JsonParser *parser,
token = json_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
- break;
+ {
+ break;
+ }
if (token == G_TOKEN_COMMA)
{
@@ -503,7 +506,9 @@ json_parse_array (JsonParser *parser,
token = json_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
- break;
+ {
+ break;
+ }
if (token == G_TOKEN_COMMA)
{
@@ -536,8 +541,6 @@ json_parse_array (JsonParser *parser,
json_array_get_length (array));
token = json_scanner_get_next_token (scanner);
- if (token == G_TOKEN_RIGHT_BRACE)
- break;
if (token == G_TOKEN_COMMA)
{
@@ -548,11 +551,12 @@ json_parse_array (JsonParser *parser,
json_array_unref (array);
return G_TOKEN_SYMBOL;
}
-
- continue;
}
-
- return G_TOKEN_RIGHT_BRACE;
+ else if (token != G_TOKEN_RIGHT_BRACE)
+ {
+ json_array_unref (array);
+ return G_TOKEN_RIGHT_BRACE;
+ }
}
json_node_take_array (priv->current_node, array);
@@ -615,6 +619,7 @@ json_parse_object (JsonParser *parser,
return G_TOKEN_STRING;
}
+ /* nested object */
if (token == G_TOKEN_LEFT_CURLY)
{
JsonNode *old_node = priv->current_node;
@@ -668,7 +673,8 @@ json_parse_object (JsonParser *parser,
return G_TOKEN_RIGHT_CURLY;
}
-
+
+ /* nested array */
if (token == G_TOKEN_LEFT_BRACE)
{
JsonNode *old_node = priv->current_node;
@@ -699,7 +705,7 @@ json_parse_object (JsonParser *parser,
g_free (name);
token = json_scanner_get_next_token (scanner);
- if (token == G_TOKEN_RIGHT_BRACE)
+ if (token == G_TOKEN_RIGHT_CURLY)
break;
if (token == G_TOKEN_COMMA)
@@ -736,29 +742,27 @@ json_parse_object (JsonParser *parser,
object,
name);
- g_free (name);
-
token = json_scanner_get_next_token (scanner);
- if (token == G_TOKEN_RIGHT_CURLY)
- break;
-
if (token == G_TOKEN_COMMA)
{
token = json_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_CURLY)
{
+ g_free (name);
json_object_unref (object);
return G_TOKEN_STRING;
}
-
- continue;
+ }
+ else if (token != G_TOKEN_RIGHT_CURLY)
+ {
+ g_free (name);
+ json_object_unref (object);
+ return G_TOKEN_RIGHT_CURLY;
}
- json_object_unref (object);
-
- return G_TOKEN_RIGHT_CURLY;
+ g_free (name);
}
json_node_take_object (priv->current_node, object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]