diff --git a/extras/tests/MemoryPool/CMakeLists.txt b/extras/tests/MemoryPool/CMakeLists.txt index 2f809cc2..7c5e8c98 100644 --- a/extras/tests/MemoryPool/CMakeLists.txt +++ b/extras/tests/MemoryPool/CMakeLists.txt @@ -7,7 +7,7 @@ add_executable(MemoryPoolTests clear.cpp saveString.cpp size.cpp - StringCopier.cpp + StringBuilder.cpp ) add_test(MemoryPool MemoryPoolTests) diff --git a/extras/tests/MemoryPool/StringCopier.cpp b/extras/tests/MemoryPool/StringBuilder.cpp similarity index 92% rename from extras/tests/MemoryPool/StringCopier.cpp rename to extras/tests/MemoryPool/StringBuilder.cpp index 29a78407..34568462 100644 --- a/extras/tests/MemoryPool/StringCopier.cpp +++ b/extras/tests/MemoryPool/StringBuilder.cpp @@ -2,20 +2,20 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include +#include #include #include "Allocators.hpp" using namespace ArduinoJson::detail; -TEST_CASE("StringCopier") { +TEST_CASE("StringBuilder") { ControllableAllocator controllableAllocator; SpyingAllocator spyingAllocator(&controllableAllocator); MemoryPool pool(0, &spyingAllocator); SECTION("Empty string") { - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); str.save(); @@ -29,7 +29,7 @@ TEST_CASE("StringCopier") { } SECTION("Short string fits in first allocation") { - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); str.append("hello"); @@ -42,7 +42,7 @@ TEST_CASE("StringCopier") { } SECTION("Long string needs reallocation") { - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); str.append( @@ -63,7 +63,7 @@ TEST_CASE("StringCopier") { } SECTION("Realloc fails") { - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); controllableAllocator.disable(); @@ -81,7 +81,7 @@ TEST_CASE("StringCopier") { } SECTION("Initial allocation fails") { - StringCopier str(&pool); + StringBuilder str(&pool); controllableAllocator.disable(); str.startString(); @@ -94,13 +94,13 @@ TEST_CASE("StringCopier") { } static StringNode* addStringToPool(MemoryPool& pool, const char* s) { - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); str.append(s); return str.save(); } -TEST_CASE("StringCopier::save() deduplicates strings") { +TEST_CASE("StringBuilder::save() deduplicates strings") { MemoryPool pool(4096); SECTION("Basic") { diff --git a/extras/tests/Misc/Utf8.cpp b/extras/tests/Misc/Utf8.cpp index beae262e..35936e31 100644 --- a/extras/tests/Misc/Utf8.cpp +++ b/extras/tests/Misc/Utf8.cpp @@ -11,7 +11,7 @@ using namespace ArduinoJson::detail; static void testCodepoint(uint32_t codepoint, std::string expected) { MemoryPool pool(4096); - StringCopier str(&pool); + StringBuilder str(&pool); str.startString(); CAPTURE(codepoint); diff --git a/src/ArduinoJson/Json/JsonDeserializer.hpp b/src/ArduinoJson/Json/JsonDeserializer.hpp index 9c483397..c382b8e5 100644 --- a/src/ArduinoJson/Json/JsonDeserializer.hpp +++ b/src/ArduinoJson/Json/JsonDeserializer.hpp @@ -22,7 +22,7 @@ template class JsonDeserializer { public: JsonDeserializer(MemoryPool* pool, TReader reader) - : stringStorage_(pool), + : stringBuilder_(pool), foundSomething_(false), latch_(reader), pool_(pool) {} @@ -268,7 +268,7 @@ class JsonDeserializer { if (!eat(':')) return DeserializationError::InvalidInput; - JsonString key = stringStorage_.str(); + JsonString key = stringBuilder_.str(); TFilter memberFilter = filter[key.c_str()]; @@ -276,7 +276,7 @@ class JsonDeserializer { VariantSlot* slot = object.get(adaptString(key.c_str())); if (!slot) { // Save key in memory pool. - auto savedKey = stringStorage_.save(); + auto savedKey = stringBuilder_.save(); // Allocate slot in object slot = pool_->allocVariant(); @@ -375,7 +375,7 @@ class JsonDeserializer { } DeserializationError::Code parseKey() { - stringStorage_.startString(); + stringBuilder_.startString(); if (isQuote(current())) { return parseQuotedString(); } else { @@ -386,13 +386,13 @@ class JsonDeserializer { DeserializationError::Code parseStringValue(VariantData& variant) { DeserializationError::Code err; - stringStorage_.startString(); + stringBuilder_.startString(); err = parseQuotedString(); if (err) return err; - variant.setString(stringStorage_.save()); + variant.setString(stringBuilder_.save()); return DeserializationError::Ok; } @@ -428,9 +428,9 @@ class JsonDeserializer { if (err) return err; if (codepoint.append(codeunit)) - Utf8::encodeCodepoint(codepoint.value(), stringStorage_); + Utf8::encodeCodepoint(codepoint.value(), stringBuilder_); #else - stringStorage_.append('\\'); + stringBuilder_.append('\\'); #endif continue; } @@ -442,10 +442,10 @@ class JsonDeserializer { move(); } - stringStorage_.append(c); + stringBuilder_.append(c); } - if (!stringStorage_.isValid()) + if (!stringBuilder_.isValid()) return DeserializationError::NoMemory; return DeserializationError::Ok; @@ -458,14 +458,14 @@ class JsonDeserializer { if (canBeInNonQuotedString(c)) { // no quotes do { move(); - stringStorage_.append(c); + stringBuilder_.append(c); c = current(); } while (canBeInNonQuotedString(c)); } else { return DeserializationError::InvalidInput; } - if (!stringStorage_.isValid()) + if (!stringBuilder_.isValid()) return DeserializationError::NoMemory; return DeserializationError::Ok; @@ -657,7 +657,7 @@ class JsonDeserializer { return DeserializationError::Ok; } - StringCopier stringStorage_; + StringBuilder stringBuilder_; bool foundSomething_; Latch latch_; MemoryPool* pool_; diff --git a/src/ArduinoJson/StringStorage/StringCopier.hpp b/src/ArduinoJson/Memory/StringBuilder.hpp similarity index 94% rename from src/ArduinoJson/StringStorage/StringCopier.hpp rename to src/ArduinoJson/Memory/StringBuilder.hpp index c4f60d7a..91ed669d 100644 --- a/src/ArduinoJson/StringStorage/StringCopier.hpp +++ b/src/ArduinoJson/Memory/StringBuilder.hpp @@ -8,13 +8,13 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -class StringCopier { +class StringBuilder { public: static const size_t initialCapacity = 31; - StringCopier(MemoryPool* pool) : pool_(pool) {} + StringBuilder(MemoryPool* pool) : pool_(pool) {} - ~StringCopier() { + ~StringBuilder() { if (node_) pool_->deallocString(node_); } diff --git a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp index adf33b07..138c498f 100644 --- a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp +++ b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp @@ -19,7 +19,7 @@ class MsgPackDeserializer { MsgPackDeserializer(MemoryPool* pool, TReader reader) : pool_(pool), reader_(reader), - stringStorage_(pool), + stringBuilder_(pool), foundSomething_(false) {} template @@ -370,14 +370,14 @@ class MsgPackDeserializer { if (err) return err; - variant->setString(stringStorage_.save()); + variant->setString(stringBuilder_.save()); return DeserializationError::Ok; } DeserializationError::Code readString(size_t n) { DeserializationError::Code err; - stringStorage_.startString(); + stringBuilder_.startString(); for (; n; --n) { uint8_t c; @@ -385,10 +385,10 @@ class MsgPackDeserializer { if (err) return err; - stringStorage_.append(static_cast(c)); + stringBuilder_.append(static_cast(c)); } - if (!stringStorage_.isValid()) + if (!stringBuilder_.isValid()) return DeserializationError::NoMemory; return DeserializationError::Ok; @@ -485,7 +485,7 @@ class MsgPackDeserializer { if (err) return err; - JsonString key = stringStorage_.str(); + JsonString key = stringBuilder_.str(); TFilter memberFilter = filter[key.c_str()]; VariantData* member; @@ -493,7 +493,7 @@ class MsgPackDeserializer { ARDUINOJSON_ASSERT(object != 0); // Save key in memory pool. - auto savedKey = stringStorage_.save(); + auto savedKey = stringBuilder_.save(); VariantSlot* slot = pool_->allocVariant(); if (!slot) @@ -555,7 +555,7 @@ class MsgPackDeserializer { MemoryPool* pool_; TReader reader_; - StringCopier stringStorage_; + StringBuilder stringBuilder_; bool foundSomething_; }; diff --git a/src/ArduinoJson/Variant/ConverterImpl.hpp b/src/ArduinoJson/Variant/ConverterImpl.hpp index 3e4cc57d..c71dbaae 100644 --- a/src/ArduinoJson/Variant/ConverterImpl.hpp +++ b/src/ArduinoJson/Variant/ConverterImpl.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include #include @@ -212,7 +212,7 @@ class MemoryPoolPrint : public Print { } private: - StringCopier copier_; + StringBuilder copier_; }; } // namespace detail