[Olsr-dev] [PATCH v1 106/115] jsoninfo: helpers: use abuf_json_insert_comma

Ferry Huberts (spam-protected)
Wed Dec 2 21:29:19 CET 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/jsoninfo/src/olsrd_jsoninfo_helpers.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
index bd930f0..4fa3f50 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo_helpers.c
@@ -61,6 +61,11 @@ char uuid[UUIDLEN + 1];
 static int entrynumber[ENTRY_NUMBER_MAX_DEPTH] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 static int currentjsondepth = 0;
 
+void abuf_json_reset_entry_number_and_depth(void) {
+  entrynumber[0] = 0;
+  currentjsondepth = 0;
+}
+
 static void abuf_json_new_indent(struct autobuf *abuf) {
   if (currentjsondepth) {
     int i = currentjsondepth;
@@ -72,9 +77,9 @@ static void abuf_json_new_indent(struct autobuf *abuf) {
   }
 }
 
-void abuf_json_reset_entry_number_and_depth(void) {
-  entrynumber[0] = 0;
-  currentjsondepth = 0;
+void abuf_json_insert_comma(struct autobuf *abuf) {
+  if (entrynumber[currentjsondepth])
+    abuf_appendf(abuf, ",");
 }
 
 void abuf_json_mark_output(bool open, struct autobuf *abuf) {
@@ -95,9 +100,7 @@ void abuf_json_mark_output(bool open, struct autobuf *abuf) {
 
 void abuf_json_mark_object(bool open, bool array, struct autobuf *abuf, const char* header) {
   if (open) {
-    if (entrynumber[currentjsondepth]) {
-      abuf_appendf(abuf, ",");
-    }
+    abuf_json_insert_comma(abuf);
     abuf_json_new_indent(abuf);
     if (header) {
       abuf_appendf(abuf, "\"%s\": %s", header, array ? "[" : "{");
@@ -121,11 +124,6 @@ void abuf_json_mark_array_entry(bool open, struct autobuf *abuf) {
   abuf_json_mark_object(open, false, abuf, NULL);
 }
 
-void abuf_json_insert_comma(struct autobuf *abuf) {
-  if (entrynumber[currentjsondepth])
-    abuf_appendf(abuf, ",");
-}
-
 void abuf_json_boolean(struct autobuf *abuf, const char* key, int value) {
   abuf_json_insert_comma(abuf);
   abuf_json_new_indent(abuf);
-- 
2.5.0




More information about the Olsr-dev mailing list