summaryrefslogtreecommitdiff
path: root/utils/raspberrypi
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-07-03 01:43:57 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-07-03 18:15:54 +0300
commitf128acc32584c07f900f0268b12133b2d227e279 (patch)
treee1e3e571029382bc657c7fadc9699a0eb6fa04ec /utils/raspberrypi
parentbfad33c3efeaff60f0f3b36ed858fb27f89239a7 (diff)
utils: raspberrypi: ctt: json_pretty_print: Avoid spaces at end of lines
Avoid outputting spaces at end of lines by recording the need for a space and outputting it before the next character only if not a newline. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Tested-by: David Plowman <david.plowman@raspberrypi.com>
Diffstat (limited to 'utils/raspberrypi')
-rw-r--r--utils/raspberrypi/ctt/ctt_pretty_print_json.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
index f7fdb651..2ca307a0 100644
--- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py
+++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
@@ -18,6 +18,7 @@ class JSONPrettyPrinter(object):
"arraycount": [],
"skipnewline": True,
"need_indent": False,
+ "need_space": False,
}
self.fout = fout
@@ -26,12 +27,16 @@ class JSONPrettyPrinter(object):
if not self.state["skipnewline"]:
self.fout.write('\n')
self.state["need_indent"] = True
+ self.state["need_space"] = False
self.state["skipnewline"] = True
def write(self, c):
if self.state["need_indent"]:
self.fout.write(' ' * self.state["indent"] * 4)
self.state["need_indent"] = False
+ if self.state["need_space"]:
+ self.fout.write(' ')
+ self.state["need_space"] = False
self.fout.write(c)
self.state["skipnewline"] = False
@@ -60,11 +65,10 @@ class JSONPrettyPrinter(object):
self.write(c)
elif c == ':':
self.write(c)
- self.write(' ')
+ self.state["need_space"] = True
elif c == ',':
if not self.state["inarray"][0]:
self.write(c)
- self.write(' ')
self.newline()
else:
self.write(c)
@@ -73,7 +77,7 @@ class JSONPrettyPrinter(object):
self.state["arraycount"][0] = 0
self.newline()
else:
- self.write(' ')
+ self.state["need_space"] = True
elif c.isspace():
pass
else: