From patchwork Fri Jul 3 00:14:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8577 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 EE10AC2E6B for ; Fri, 3 Jul 2020 00:14:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B80F560C6A; Fri, 3 Jul 2020 02:14:40 +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="EiQX2PE0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BFED160CB1 for ; Fri, 3 Jul 2020 02:14:36 +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 55C9AA2D; 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=Q0nEgp51+e1442dz9uoGps0KFX1YFA9EyoPGVUQ41L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EiQX2PE0z1lXKpEX5UdQ7waj6HwHLMim3Hy++EKTJn+Sj5mOSHVZknqo89Lv9mdVq nIQOfZxDjo6mbPjYCxl83aVZ+lrmxMOsjuYBRcgozxib0bRhZabu7uNsWhV4rwlxwO ZEj9Lixjy+kjbqlFNKTZSsqQQch+RMzAq592SbbE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 03:14:20 +0300 Message-Id: <20200703001422.24324-9-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 08/10] utils: raspberrypi: ctt: json_pretty_print: Collapse newlines 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" 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 --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 11 ++++++----- 1 file 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 f1c61347d8fc..f7fdb65116bc 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: