diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-09-07 12:57:04 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-09-07 12:57:04 +0200 |
commit | 0558244645611f314f47e0fa427f7323ce253eaf (patch) | |
tree | 824bcd55ec8577703345106d0a08e167407500a7 /include/lib/ArduinoJson/Serialization/Prettyfier.hpp | |
parent | 0248c6352f2117e50fac71dd632a79d8fa4f8737 (diff) |
remove external libraries from main branch
Diffstat (limited to 'include/lib/ArduinoJson/Serialization/Prettyfier.hpp')
-rw-r--r-- | include/lib/ArduinoJson/Serialization/Prettyfier.hpp | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/include/lib/ArduinoJson/Serialization/Prettyfier.hpp b/include/lib/ArduinoJson/Serialization/Prettyfier.hpp deleted file mode 100644 index 8b4f0d2..0000000 --- a/include/lib/ArduinoJson/Serialization/Prettyfier.hpp +++ /dev/null @@ -1,133 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "IndentedPrint.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Converts a compact JSON string into an indented one. -template <typename Print> -class Prettyfier { - public: - explicit Prettyfier(IndentedPrint<Print>& p) : _sink(p) { - _previousChar = 0; - _inString = false; - } - - size_t print(char c) { - size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); - _previousChar = c; - return n; - } - - size_t print(const char* s) { - // TODO: optimize - size_t n = 0; - while (*s) n += print(*s++); - return n; - } - - private: - Prettyfier& operator=(const Prettyfier&); // cannot be assigned - - bool inEmptyBlock() { - return _previousChar == '{' || _previousChar == '['; - } - - size_t handleStringChar(char c) { - bool isQuote = c == '"' && _previousChar != '\\'; - - if (isQuote) _inString = false; - - return _sink.print(c); - } - - size_t handleMarkupChar(char c) { - switch (c) { - case '{': - case '[': - return writeBlockOpen(c); - - case '}': - case ']': - return writeBlockClose(c); - - case ':': - return writeColon(); - - case ',': - return writeComma(); - - case '"': - return writeQuoteOpen(); - - default: - return writeNormalChar(c); - } - } - - size_t writeBlockClose(char c) { - size_t n = 0; - n += unindentIfNeeded(); - n += _sink.print(c); - return n; - } - - size_t writeBlockOpen(char c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.print(c); - return n; - } - - size_t writeColon() { - size_t n = 0; - n += _sink.print(": "); - return n; - } - - size_t writeComma() { - size_t n = 0; - n += _sink.print(",\r\n"); - return n; - } - - size_t writeQuoteOpen() { - _inString = true; - size_t n = 0; - n += indentIfNeeded(); - n += _sink.print('"'); - return n; - } - - size_t writeNormalChar(char c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.print(c); - return n; - } - - size_t indentIfNeeded() { - if (!inEmptyBlock()) return 0; - - _sink.indent(); - return _sink.print("\r\n"); - } - - size_t unindentIfNeeded() { - if (inEmptyBlock()) return 0; - - _sink.unindent(); - return _sink.print("\r\n"); - } - - char _previousChar; - IndentedPrint<Print>& _sink; - bool _inString; -}; -} -} |