From 9e885147009f4a06796d719c1987d6406b3af931 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 25 Aug 2014 12:28:58 +0200 Subject: [PATCH] Refactoring.... --- JsonGenerator/PrettyPrintDecorator.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/JsonGenerator/PrettyPrintDecorator.cpp b/JsonGenerator/PrettyPrintDecorator.cpp index 3667ebcb..df3f0a7e 100644 --- a/JsonGenerator/PrettyPrintDecorator.cpp +++ b/JsonGenerator/PrettyPrintDecorator.cpp @@ -75,30 +75,20 @@ size_t PrettyPrintDecorator::writeComma() size_t PrettyPrintDecorator::writeOpening(uint8_t c) { - size_t n; - - if (previousChar == '{' || previousChar == '[') - { - n = writeln() + sink.write(c); - } - else - { - n = sink.write(c); - } + bool inEmptyBlock = previousChar == '{' || previousChar == '['; + + size_t n = inEmptyBlock ? writeln() + sink.write(c) : sink.write(c); indent++; + return n; } size_t PrettyPrintDecorator::writeClosing(uint8_t c) { + bool inEmptyBlock = previousChar == '{' || previousChar == '['; + indent--; - if (previousChar == '{' || previousChar == '[') - { - return sink.write(c); - } - else - { - return writeln() + sink.write(c); - } + + return inEmptyBlock ? sink.write(c) : writeln() + sink.write(c); } \ No newline at end of file