IndentedPrint.cpp 743 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include "../../include/ArduinoJson/Internals/IndentedPrint.hpp"
  7. using namespace ArduinoJson::Internals;
  8. void IndentedPrint::indent() {
  9. if (level < MAX_LEVEL) level++;
  10. }
  11. void IndentedPrint::unindent() {
  12. if (level > 0) level--;
  13. }
  14. void IndentedPrint::setTabSize(uint8_t n) {
  15. if (n < MAX_TAB_SIZE) tabSize = n;
  16. }
  17. size_t IndentedPrint::write(uint8_t c) {
  18. size_t n = 0;
  19. if (isNewLine) n += writeTabs();
  20. n += sink->write(c);
  21. isNewLine = c == '\n';
  22. return n;
  23. }
  24. inline size_t IndentedPrint::writeTabs() {
  25. size_t n = 0;
  26. for (int i = 0; i < level * tabSize; i++) n += sink->write(' ');
  27. return n;
  28. }