From patchwork Fri Jul 3 00:14:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8578 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5A4EEBE905 for ; Fri, 3 Jul 2020 00:14:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2929460C62; Fri, 3 Jul 2020 02:14:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uejkICwv"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 239AA60C63 for ; Fri, 3 Jul 2020 02:14:37 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7AB71450; Fri, 3 Jul 2020 02:14:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593735276; bh=NLtrgA4b/wli+aqEmSZI/blphIJQ64+h7IVFpFZn0FQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uejkICwvcfAre708jbdTl/0o2qoOFIrTmw56/G5XF/+EFNulHMpa3MvAlqJN4mmeP wyi6mMmcnFu/JuqtXDXmBWLegc8PkjE/7mbBOB11CtJGpbUaszd36/jedoUc77ttSg s+nibSRGRlb97dTmXj5rQcn8Qo9qvTjJTmuMJjOU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 03:14:21 +0300 Message-Id: <20200703001422.24324-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200703001422.24324-1-laurent.pinchart@ideasonboard.com> References: <20200703001422.24324-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/10] utils: raspberrypi: ctt: json_pretty_print: Avoid spaces at end of lines X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 10 +++++++--- 1 file 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 f7fdb65116bc..2ca307a0af11 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: