forked from bblanchon/ArduinoJson
Moved PrettyPrintDecorator into the namespace ArduinoJson::Generator
This commit is contained in:
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "PrettyPrintDecorator.h"
|
#include "PrettyPrintDecorator.h"
|
||||||
|
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
size_t PrettyPrintDecorator::write(uint8_t c)
|
size_t PrettyPrintDecorator::write(uint8_t c)
|
||||||
{
|
{
|
||||||
size_t n = inString ? handleStringChar(c) : handleMarkupChar(c);
|
size_t n = inString ? handleStringChar(c) : handleMarkupChar(c);
|
||||||
|
@ -8,55 +8,60 @@
|
|||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
class PrettyPrintDecorator : public Print
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
|
||||||
PrettyPrintDecorator(Print& p)
|
|
||||||
: indent(0), sink(p)
|
|
||||||
{
|
{
|
||||||
previousChar = 0;
|
class PrettyPrintDecorator : public Print
|
||||||
inString = false;
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PrettyPrintDecorator(Print& p)
|
||||||
|
: indent(0), sink(p)
|
||||||
|
{
|
||||||
|
previousChar = 0;
|
||||||
|
inString = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual size_t write(uint8_t);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int indent;
|
||||||
|
uint8_t previousChar;
|
||||||
|
Print& sink;
|
||||||
|
bool inString;
|
||||||
|
|
||||||
|
bool inEmptyBlock()
|
||||||
|
{
|
||||||
|
return previousChar == '{' || previousChar == '[';
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t handleStringChar(uint8_t);
|
||||||
|
size_t handleMarkupChar(uint8_t);
|
||||||
|
|
||||||
|
size_t handleBlockClose(uint8_t);
|
||||||
|
size_t handleBlockOpen(uint8_t);
|
||||||
|
size_t handleColumn();
|
||||||
|
size_t handleComma();
|
||||||
|
size_t handleQuoteOpen();
|
||||||
|
size_t handleNormalChar(uint8_t);
|
||||||
|
|
||||||
|
size_t breakAndIndent();
|
||||||
|
|
||||||
|
size_t breakThenWrite(uint8_t c)
|
||||||
|
{
|
||||||
|
return breakAndIndent() + writeChar(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t writeThenBreak(uint8_t c)
|
||||||
|
{
|
||||||
|
return writeChar(c) + breakAndIndent();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t writeChar(uint8_t c)
|
||||||
|
{
|
||||||
|
return sink.write(c);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
virtual size_t write(uint8_t);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int indent;
|
|
||||||
uint8_t previousChar;
|
|
||||||
Print& sink;
|
|
||||||
bool inString;
|
|
||||||
|
|
||||||
bool inEmptyBlock()
|
|
||||||
{
|
|
||||||
return previousChar == '{' || previousChar == '[';
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t handleStringChar(uint8_t);
|
|
||||||
size_t handleMarkupChar(uint8_t);
|
|
||||||
|
|
||||||
size_t handleBlockClose(uint8_t);
|
|
||||||
size_t handleBlockOpen(uint8_t);
|
|
||||||
size_t handleColumn();
|
|
||||||
size_t handleComma();
|
|
||||||
size_t handleQuoteOpen();
|
|
||||||
size_t handleNormalChar(uint8_t);
|
|
||||||
|
|
||||||
size_t breakAndIndent();
|
|
||||||
|
|
||||||
size_t breakThenWrite(uint8_t c)
|
|
||||||
{
|
|
||||||
return breakAndIndent() + writeChar(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t writeThenBreak(uint8_t c)
|
|
||||||
{
|
|
||||||
return writeChar(c) + breakAndIndent();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t writeChar(uint8_t c)
|
|
||||||
{
|
|
||||||
return sink.write(c);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
using namespace ArduinoJson::Internals;
|
using namespace ArduinoJson::Internals;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
using namespace ArduinoJson::Internals;
|
using namespace ArduinoJson::Internals;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
using namespace ArduinoJson::Internals;
|
using namespace ArduinoJson::Internals;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
|
Reference in New Issue
Block a user