From f128acc32584c07f900f0268b12133b2d227e279 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 3 Jul 2020 01:43:57 +0300 Subject: 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 Reviewed-by: David Plowman Tested-by: David Plowman --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'utils/raspberrypi') 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: -- cgit v1.2.1