You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/03/17 21:36:16 UTC
[lucy-commits] [03/11] git commit: Support null values in .cfp JSON parser
Support null values in .cfp JSON parser
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/daab988c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/daab988c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/daab988c
Branch: refs/heads/master
Commit: daab988cf2c6668af6d3c370d71c3061cbcf3e51
Parents: eb4d676
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Mar 12 13:22:47 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Mar 17 18:25:29 2014 +0100
----------------------------------------------------------------------
compiler/src/CFCParcel.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/daab988c/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParcel.c b/compiler/src/CFCParcel.c
index 7674d05..2b3bead 100644
--- a/compiler/src/CFCParcel.c
+++ b/compiler/src/CFCParcel.c
@@ -49,6 +49,7 @@ static CFCParcel *default_parcel = NULL;
#define JSON_STRING 1
#define JSON_HASH 2
+#define JSON_NULL 3
typedef struct JSONNode {
int type;
@@ -66,6 +67,9 @@ S_parse_json_hash(const char **json);
static JSONNode*
S_parse_json_string(const char **json);
+static JSONNode*
+S_parse_json_null(const char **json);
+
static void
S_skip_whitespace(const char **json);
@@ -543,6 +547,9 @@ S_parse_json_hash(const char **json) {
else if (*text == '{') {
value = S_parse_json_hash(&text);
}
+ else if (*text == 'n') {
+ value = S_parse_json_null(&text);
+ }
if (!value) {
S_destroy_json(node);
return NULL;
@@ -596,6 +603,24 @@ S_parse_json_string(const char **json) {
return node;
}
+// Parse a JSON null value.
+static JSONNode*
+S_parse_json_null(const char **json) {
+ static const char null_str[] = "null";
+
+ if (strncmp(*json, null_str, sizeof(null_str) - 1) != 0) {
+ return NULL;
+ }
+
+ JSONNode *node = (JSONNode*)calloc(1, sizeof(JSONNode));
+ node->type = JSON_NULL;
+
+ // Move pointer.
+ *json += sizeof(null_str) - 1;
+
+ return node;
+}
+
static void
S_skip_whitespace(const char **json) {
while (isspace(json[0][0])) { *json = *json + 1; }