mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Simplified string adapters
This commit is contained in:
		| @@ -7,6 +7,7 @@ | ||||
| #include <ArduinoJson/Memory/Alignment.hpp> | ||||
| #include <ArduinoJson/Polyfills/assert.hpp> | ||||
| #include <ArduinoJson/Polyfills/mpl/max.hpp> | ||||
| #include <ArduinoJson/Strings/StringAdapters.hpp> | ||||
| #include <ArduinoJson/Variant/VariantSlot.hpp> | ||||
|  | ||||
| #include <string.h>  // memmove | ||||
| @@ -64,7 +65,7 @@ class MemoryPool { | ||||
|       return 0; | ||||
|  | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|     const char* existingCopy = findString(str.begin()); | ||||
|     const char* existingCopy = findString(str); | ||||
|     if (existingCopy) | ||||
|       return existingCopy; | ||||
| #endif | ||||
| @@ -86,7 +87,7 @@ class MemoryPool { | ||||
|  | ||||
|   const char* saveStringFromFreeZone(size_t len) { | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|     const char* dup = findString(_left); | ||||
|     const char* dup = findString(adaptString(_left)); | ||||
|     if (dup) | ||||
|       return dup; | ||||
| #endif | ||||
| @@ -163,16 +164,11 @@ class MemoryPool { | ||||
|   } | ||||
|  | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|   template <typename TIterator> | ||||
|   const char* findString(TIterator str) { | ||||
|   template <typename TAdaptedString> | ||||
|   const char* findString(const TAdaptedString& str) { | ||||
|     for (char* next = _begin; next < _left; ++next) { | ||||
|       char* begin = next; | ||||
|  | ||||
|       // try to match | ||||
|       for (TIterator it = str; *it == *next; ++it) { | ||||
|         if (*next++ == 0) | ||||
|           return begin; | ||||
|       } | ||||
|       if (str.equals(next)) | ||||
|         return next; | ||||
|  | ||||
|       // jump to next terminator | ||||
|       while (*next) ++next; | ||||
|   | ||||
| @@ -39,10 +39,6 @@ class ArduinoStringAdapter { | ||||
|     return _str->length(); | ||||
|   } | ||||
|  | ||||
|   const char* begin() const { | ||||
|     return _str->c_str(); | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_copy storage_policy; | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -39,10 +39,6 @@ class ConstRamStringAdapter { | ||||
|     return _str; | ||||
|   } | ||||
|  | ||||
|   const char* begin() const { | ||||
|     return _str; | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_address storage_policy; | ||||
|  | ||||
|  protected: | ||||
|   | ||||
| @@ -5,7 +5,6 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <ArduinoJson/Polyfills/pgmspace.hpp> | ||||
| #include <ArduinoJson/Strings/FlashStringIterator.hpp> | ||||
| #include <ArduinoJson/Strings/IsString.hpp> | ||||
| #include <ArduinoJson/Strings/StoragePolicy.hpp> | ||||
|  | ||||
| @@ -43,10 +42,6 @@ class FlashStringAdapter { | ||||
|     return strlen_P(reinterpret_cast<const char*>(_str)); | ||||
|   } | ||||
|  | ||||
|   FlashStringIterator begin() const { | ||||
|     return FlashStringIterator(_str); | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_copy storage_policy; | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -1,44 +0,0 @@ | ||||
| // ArduinoJson - https://arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2021 | ||||
| // MIT License | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| class FlashStringIterator { | ||||
|  public: | ||||
|   explicit FlashStringIterator(const __FlashStringHelper* ptr) | ||||
|       : _ptr(reinterpret_cast<const char*>(ptr)) {} | ||||
|  | ||||
|   explicit FlashStringIterator(const char* ptr) : _ptr(ptr) {} | ||||
|  | ||||
|   FlashStringIterator operator+(ptrdiff_t d) const { | ||||
|     return FlashStringIterator(_ptr + d); | ||||
|   } | ||||
|  | ||||
|   ptrdiff_t operator-(FlashStringIterator other) const { | ||||
|     return _ptr - other._ptr; | ||||
|   } | ||||
|  | ||||
|   FlashStringIterator operator++(int) { | ||||
|     return FlashStringIterator(_ptr++); | ||||
|   } | ||||
|  | ||||
|   FlashStringIterator operator++() { | ||||
|     return FlashStringIterator(++_ptr); | ||||
|   } | ||||
|  | ||||
|   bool operator!=(FlashStringIterator other) const { | ||||
|     return _ptr != other._ptr; | ||||
|   } | ||||
|  | ||||
|   char operator*() const { | ||||
|     return char(pgm_read_byte(_ptr)); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   const char* _ptr; | ||||
| }; | ||||
|  | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
| @@ -5,7 +5,6 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <ArduinoJson/Namespace.hpp> | ||||
| #include <ArduinoJson/Strings/FlashStringIterator.hpp> | ||||
| #include <ArduinoJson/Strings/IsString.hpp> | ||||
| #include <ArduinoJson/Strings/StoragePolicy.hpp> | ||||
|  | ||||
| @@ -42,10 +41,6 @@ class SizedFlashStringAdapter { | ||||
|     return _size; | ||||
|   } | ||||
|  | ||||
|   FlashStringIterator begin() const { | ||||
|     return FlashStringIterator(_str); | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_copy storage_policy; | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -36,10 +36,6 @@ class SizedRamStringAdapter { | ||||
|     return _size; | ||||
|   } | ||||
|  | ||||
|   const char* begin() const { | ||||
|     return _str; | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_copy storage_policy; | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -41,10 +41,6 @@ class StdStringAdapter { | ||||
|     return _str->size(); | ||||
|   } | ||||
|  | ||||
|   const char* begin() const { | ||||
|     return _str->c_str(); | ||||
|   } | ||||
|  | ||||
|   typedef storage_policies::store_by_copy storage_policy; | ||||
|  | ||||
|  private: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user