forked from bblanchon/ArduinoJson
Refactoring...
This commit is contained in:
@ -20,7 +20,7 @@ size_t PrettyPrintDecorator::handleStringChar(uint8_t c)
|
|||||||
|
|
||||||
if (isQuote) inString = false;
|
if (isQuote) inString = false;
|
||||||
|
|
||||||
return writeChar(c);
|
return sink.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleMarkupChar(uint8_t 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)
|
size_t PrettyPrintDecorator::handleBlockOpen(uint8_t c)
|
||||||
{
|
{
|
||||||
return indentIfNeeded() + writeChar(c);
|
return indentIfNeeded() + sink.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleBlockClose(uint8_t c)
|
size_t PrettyPrintDecorator::handleBlockClose(uint8_t c)
|
||||||
{
|
{
|
||||||
if (inEmptyBlock())
|
return unindentIfNeeded() + sink.write(c);
|
||||||
{
|
|
||||||
return writeChar(c);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sink.unindent();
|
|
||||||
return breakThenWrite(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleColumn()
|
size_t PrettyPrintDecorator::handleColumn()
|
||||||
{
|
{
|
||||||
return writeChar(':') + writeChar(' ');
|
return sink.write(':') + sink.write(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleComma()
|
size_t PrettyPrintDecorator::handleComma()
|
||||||
{
|
{
|
||||||
return writeThenBreak(',');
|
return sink.write(',') + sink.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleQuoteOpen()
|
size_t PrettyPrintDecorator::handleQuoteOpen()
|
||||||
{
|
{
|
||||||
size_t n = indentIfNeeded() + writeChar('"');
|
|
||||||
|
|
||||||
inString = true;
|
inString = true;
|
||||||
|
return indentIfNeeded() + sink.write('"');
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::handleNormalChar(uint8_t c)
|
size_t PrettyPrintDecorator::handleNormalChar(uint8_t c)
|
||||||
{
|
{
|
||||||
return indentIfNeeded() + writeChar(c);
|
return indentIfNeeded() + sink.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::indentIfNeeded()
|
size_t PrettyPrintDecorator::indentIfNeeded()
|
||||||
@ -97,4 +86,12 @@ size_t PrettyPrintDecorator::indentIfNeeded()
|
|||||||
|
|
||||||
sink.indent();
|
sink.indent();
|
||||||
return sink.println();
|
return sink.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PrettyPrintDecorator::unindentIfNeeded()
|
||||||
|
{
|
||||||
|
if (inEmptyBlock()) return 0;
|
||||||
|
|
||||||
|
sink.unindent();
|
||||||
|
return sink.println();
|
||||||
}
|
}
|
@ -45,21 +45,7 @@ namespace ArduinoJson
|
|||||||
size_t handleQuoteOpen();
|
size_t handleQuoteOpen();
|
||||||
size_t handleNormalChar(uint8_t);
|
size_t handleNormalChar(uint8_t);
|
||||||
size_t indentIfNeeded();
|
size_t indentIfNeeded();
|
||||||
|
size_t unindentIfNeeded();
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user