[json-glib/json-glib-0-12] generator: Implement dumping bare values



commit 93069a40ff7b26d787218ea3f23a23b9b53e8d05
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Tue Dec 14 11:37:25 2010 +0000

    generator: Implement dumping bare values
    
    JsonGenerator is not able to generate strings for bare values, something
    that completely went under the radar for all this time.
    (cherry picked from commit 4add0e081b8f58dec1cd68152d846be87942091e)
    
    Signed-off-by: Emmanuele Bassi <ebassi linux intel com>

 json-glib/json-generator.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c
index 0df5c0b..7b41c40 100644
--- a/json-glib/json-generator.c
+++ b/json-glib/json-generator.c
@@ -67,7 +67,8 @@ enum
 static gchar *dump_value  (JsonGenerator *generator,
                            gint           level,
                            const gchar   *name,
-                           JsonNode      *node);
+                           JsonNode      *node,
+                           gsize         *length);
 static gchar *dump_array  (JsonGenerator *generator,
                            gint           level,
                            const gchar   *name,
@@ -265,7 +266,8 @@ static gchar *
 dump_value (JsonGenerator *generator,
             gint           level,
             const gchar   *name,
-            JsonNode      *node)
+            JsonNode      *node,
+            gsize         *length)
 {
   JsonGeneratorPrivate *priv = generator->priv;
   gboolean pretty = priv->pretty;
@@ -325,6 +327,9 @@ dump_value (JsonGenerator *generator,
 
   g_value_unset (&value);
 
+  if (length)
+    *length = buffer->len;
+
   return g_string_free (buffer, FALSE);
 }
 
@@ -379,7 +384,7 @@ dump_array (JsonGenerator *generator,
           break;
 
         case JSON_NODE_VALUE:
-          value = dump_value (generator, sub_level, NULL, cur);
+          value = dump_value (generator, sub_level, NULL, cur, NULL);
           g_string_append (buffer, value);
           g_free (value);
           break;
@@ -474,7 +479,7 @@ dump_object (JsonGenerator *generator,
           break;
 
         case JSON_NODE_VALUE:
-          value = dump_value (generator, sub_level, member_name, cur);
+          value = dump_value (generator, sub_level, member_name, cur, NULL);
           g_string_append (buffer, value);
           g_free (value);
           break;
@@ -581,7 +586,7 @@ json_generator_to_data (JsonGenerator *generator,
       break;
 
     case JSON_NODE_VALUE:
-      retval = NULL;
+      retval = dump_value (generator, 0, NULL, root, length);
       break;
     }
 



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