2014-08-26 09:28:41 +02:00
|
|
|
/*
|
|
|
|
* Arduino JSON library
|
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Print.h"
|
|
|
|
|
2014-08-26 10:16:13 +02:00
|
|
|
namespace ArduinoJson
|
2014-08-26 09:28:41 +02:00
|
|
|
{
|
2014-08-26 10:16:13 +02:00
|
|
|
namespace Generator
|
2014-08-26 09:28:41 +02:00
|
|
|
{
|
2014-08-26 10:16:13 +02:00
|
|
|
class IndentedPrint : public Print
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
IndentedPrint(Print& p)
|
|
|
|
: sink(p)
|
|
|
|
{
|
|
|
|
level = 0;
|
2014-08-26 11:59:41 +02:00
|
|
|
tabSize = 2;
|
2014-08-26 10:16:13 +02:00
|
|
|
isNewLine = true;
|
|
|
|
}
|
2014-08-26 09:28:41 +02:00
|
|
|
|
2014-08-26 10:16:13 +02:00
|
|
|
virtual size_t write(uint8_t);
|
2014-08-26 09:53:32 +02:00
|
|
|
|
2014-08-26 10:16:13 +02:00
|
|
|
void indent();
|
|
|
|
void unindent();
|
2014-08-26 11:58:33 +02:00
|
|
|
void setTabSize(uint8_t n);
|
2014-08-26 09:28:41 +02:00
|
|
|
|
2014-08-26 10:16:13 +02:00
|
|
|
private:
|
|
|
|
Print& sink;
|
2014-08-26 11:58:33 +02:00
|
|
|
uint8_t level : 4;
|
|
|
|
uint8_t tabSize : 3;
|
2014-08-26 10:16:13 +02:00
|
|
|
bool isNewLine : 1;
|
2014-08-26 11:58:33 +02:00
|
|
|
|
2014-08-26 10:16:13 +02:00
|
|
|
size_t writeTabs();
|
2014-08-26 11:58:33 +02:00
|
|
|
|
2014-08-26 12:03:50 +02:00
|
|
|
static const int MAX_LEVEL = 15; // because it's only 4 bits
|
|
|
|
static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
|
2014-08-26 10:16:13 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2014-08-26 09:28:41 +02:00
|
|
|
|