[json-glib] parser: Re-use json_parse_value()
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] parser: Re-use json_parse_value()
- Date: Thu, 18 Mar 2010 17:12:18 +0000 (UTC)
commit 54756457de3f01d1a487fc6b90c5bd9b5b50bcf3
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Thu Mar 18 17:09:38 2010 +0000
parser: Re-use json_parse_value()
The main switch inside json_parse_statement() is re-implementing the
bare value parsing that is also provided by json_parse_value(). We
should kill it off to avoid redundant code.
json-glib/json-parser.c | 57 +---------------------------------------------
1 files changed, 2 insertions(+), 55 deletions(-)
---
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index 082e9b1..4e22572 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -841,67 +841,14 @@ json_parse_statement (JsonParser *parser,
break;
case JSON_TOKEN_NULL:
- priv->root = priv->current_node = json_node_new (JSON_NODE_NULL);
- json_scanner_get_next_token (scanner);
- return G_TOKEN_NONE;
-
case JSON_TOKEN_TRUE:
case JSON_TOKEN_FALSE:
- priv->root = priv->current_node = json_node_new (JSON_NODE_VALUE);
- json_node_set_boolean (priv->current_node,
- token == JSON_TOKEN_TRUE ? TRUE : FALSE);
- json_scanner_get_next_token (scanner);
- return G_TOKEN_NONE;
-
case '-':
- {
- guint next_token;
-
- token = json_scanner_get_next_token (scanner);
- next_token = json_scanner_peek_next_token (scanner);
-
- if (next_token == G_TOKEN_INT || next_token == G_TOKEN_FLOAT)
- {
- priv->root = priv->current_node = json_node_new (JSON_NODE_VALUE);
-
- token = json_scanner_get_next_token (scanner);
- switch (token)
- {
- case G_TOKEN_INT:
- json_node_set_int (priv->current_node,
- scanner->value.v_int64 * -1);
- break;
- case G_TOKEN_FLOAT:
- json_node_set_double (priv->current_node,
- scanner->value.v_float * -1.0);
- break;
- default:
- return G_TOKEN_INT;
- }
-
- json_scanner_get_next_token (scanner);
- return G_TOKEN_NONE;
- }
- else
- return G_TOKEN_INT;
- }
- break;
-
case G_TOKEN_INT:
case G_TOKEN_FLOAT:
case G_TOKEN_STRING:
- json_scanner_get_next_token (scanner);
- priv->root = priv->current_node = json_node_new (JSON_NODE_VALUE);
-
- if (token == G_TOKEN_INT)
- json_node_set_int (priv->current_node, scanner->value.v_int64);
- else if (token == G_TOKEN_FLOAT)
- json_node_set_double (priv->current_node, scanner->value.v_float);
- else
- json_node_set_string (priv->current_node, scanner->value.v_string);
-
- json_scanner_get_next_token (scanner);
- return G_TOKEN_NONE;
+ token = json_scanner_get_next_token (scanner);
+ return json_parse_value (parser, scanner, token, &priv->root);
default:
json_scanner_get_next_token (scanner);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]