diff --git a/JsonGenerator/PrettyPrintDecorator.cpp b/JsonGenerator/PrettyPrintDecorator.cpp index ebc7497b..c7e6110f 100644 --- a/JsonGenerator/PrettyPrintDecorator.cpp +++ b/JsonGenerator/PrettyPrintDecorator.cpp @@ -16,7 +16,9 @@ size_t PrettyPrintDecorator::handleStringChar(uint8_t c) { bool isQuote = c == '"' && previousChar != '\\'; - return isQuote ? writeQuote() : writeNormalChar(c); + if (isQuote) inString = false; + + return sink.write(c); } size_t PrettyPrintDecorator::handleMarkupChar(uint8_t c) @@ -41,14 +43,13 @@ size_t PrettyPrintDecorator::handleMarkupChar(uint8_t c) return writeQuote(); default: - return writeNormalChar(c); // <- should not happen anyway + return writeValueChar(c); } } -size_t PrettyPrintDecorator::writeNormalChar(uint8_t c) +size_t PrettyPrintDecorator::writeValueChar(uint8_t c) { - bool inEmptyBlock = !inString && (previousChar == '{' || previousChar == '['); - + bool inEmptyBlock = previousChar == '{' || previousChar == '['; return inEmptyBlock ? writeln() + sink.write(c) : sink.write(c); } @@ -75,8 +76,12 @@ size_t PrettyPrintDecorator::writeOpening(uint8_t c) size_t PrettyPrintDecorator::writeQuote() { - size_t n = writeNormalChar('"'); - inString = !inString; + bool inEmptyBlock = previousChar == '{' || previousChar == '['; + + size_t n = inEmptyBlock ? writeln() + sink.write('"') : sink.write('"'); + + inString = true; + return n; } diff --git a/JsonGenerator/PrettyPrintDecorator.h b/JsonGenerator/PrettyPrintDecorator.h index 61409a96..dd62fcea 100644 --- a/JsonGenerator/PrettyPrintDecorator.h +++ b/JsonGenerator/PrettyPrintDecorator.h @@ -35,7 +35,7 @@ private: size_t writeClosing(uint8_t); size_t writeColumn(); size_t writeComma(); - size_t writeNormalChar(uint8_t); + size_t writeValueChar(uint8_t); size_t writeOpening(uint8_t); size_t writeQuote(); };