[json-glib] Consolidate null handling in JsonArray and JsonObject



commit 9dfb5000cad954431165e836e203e561ccb79c66
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Sat Oct 27 11:48:58 2012 +0100

    Consolidate null handling in JsonArray and JsonObject
    
    A null value is not only valid for JSON_NODE_NULL nodes, but also for
    JSON_NODE_ARRAY and JSON_NODE_OBJECT nodes that do not have a JsonArray
    or a JsonObject set.

 json-glib/json-array.c  |   11 ++++++++++-
 json-glib/json-object.c |   11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/json-glib/json-array.c b/json-glib/json-array.c
index 3d5e47f..b353ea3 100644
--- a/json-glib/json-array.c
+++ b/json-glib/json-array.c
@@ -360,7 +360,16 @@ json_array_get_null_element (JsonArray *array,
   node = g_ptr_array_index (array->elements, index_);
   g_return_val_if_fail (node != NULL, FALSE);
 
-  return JSON_NODE_TYPE (node) == JSON_NODE_NULL;
+  if (JSON_NODE_HOLDS_NULL (node))
+    return TRUE;
+
+  if (JSON_NODE_HOLDS_ARRAY (node))
+    return json_node_get_array (node) == NULL;
+
+  if (JSON_NODE_HOLDS_OBJECT (node))
+    return json_node_get_object (node) == NULL;
+
+  return FALSE;
 }
 
 /**
diff --git a/json-glib/json-object.c b/json-glib/json-object.c
index 8f55098..acb3c5a 100644
--- a/json-glib/json-object.c
+++ b/json-glib/json-object.c
@@ -652,7 +652,16 @@ json_object_get_null_member (JsonObject  *object,
   node = object_get_member_internal (object, member_name);
   g_return_val_if_fail (node != NULL, FALSE);
 
-  return JSON_NODE_TYPE (node) == JSON_NODE_NULL;
+  if (JSON_NODE_HOLDS_NULL (node))
+    return TRUE;
+
+  if (JSON_NODE_HOLDS_OBJECT (node))
+    return json_node_get_object (node) == NULL;
+
+  if (JSON_NODE_HOLDS_ARRAY (node))
+    return json_node_get_array (node) == NULL;
+
+  return FALSE;
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]