From e48ea94789b180f56d37d132f25b7635bab64f8a Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 26 Aug 2014 09:49:59 +0200 Subject: [PATCH] Refactoring... --- JsonGenerator/PrettyPrintDecorator.cpp | 33 ++++++++++++-------------- JsonGenerator/PrettyPrintDecorator.h | 16 +------------ 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/JsonGenerator/PrettyPrintDecorator.cpp b/JsonGenerator/PrettyPrintDecorator.cpp index 83e07b36..65280b70 100644 --- a/JsonGenerator/PrettyPrintDecorator.cpp +++ b/JsonGenerator/PrettyPrintDecorator.cpp @@ -20,7 +20,7 @@ size_t PrettyPrintDecorator::handleStringChar(uint8_t c) if (isQuote) inString = false; - return writeChar(c); + return sink.write(c); } size_t PrettyPrintDecorator::handleMarkupChar(uint8_t c) @@ -51,44 +51,33 @@ size_t PrettyPrintDecorator::handleMarkupChar(uint8_t c) size_t PrettyPrintDecorator::handleBlockOpen(uint8_t c) { - return indentIfNeeded() + writeChar(c); + return indentIfNeeded() + sink.write(c); } size_t PrettyPrintDecorator::handleBlockClose(uint8_t c) { - if (inEmptyBlock()) - { - return writeChar(c); - } - else - { - sink.unindent(); - return breakThenWrite(c); - } + return unindentIfNeeded() + sink.write(c); } size_t PrettyPrintDecorator::handleColumn() { - return writeChar(':') + writeChar(' '); + return sink.write(':') + sink.write(' '); } size_t PrettyPrintDecorator::handleComma() { - return writeThenBreak(','); + return sink.write(',') + sink.println(); } size_t PrettyPrintDecorator::handleQuoteOpen() { - size_t n = indentIfNeeded() + writeChar('"'); - inString = true; - - return n; + return indentIfNeeded() + sink.write('"'); } size_t PrettyPrintDecorator::handleNormalChar(uint8_t c) { - return indentIfNeeded() + writeChar(c); + return indentIfNeeded() + sink.write(c); } size_t PrettyPrintDecorator::indentIfNeeded() @@ -97,4 +86,12 @@ size_t PrettyPrintDecorator::indentIfNeeded() sink.indent(); return sink.println(); +} + +size_t PrettyPrintDecorator::unindentIfNeeded() +{ + if (inEmptyBlock()) return 0; + + sink.unindent(); + return sink.println(); } \ No newline at end of file diff --git a/JsonGenerator/PrettyPrintDecorator.h b/JsonGenerator/PrettyPrintDecorator.h index e0aa46e7..99df3035 100644 --- a/JsonGenerator/PrettyPrintDecorator.h +++ b/JsonGenerator/PrettyPrintDecorator.h @@ -45,21 +45,7 @@ namespace ArduinoJson size_t handleQuoteOpen(); size_t handleNormalChar(uint8_t); size_t indentIfNeeded(); - - size_t breakThenWrite(uint8_t c) - { - return sink.println() + writeChar(c); - } - - size_t writeThenBreak(uint8_t c) - { - return writeChar(c) + sink.println(); - } - - size_t writeChar(uint8_t c) - { - return sink.write(c); - } + size_t unindentIfNeeded(); }; } } \ No newline at end of file