mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Renamed srcs/ into src/
This commit is contained in:
		| @@ -3,5 +3,5 @@ project(ArduinoJson) | |||||||
|  |  | ||||||
| enable_testing() | enable_testing() | ||||||
|  |  | ||||||
| add_subdirectory(srcs) | add_subdirectory(src) | ||||||
| add_subdirectory(test) | add_subdirectory(test) | ||||||
| @@ -1,40 +1,40 @@ | |||||||
| /*
 | /*
 | ||||||
|  * Arduino JSON library |  * Arduino JSON library | ||||||
|  * Benoit Blanchon 2014 - MIT License |  * Benoit Blanchon 2014 - MIT License | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #ifndef ARDUINO | #ifndef ARDUINO | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/Arduino/Print.h" | #include "ArduinoJson/Arduino/Print.h" | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
| 
 | 
 | ||||||
| size_t Print::print(const char s[]) | size_t Print::print(const char s[]) | ||||||
| { | { | ||||||
|     size_t n = 0; |     size_t n = 0; | ||||||
|     while (*s) |     while (*s) | ||||||
|     { |     { | ||||||
|         n += write(*s++); |         n += write(*s++); | ||||||
|     } |     } | ||||||
|     return n; |     return n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t Print::print(double value, int digits) | size_t Print::print(double value, int digits) | ||||||
| { | { | ||||||
|     char tmp[32]; |     char tmp[32]; | ||||||
|     sprintf(tmp, "%.*lg", digits+1, value); |     sprintf(tmp, "%.*lg", digits+1, value); | ||||||
|     return print(tmp); |     return print(tmp); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t Print::print(long value) | size_t Print::print(long value) | ||||||
| { | { | ||||||
|     char tmp[32]; |     char tmp[32]; | ||||||
|     sprintf(tmp, "%ld", value); |     sprintf(tmp, "%ld", value); | ||||||
|     return print(tmp); |     return print(tmp); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t Print::println() | size_t Print::println() | ||||||
| { | { | ||||||
|     return write('\r') + write('\n'); |     return write('\r') + write('\n'); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| file(GLOB_RECURSE INC_FILES ../include/*.h) | file(GLOB_RECURSE INC_FILES ../include/*.h) | ||||||
| file(GLOB_RECURSE SRC_FILES *.cpp) | file(GLOB_RECURSE SRC_FILES *.cpp) | ||||||
| 
 | 
 | ||||||
| include_directories(../include) | include_directories(../include) | ||||||
| 
 | 
 | ||||||
| add_library(ArduinoJson ${SRC_FILES} ${INC_FILES}) | add_library(ArduinoJson ${SRC_FILES} ${INC_FILES}) | ||||||
| @@ -1 +1 @@ | |||||||
| #include "ArduinoJson/Internals/CompactJsonWriter.h" | #include "ArduinoJson/Internals/CompactJsonWriter.h" | ||||||
| @@ -1,45 +1,45 @@ | |||||||
| /*
 | /*
 | ||||||
|  * Arduino JSON library |  * Arduino JSON library | ||||||
|  * Benoit Blanchon 2014 - MIT License |  * Benoit Blanchon 2014 - MIT License | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/Internals/EscapedString.h" | #include "ArduinoJson/Internals/EscapedString.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Internals; | using namespace ArduinoJson::Internals; | ||||||
| 
 | 
 | ||||||
| static inline char getSpecialChar(char c) | static inline char getSpecialChar(char c) | ||||||
| { | { | ||||||
|     // Optimized for code size on a 8-bit AVR
 |     // Optimized for code size on a 8-bit AVR
 | ||||||
| 
 | 
 | ||||||
|     const char* p = "\"\"\\\\\bb\ff\nn\rr\tt\0"; |     const char* p = "\"\"\\\\\bb\ff\nn\rr\tt\0"; | ||||||
| 
 | 
 | ||||||
|     while (p[0] && p[0] != c) |     while (p[0] && p[0] != c) | ||||||
|     { |     { | ||||||
|         p += 2; |         p += 2; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return p[1]; |     return p[1]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline size_t printCharTo(char c, Print* p) | static inline size_t printCharTo(char c, Print* p) | ||||||
| { | { | ||||||
|     char specialChar = getSpecialChar(c); |     char specialChar = getSpecialChar(c); | ||||||
| 
 | 
 | ||||||
|     return specialChar != 0 |     return specialChar != 0 | ||||||
|         ? p->write('\\') + p->write(specialChar) |         ? p->write('\\') + p->write(specialChar) | ||||||
|         : p->write(c); |         : p->write(c); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t EscapedString::printTo(const char* s, Print* p) | size_t EscapedString::printTo(const char* s, Print* p) | ||||||
| { | { | ||||||
|     if (!s) return p->print("null"); |     if (!s) return p->print("null"); | ||||||
|      |      | ||||||
|     size_t n = p->write('\"'); |     size_t n = p->write('\"'); | ||||||
| 
 | 
 | ||||||
|     while (*s) |     while (*s) | ||||||
|     { |     { | ||||||
|         n += printCharTo(*s++, p); |         n += printCharTo(*s++, p); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return n + p->write('\"'); |     return n + p->write('\"'); | ||||||
| } | } | ||||||
| @@ -1,45 +1,45 @@ | |||||||
| #include "ArduinoJson/Internals/IndentedPrint.h" | #include "ArduinoJson/Internals/IndentedPrint.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Generator; | using namespace ArduinoJson::Generator; | ||||||
| 
 | 
 | ||||||
| void IndentedPrint::indent() | void IndentedPrint::indent() | ||||||
| { | { | ||||||
|     if (level < MAX_LEVEL) |     if (level < MAX_LEVEL) | ||||||
|         level++; |         level++; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void IndentedPrint::unindent() | void IndentedPrint::unindent() | ||||||
| { | { | ||||||
|     if (level > 0) |     if (level > 0) | ||||||
|         level--; |         level--; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void IndentedPrint::setTabSize(uint8_t n) | void IndentedPrint::setTabSize(uint8_t n) | ||||||
| { | { | ||||||
|     if (n < MAX_TAB_SIZE) |     if (n < MAX_TAB_SIZE) | ||||||
|         tabSize = n; |         tabSize = n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t IndentedPrint::write(uint8_t c) | size_t IndentedPrint::write(uint8_t c) | ||||||
| { | { | ||||||
|     size_t n = 0; |     size_t n = 0; | ||||||
| 
 | 
 | ||||||
|     if (isNewLine) |     if (isNewLine) | ||||||
|         n += writeTabs(); |         n += writeTabs(); | ||||||
| 
 | 
 | ||||||
|     n += sink->write(c); |     n += sink->write(c); | ||||||
| 
 | 
 | ||||||
|     isNewLine = c == '\n'; |     isNewLine = c == '\n'; | ||||||
| 
 | 
 | ||||||
|     return n; |     return n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| inline size_t IndentedPrint::writeTabs() | inline size_t IndentedPrint::writeTabs() | ||||||
| { | { | ||||||
|     size_t n = 0; |     size_t n = 0; | ||||||
| 
 | 
 | ||||||
|     for (int i = 0; i < level*tabSize; i++) |     for (int i = 0; i < level*tabSize; i++) | ||||||
|         n += sink->write(' '); |         n += sink->write(' '); | ||||||
| 
 | 
 | ||||||
|     return n; |     return n; | ||||||
| } | } | ||||||
| @@ -1,166 +1,166 @@ | |||||||
| #include "ArduinoJson/Internals/JsonNode.h" | #include "ArduinoJson/Internals/JsonNode.h" | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/Internals/JsonWriter.h" | #include "ArduinoJson/Internals/JsonWriter.h" | ||||||
| #include "ArduinoJson/JsonArray.h" | #include "ArduinoJson/JsonArray.h" | ||||||
| #include "ArduinoJson/JsonObject.h" | #include "ArduinoJson/JsonObject.h" | ||||||
| #include "ArduinoJson/JsonBuffer.h" | #include "ArduinoJson/JsonBuffer.h" | ||||||
| 
 | 
 | ||||||
| void JsonNode::writeTo(JsonWriter& writer) | void JsonNode::writeTo(JsonWriter& writer) | ||||||
| { | { | ||||||
|     switch (type) |     switch (type) | ||||||
|     { |     { | ||||||
|     case JSON_PROXY: |     case JSON_PROXY: | ||||||
|         content.asProxy.target->writeTo(writer); |         content.asProxy.target->writeTo(writer); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     case JSON_ARRAY: |     case JSON_ARRAY: | ||||||
|         writeArrayTo(writer); |         writeArrayTo(writer); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     case JSON_OBJECT: |     case JSON_OBJECT: | ||||||
|         writeObjectTo(writer); |         writeObjectTo(writer); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     case JSON_STRING: |     case JSON_STRING: | ||||||
|         writer.writeString(content.asString); |         writer.writeString(content.asString); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     case JSON_LONG: |     case JSON_LONG: | ||||||
|         writer.writeInteger(content.asInteger); |         writer.writeInteger(content.asInteger); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     case JSON_BOOLEAN: |     case JSON_BOOLEAN: | ||||||
|         writer.writeBoolean(content.asBoolean); |         writer.writeBoolean(content.asBoolean); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|     default: // >= JSON_DOUBLE_0_DECIMALS
 |     default: // >= JSON_DOUBLE_0_DECIMALS
 | ||||||
|         writer.writeDouble(content.asDouble, type - JSON_DOUBLE_0_DECIMALS); |         writer.writeDouble(content.asDouble, type - JSON_DOUBLE_0_DECIMALS); | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::addChild(JsonNode* childToAdd) | void JsonNode::addChild(JsonNode* childToAdd) | ||||||
| { | { | ||||||
|     if (type == JSON_PROXY)  |     if (type == JSON_PROXY)  | ||||||
|         return content.asProxy.target->addChild(childToAdd); |         return content.asProxy.target->addChild(childToAdd); | ||||||
| 
 | 
 | ||||||
|     if (type != JSON_ARRAY && type != JSON_OBJECT)  |     if (type != JSON_ARRAY && type != JSON_OBJECT)  | ||||||
|         return; |         return; | ||||||
| 
 | 
 | ||||||
|     JsonNode* lastChild = content.asContainer.child; |     JsonNode* lastChild = content.asContainer.child; | ||||||
| 
 | 
 | ||||||
|     if (!lastChild) |     if (!lastChild) | ||||||
|     { |     { | ||||||
|         content.asContainer.child = childToAdd; |         content.asContainer.child = childToAdd; | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     while (lastChild->next) |     while (lastChild->next) | ||||||
|         lastChild = lastChild->next; |         lastChild = lastChild->next; | ||||||
| 
 | 
 | ||||||
|     lastChild->next = childToAdd; |     lastChild->next = childToAdd; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::removeChild(JsonNode* childToRemove) | void JsonNode::removeChild(JsonNode* childToRemove) | ||||||
| { | { | ||||||
|     if (type == JSON_PROXY) |     if (type == JSON_PROXY) | ||||||
|         return content.asProxy.target->removeChild(childToRemove); |         return content.asProxy.target->removeChild(childToRemove); | ||||||
| 
 | 
 | ||||||
|     if (type != JSON_ARRAY && type != JSON_OBJECT) return; |     if (type != JSON_ARRAY && type != JSON_OBJECT) return; | ||||||
| 
 | 
 | ||||||
|     if (content.asContainer.child == childToRemove) |     if (content.asContainer.child == childToRemove) | ||||||
|     { |     { | ||||||
|         content.asContainer.child = childToRemove->next; |         content.asContainer.child = childToRemove->next; | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (JsonNode* child = content.asContainer.child; child; child = child->next) |     for (JsonNode* child = content.asContainer.child; child; child = child->next) | ||||||
|     { |     { | ||||||
|         if (child->next == childToRemove) |         if (child->next == childToRemove) | ||||||
|             child->next = childToRemove->next; |             child->next = childToRemove->next; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::writeArrayTo(JsonWriter& writer) | void JsonNode::writeArrayTo(JsonWriter& writer) | ||||||
| { | { | ||||||
|     JsonNode* child = content.asContainer.child; |     JsonNode* child = content.asContainer.child; | ||||||
| 
 | 
 | ||||||
|     if (child) |     if (child) | ||||||
|     { |     { | ||||||
|         writer.beginArray(); |         writer.beginArray(); | ||||||
| 
 | 
 | ||||||
|         for (;;) |         for (;;) | ||||||
|         { |         { | ||||||
|             child->writeTo(writer); |             child->writeTo(writer); | ||||||
| 
 | 
 | ||||||
|             child = child->next; |             child = child->next; | ||||||
|             if (!child) break; |             if (!child) break; | ||||||
|              |              | ||||||
|             writer.writeComma(); |             writer.writeComma(); | ||||||
|         }  |         }  | ||||||
| 
 | 
 | ||||||
|         writer.endArray(); |         writer.endArray(); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         writer.writeEmptyArray(); |         writer.writeEmptyArray(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::writeObjectTo(JsonWriter& writer) | void JsonNode::writeObjectTo(JsonWriter& writer) | ||||||
| { | { | ||||||
|     JsonNode* child = content.asContainer.child; |     JsonNode* child = content.asContainer.child; | ||||||
| 
 | 
 | ||||||
|     if (child) |     if (child) | ||||||
|     { |     { | ||||||
|         writer.beginObject(); |         writer.beginObject(); | ||||||
| 
 | 
 | ||||||
|         for (;;) |         for (;;) | ||||||
|         { |         { | ||||||
|             writer.writeString(child->content.asKey.key); |             writer.writeString(child->content.asKey.key); | ||||||
|             writer.writeColon(); |             writer.writeColon(); | ||||||
|             child->content.asKey.value->writeTo(writer); |             child->content.asKey.value->writeTo(writer); | ||||||
| 
 | 
 | ||||||
|             child = child->next; |             child = child->next; | ||||||
|             if (!child) break; |             if (!child) break; | ||||||
| 
 | 
 | ||||||
|             writer.writeComma(); |             writer.writeComma(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         writer.endObject(); |         writer.endObject(); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         writer.writeEmptyObject(); |         writer.writeEmptyObject(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::setAsProxyOfSelf() | void JsonNode::setAsProxyOfSelf() | ||||||
| { | { | ||||||
|     JsonBuffer* buffer = content.asContainer.buffer; |     JsonBuffer* buffer = content.asContainer.buffer; | ||||||
|     if (!buffer) return; |     if (!buffer) return; | ||||||
|          |          | ||||||
|     JsonNode* newNode = buffer->createNode();  |     JsonNode* newNode = buffer->createNode();  | ||||||
|     if (!newNode) return; |     if (!newNode) return; | ||||||
| 
 | 
 | ||||||
|     *newNode = *this; |     *newNode = *this; | ||||||
| 
 | 
 | ||||||
|     setAsProxyOf(newNode); |     setAsProxyOf(newNode); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonNode::duplicate(JsonNode* other) | void JsonNode::duplicate(JsonNode* other) | ||||||
| { | { | ||||||
|     if (!other) |     if (!other) | ||||||
|     { |     { | ||||||
|         type = JSON_UNDEFINED; |         type = JSON_UNDEFINED; | ||||||
|     } |     } | ||||||
|     else  if (other->type == JSON_ARRAY || other->type==JSON_OBJECT) |     else  if (other->type == JSON_ARRAY || other->type==JSON_OBJECT) | ||||||
|     { |     { | ||||||
|         other->setAsProxyOfSelf(); |         other->setAsProxyOfSelf(); | ||||||
|         setAsProxyOf(other->content.asProxy.target); |         setAsProxyOf(other->content.asProxy.target); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         *this = *other; |         *this = *other; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,25 +1,25 @@ | |||||||
| #include "ArduinoJson/Internals/JsonWriter.h" | #include "ArduinoJson/Internals/JsonWriter.h" | ||||||
| #include "ArduinoJson/Internals/EscapedString.h" | #include "ArduinoJson/Internals/EscapedString.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Internals; | using namespace ArduinoJson::Internals; | ||||||
| 
 | 
 | ||||||
| void JsonWriter::writeString(char const* value) | void JsonWriter::writeString(char const* value) | ||||||
| { | { | ||||||
|     _length += EscapedString::printTo(value, _sink); |     _length += EscapedString::printTo(value, _sink); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonWriter::writeInteger(long value) | void JsonWriter::writeInteger(long value) | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|     _length += _sink->print(value); |     _length += _sink->print(value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonWriter::writeBoolean(bool value) | void JsonWriter::writeBoolean(bool value) | ||||||
| { | { | ||||||
|     _length += _sink->print(value ? "true" : "false"); |     _length += _sink->print(value ? "true" : "false"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonWriter::writeDouble(double value, int decimals) | void JsonWriter::writeDouble(double value, int decimals) | ||||||
| { | { | ||||||
|     _length += _sink->print(value, decimals); |     _length += _sink->print(value, decimals); | ||||||
| } | } | ||||||
| @@ -1 +1 @@ | |||||||
| #include "ArduinoJson/Internals/PrettyJsonWriter.h" | #include "ArduinoJson/Internals/PrettyJsonWriter.h" | ||||||
| @@ -1,17 +1,17 @@ | |||||||
| /*
 | /*
 | ||||||
|  * Arduino JSON library |  * Arduino JSON library | ||||||
|  * Benoit Blanchon 2014 - MIT License |  * Benoit Blanchon 2014 - MIT License | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/Internals/StringBuilder.h" | #include "ArduinoJson/Internals/StringBuilder.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Internals; | using namespace ArduinoJson::Internals; | ||||||
| 
 | 
 | ||||||
| size_t StringBuilder::write(uint8_t c) | size_t StringBuilder::write(uint8_t c) | ||||||
| { | { | ||||||
|     if (length >= capacity) return 0; |     if (length >= capacity) return 0; | ||||||
| 
 | 
 | ||||||
|     buffer[length++] = c; |     buffer[length++] = c; | ||||||
|     buffer[length] = 0; |     buffer[length] = 0; | ||||||
|     return 1; |     return 1; | ||||||
| } | } | ||||||
| @@ -1,86 +1,86 @@ | |||||||
| #include "ArduinoJson/JsonArray.h" | #include "ArduinoJson/JsonArray.h" | ||||||
| #include "ArduinoJson/JsonObject.h" | #include "ArduinoJson/JsonObject.h" | ||||||
| #include "ArduinoJson/JsonValue.h" | #include "ArduinoJson/JsonValue.h" | ||||||
| 
 | 
 | ||||||
| JsonValue JsonArray::operator[](int index) const | JsonValue JsonArray::operator[](int index) const | ||||||
| { | { | ||||||
|     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) |     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) | ||||||
|     { |     { | ||||||
|         if (!index) return JsonValue(*it); |         if (!index) return JsonValue(*it); | ||||||
|         index--; |         index--; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return JsonValue(); |     return JsonValue(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonArray::add(bool value) | void JsonArray::add(bool value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|     if (!node) return; |     if (!node) return; | ||||||
| 
 | 
 | ||||||
|     node->setAsBoolean(value); |     node->setAsBoolean(value); | ||||||
|     addChild(node); |     addChild(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonArray::add(char const* value) | void JsonArray::add(char const* value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|     if (!node) return; |     if (!node) return; | ||||||
| 
 | 
 | ||||||
|     node->setAsString(value); |     node->setAsString(value); | ||||||
|     addChild(node); |     addChild(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonArray::add(double value, int decimals) | void JsonArray::add(double value, int decimals) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|     if (!node) return; |     if (!node) return; | ||||||
| 
 | 
 | ||||||
|     node->setAsDouble(value, decimals); |     node->setAsDouble(value, decimals); | ||||||
|     addChild(node); |     addChild(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonArray::add(long value) | void JsonArray::add(long value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|     if (!node) return; |     if (!node) return; | ||||||
| 
 | 
 | ||||||
|     node->setAsLong(value); |     node->setAsLong(value); | ||||||
|     addChild(node); |     addChild(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // TODO: we should have the same issue as in JsonValue
 | // TODO: we should have the same issue as in JsonValue
 | ||||||
| void JsonArray::add(JsonContainer nestedContainer) | void JsonArray::add(JsonContainer nestedContainer) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|     if (!node) return; |     if (!node) return; | ||||||
| 
 | 
 | ||||||
|     node->duplicate(nestedContainer._node); |     node->duplicate(nestedContainer._node); | ||||||
|     addChild(node); |     addChild(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonArray JsonArray::createNestedArray() | JsonArray JsonArray::createNestedArray() | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|      |      | ||||||
|     if (node) |     if (node) | ||||||
|     { |     { | ||||||
|         node->setAsArray(_node->getContainerBuffer()); |         node->setAsArray(_node->getContainerBuffer()); | ||||||
|         addChild(node); |         addChild(node); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return JsonArray(node); |     return JsonArray(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonObject JsonArray::createNestedObject() | JsonObject JsonArray::createNestedObject() | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
|      |      | ||||||
|     if (node) |     if (node) | ||||||
|     { |     { | ||||||
|         node->setAsObject(_node->getContainerBuffer()); |         node->setAsObject(_node->getContainerBuffer()); | ||||||
|         addChild(node); |         addChild(node); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return JsonObject(node); |     return JsonObject(node); | ||||||
| } | } | ||||||
| @@ -1,86 +1,86 @@ | |||||||
| #include "ArduinoJson/JsonBuffer.h" | #include "ArduinoJson/JsonBuffer.h" | ||||||
| 
 | 
 | ||||||
| #include <new> | #include <new> | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/JsonValue.h" | #include "ArduinoJson/JsonValue.h" | ||||||
| #include "ArduinoJson/Internals/JsonParser.h" | #include "ArduinoJson/Internals/JsonParser.h" | ||||||
| #include "ArduinoJson/Internals/JsonNode.h" | #include "ArduinoJson/Internals/JsonNode.h" | ||||||
| 
 | 
 | ||||||
| JsonValue JsonBuffer::createValue() | JsonValue JsonBuffer::createValue() | ||||||
| { | { | ||||||
|     return JsonValue(createNode()); |     return JsonValue(createNode()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createNode() | JsonNode* JsonBuffer::createNode() | ||||||
| { | { | ||||||
|     void* node = allocateNode(); |     void* node = allocateNode(); | ||||||
|     if (!node) return 0; |     if (!node) return 0; | ||||||
|          |          | ||||||
|     return new (node) JsonNode(); |     return new (node) JsonNode(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonArray JsonBuffer::parseArray(char* json) | JsonArray JsonBuffer::parseArray(char* json) | ||||||
| { | { | ||||||
|     JsonParser parser(this, json); |     JsonParser parser(this, json); | ||||||
|     return JsonArray(parser.parseAnything()); |     return JsonArray(parser.parseAnything()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createArrayNode() | JsonNode* JsonBuffer::createArrayNode() | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsArray(this); |         node->setAsArray(this); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createBoolNode(bool value) | JsonNode* JsonBuffer::createBoolNode(bool value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsBoolean(value); |         node->setAsBoolean(value); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createDoubleNode(double value, int decimals) | JsonNode* JsonBuffer::createDoubleNode(double value, int decimals) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsDouble(value, decimals); |         node->setAsDouble(value, decimals); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createLongNode(long value) | JsonNode* JsonBuffer::createLongNode(long value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsLong(value); |         node->setAsLong(value); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createObjectNode() | JsonNode* JsonBuffer::createObjectNode() | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsObject(this); |         node->setAsObject(this); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonBuffer::createStringNode(const char* value) | JsonNode* JsonBuffer::createStringNode(const char* value) | ||||||
| { | { | ||||||
|     JsonNode* node = createNode(); |     JsonNode* node = createNode(); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsString(value); |         node->setAsString(value); | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| } | } | ||||||
| @@ -1,82 +1,82 @@ | |||||||
| #include "ArduinoJson/JsonContainer.h" | #include "ArduinoJson/JsonContainer.h" | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/JsonBuffer.h" | #include "ArduinoJson/JsonBuffer.h" | ||||||
| #include "ArduinoJson/Internals/StringBuilder.h" | #include "ArduinoJson/Internals/StringBuilder.h" | ||||||
| #include "ArduinoJson/Internals/CompactJsonWriter.h" | #include "ArduinoJson/Internals/CompactJsonWriter.h" | ||||||
| #include "ArduinoJson/Internals/PrettyJsonWriter.h" | #include "ArduinoJson/Internals/PrettyJsonWriter.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Internals; | using namespace ArduinoJson::Internals; | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const | size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const | ||||||
| { | { | ||||||
|     StringBuilder sb(buffer, bufferSize); |     StringBuilder sb(buffer, bufferSize); | ||||||
|     return printTo(sb); |     return printTo(sb); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::printTo(Print& p) const | size_t JsonContainer::printTo(Print& p) const | ||||||
| { | { | ||||||
|     CompactJsonWriter writer(&p); |     CompactJsonWriter writer(&p); | ||||||
|     _node->writeTo(writer); |     _node->writeTo(writer); | ||||||
|     return writer.bytesWritten(); |     return writer.bytesWritten(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::prettyPrintTo(char* buffer, size_t bufferSize) const | size_t JsonContainer::prettyPrintTo(char* buffer, size_t bufferSize) const | ||||||
| { | { | ||||||
|     StringBuilder sb(buffer, bufferSize); |     StringBuilder sb(buffer, bufferSize); | ||||||
|     return prettyPrintTo(sb); |     return prettyPrintTo(sb); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const | size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const | ||||||
| { | { | ||||||
|     PrettyJsonWriter writer(&p); |     PrettyJsonWriter writer(&p); | ||||||
|     _node->writeTo(writer); |     _node->writeTo(writer); | ||||||
|     return writer.bytesWritten(); |     return writer.bytesWritten(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::prettyPrintTo(Print& print) const | size_t JsonContainer::prettyPrintTo(Print& print) const | ||||||
| { | { | ||||||
|     IndentedPrint indentedPrint = IndentedPrint(print); |     IndentedPrint indentedPrint = IndentedPrint(print); | ||||||
|     return prettyPrintTo(indentedPrint); |     return prettyPrintTo(indentedPrint); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonContainer::createNode() | JsonNode* JsonContainer::createNode() | ||||||
| { | { | ||||||
|     if (!_node) return 0; |     if (!_node) return 0; | ||||||
| 
 | 
 | ||||||
|     JsonBuffer* buffer = _node->getContainerBuffer(); |     JsonBuffer* buffer = _node->getContainerBuffer(); | ||||||
|     if (!buffer) return 0; |     if (!buffer) return 0; | ||||||
| 
 | 
 | ||||||
|     return buffer->createNode(); |     return buffer->createNode(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool JsonContainer::operator==(const JsonContainer & other) const | bool JsonContainer::operator==(const JsonContainer & other) const | ||||||
| { | { | ||||||
|     if (_node == other._node) return true; |     if (_node == other._node) return true; | ||||||
|     if (!_node || !other._node) return false; |     if (!_node || !other._node) return false; | ||||||
|     return _node->getProxyTarget() == other._node->getProxyTarget(); |     return _node->getProxyTarget() == other._node->getProxyTarget(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonContainer::addChild(JsonNode* childToAdd) | void JsonContainer::addChild(JsonNode* childToAdd) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->addChild(childToAdd); |         _node->addChild(childToAdd); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonContainer::removeChild(JsonNode* childToRemove) | void JsonContainer::removeChild(JsonNode* childToRemove) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->removeChild(childToRemove); |         _node->removeChild(childToRemove); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t JsonContainer::size() const | size_t JsonContainer::size() const | ||||||
| { | { | ||||||
|     int size = 0; |     int size = 0; | ||||||
| 
 | 
 | ||||||
|     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) |     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) | ||||||
|     { |     { | ||||||
|         size++; |         size++; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return size; |     return size; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @@ -1,73 +1,73 @@ | |||||||
| #include "ArduinoJson/JsonObject.h" | #include "ArduinoJson/JsonObject.h" | ||||||
| 
 | 
 | ||||||
| #include <string.h> // for strcmp
 | #include <string.h> // for strcmp
 | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/JsonBuffer.h" | #include "ArduinoJson/JsonBuffer.h" | ||||||
| #include "ArduinoJson/JsonValue.h" | #include "ArduinoJson/JsonValue.h" | ||||||
| #include "ArduinoJson/Internals/EscapedString.h" | #include "ArduinoJson/Internals/EscapedString.h" | ||||||
| #include "ArduinoJson/Internals/JsonNode.h" | #include "ArduinoJson/Internals/JsonNode.h" | ||||||
| #include "ArduinoJson/Internals/StringBuilder.h" | #include "ArduinoJson/Internals/StringBuilder.h" | ||||||
| 
 | 
 | ||||||
| using namespace ArduinoJson::Internals; | using namespace ArduinoJson::Internals; | ||||||
| 
 | 
 | ||||||
| JsonValue JsonObject::operator[](char const* key) | JsonValue JsonObject::operator[](char const* key) | ||||||
| { | { | ||||||
|     JsonNode* node = getOrCreateNodeAt(key); |     JsonNode* node = getOrCreateNodeAt(key); | ||||||
|     return JsonValue(node); |     return JsonValue(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonObject::remove(char const* key) | void JsonObject::remove(char const* key) | ||||||
| { | { | ||||||
|     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) |     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) | ||||||
|     { |     { | ||||||
|         const char* childKey = it->getAsObjectKey(); |         const char* childKey = it->getAsObjectKey(); | ||||||
| 
 | 
 | ||||||
|         if (!strcmp(childKey, key)) |         if (!strcmp(childKey, key)) | ||||||
|         { |         { | ||||||
|             removeChild(*it); |             removeChild(*it); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonArray JsonObject::createNestedArray(char const* key) | JsonArray JsonObject::createNestedArray(char const* key) | ||||||
| { | { | ||||||
|     JsonNode* node = getOrCreateNodeAt(key); |     JsonNode* node = getOrCreateNodeAt(key); | ||||||
| 
 | 
 | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsArray(_node->getContainerBuffer()); |         node->setAsArray(_node->getContainerBuffer()); | ||||||
| 
 | 
 | ||||||
|     return JsonArray(node); |     return JsonArray(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonObject JsonObject::createNestedObject(char const* key) | JsonObject JsonObject::createNestedObject(char const* key) | ||||||
| { | { | ||||||
|     JsonNode* node = getOrCreateNodeAt(key); |     JsonNode* node = getOrCreateNodeAt(key); | ||||||
|      |      | ||||||
|     if (node) |     if (node) | ||||||
|         node->setAsObject(_node->getContainerBuffer()); |         node->setAsObject(_node->getContainerBuffer()); | ||||||
| 
 | 
 | ||||||
|     return JsonObject(node); |     return JsonObject(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonNode* JsonObject::getOrCreateNodeAt(const char* key) | JsonNode* JsonObject::getOrCreateNodeAt(const char* key) | ||||||
| { | { | ||||||
|     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) |     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) | ||||||
|     { |     { | ||||||
|         const char* childKey = it->getAsObjectKey(); |         const char* childKey = it->getAsObjectKey(); | ||||||
| 
 | 
 | ||||||
|         if (!strcmp(childKey, key)) |         if (!strcmp(childKey, key)) | ||||||
|             return it->getAsObjectValue(); |             return it->getAsObjectValue(); | ||||||
|     } |     } | ||||||
|        |        | ||||||
|     JsonNode* newValueNode = createNode(); |     JsonNode* newValueNode = createNode(); | ||||||
|     if (!newValueNode) return 0; |     if (!newValueNode) return 0; | ||||||
|      |      | ||||||
|     JsonNode* newKeyNode = createNode(); |     JsonNode* newKeyNode = createNode(); | ||||||
|     if (!newKeyNode) return 0; |     if (!newKeyNode) return 0; | ||||||
| 
 | 
 | ||||||
|     newKeyNode->setAsObjectKeyValue(key, newValueNode); |     newKeyNode->setAsObjectKeyValue(key, newValueNode); | ||||||
| 
 | 
 | ||||||
|     addChild(newKeyNode); |     addChild(newKeyNode); | ||||||
| 
 | 
 | ||||||
|     return newValueNode; |     return newValueNode; | ||||||
| } | } | ||||||
| @@ -1,59 +1,59 @@ | |||||||
| #include "ArduinoJson/JsonValue.h" | #include "ArduinoJson/JsonValue.h" | ||||||
| 
 | 
 | ||||||
| #include "ArduinoJson/JsonArray.h" | #include "ArduinoJson/JsonArray.h" | ||||||
| #include "ArduinoJson/JsonObject.h" | #include "ArduinoJson/JsonObject.h" | ||||||
| #include "ArduinoJson/Internals/JsonNode.h" | #include "ArduinoJson/Internals/JsonNode.h" | ||||||
| 
 | 
 | ||||||
| void JsonValue::operator=(bool value) | void JsonValue::operator=(bool value) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->setAsBoolean(value); |         _node->setAsBoolean(value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonValue::operator=(char const* value) | void JsonValue::operator=(char const* value) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->setAsString(value); |         _node->setAsString(value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonValue::set(double value, int decimals) | void JsonValue::set(double value, int decimals) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->setAsDouble(value, decimals); |         _node->setAsDouble(value, decimals); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void JsonValue::operator=(int value) | void JsonValue::operator=(int value) | ||||||
| { | { | ||||||
|     if (_node) |     if (_node) | ||||||
|         _node->setAsLong(value); |         _node->setAsLong(value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator bool() const | JsonValue::operator bool() const | ||||||
| { | { | ||||||
|     return _node ? _node->getAsBoolean() : false; |     return _node ? _node->getAsBoolean() : false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator char const*() const | JsonValue::operator char const*() const | ||||||
| { | { | ||||||
|     return _node ? _node->getAsString() : 0; |     return _node ? _node->getAsString() : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator double() const | JsonValue::operator double() const | ||||||
| { | { | ||||||
|     return _node ? _node->getAsDouble() : 0; |     return _node ? _node->getAsDouble() : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator long() const | JsonValue::operator long() const | ||||||
| { | { | ||||||
|     return _node ? _node->getAsInteger() : 0; |     return _node ? _node->getAsInteger() : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator JsonArray() const | JsonValue::operator JsonArray() const | ||||||
| { | { | ||||||
|     return JsonArray(_node); |     return JsonArray(_node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JsonValue::operator JsonObject() const | JsonValue::operator JsonObject() const | ||||||
| { | { | ||||||
|     return JsonObject(_node); |     return JsonObject(_node); | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user