Skip to contentSkip to conversation

qjson: Drop trailing space for pretty formatting

PATCH In review Max Reitz 3 participants 3 messages Nov 21, 2014

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qjson: Drop trailing space for pretty formatting

For the pretty formatting, the functions converting QDicts and QLists to JSON should not print a space after the comma separating objects, because a newline will emitted immediately afterwards, making the whitespace superfluous.

---
 qobject/qjson.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
qobject/qjson.c +6 -4
index 6cf2511..12c576d 100644
@@ -86,8 +86,9 @@ static void to_json_dict_iter(const char *key, QObject *obj, void *opaque)
     QString *qkey;
     int j;
 
-    if (s->count)
-        qstring_append(s->str, ", ");
+    if (s->count) {
+        qstring_append(s->str, s->pretty ? "," : ", ");
+    }
 
     if (s->pretty) {
         qstring_append(s->str, "\n");
@@ -109,8 +110,9 @@ static void to_json_list_iter(QObject *obj, void *opaque)
     ToJsonIterState *s = opaque;
     int j;
 
-    if (s->count)
-        qstring_append(s->str, ", ");
+    if (s->count) {
+        qstring_append(s->str, s->pretty ? "," : ", ");
+    }
 
     if (s->pretty) {
         qstring_append(s->str, "\n");
Signature · 1 line
1.9.3
#1 lore raw

Am 21.11.2014 um 10:29 hat Max Reitz geschrieben:

Quoted 6 lines

For the pretty formatting, the functions converting QDicts and QLists to JSON should not print a space after the comma separating objects, because a newline will emitted immediately afterwards, making the whitespace superfluous.

Luiz, any objections?

/me waits a bit... 3... 2... 1...

No? Great, thanks, applied to block-next.

(More seriously, I have a patch with a qemu-iotests case depending on the output, so I'm merging this before my patch. If there is a problem, there's still some time until block-next ends up in master, so I can always drop it or replace it with a v2.)

Kevin

Reviewed-by on v1 1/1
#2 lore raw
In reply to Max Reitz
Quoted 10 lines · Max Reitz

For the pretty formatting, the functions converting QDicts and QLists to JSON should not print a space after the comma separating objects, because a newline will emitted immediately afterwards, making the whitespace superfluous.

---
 qobject/qjson.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org