Files
ArduinoJson/src/Internals/IndentedPrint.cpp

41 lines
728 B
C++
Raw Normal View History

2014-10-23 23:39:22 +02:00
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include "ArduinoJson/Internals/IndentedPrint.hpp"
2014-10-16 16:25:42 +02:00
2014-10-18 23:05:54 +02:00
using namespace ArduinoJson::Internals;
2014-10-16 16:25:42 +02:00
2014-10-23 19:54:00 +02:00
void IndentedPrint::indent() {
if (level < MAX_LEVEL) level++;
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
void IndentedPrint::unindent() {
if (level > 0) level--;
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
void IndentedPrint::setTabSize(uint8_t n) {
if (n < MAX_TAB_SIZE) tabSize = n;
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
size_t IndentedPrint::write(uint8_t c) {
size_t n = 0;
2014-10-16 16:25:42 +02:00
if (isNewLine) n += writeTabs();
2014-10-16 16:25:42 +02:00
2014-10-23 19:54:00 +02:00
n += sink->write(c);
2014-10-16 16:25:42 +02:00
2014-10-23 19:54:00 +02:00
isNewLine = c == '\n';
2014-10-16 16:25:42 +02:00
2014-10-23 19:54:00 +02:00
return n;
2014-10-16 16:25:42 +02:00
}
2014-10-23 19:54:00 +02:00
inline size_t IndentedPrint::writeTabs() {
size_t n = 0;
2014-10-16 16:25:42 +02:00
for (int i = 0; i < level * tabSize; i++) n += sink->write(' ');
2014-10-16 16:25:42 +02:00
2014-10-23 19:54:00 +02:00
return n;
2014-10-07 11:22:10 +02:00
}