diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-07-03 01:43:57 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-07-03 18:15:50 +0300 |
commit | bfad33c3efeaff60f0f3b36ed858fb27f89239a7 (patch) | |
tree | c0f6dd9419501843d955591cdbef2f0dcc5fb97d /utils | |
parent | d9617a499a174cdf7f56acafc2e7eec24be478c2 (diff) |
utils: raspberrypi: ctt: json_pretty_print: Collapse newlines
Simplify the newline skipping logic by simply collapsing newlines. If a
newline has been output, all subsequent newlines will be skipped until
the next non-newline character is output.
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')
-rw-r--r-- | utils/raspberrypi/ctt/ctt_pretty_print_json.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index f1c61347..f7fdb651 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -23,19 +23,21 @@ class JSONPrettyPrinter(object): self.fout = fout def newline(self): - self.fout.write('\n') - self.state["need_indent"] = True + if not self.state["skipnewline"]: + self.fout.write('\n') + self.state["need_indent"] = True + 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 self.fout.write(c) + self.state["skipnewline"] = False def process_char(self, c): if c == '{': - if not self.state["skipnewline"]: - self.newline() + self.newline() self.write(c) self.state["indent"] += 1 self.newline() @@ -76,7 +78,6 @@ class JSONPrettyPrinter(object): pass else: self.write(c) - self.state["skipnewline"] = (c == '[') def print(self, string): for c in string: |