mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-02 08:48:27 +01:00
Added string deduplication (closes #1303)
This commit is contained in:
@@ -39,6 +39,10 @@ class ArduinoStringAdapter {
|
||||
return _str->length();
|
||||
}
|
||||
|
||||
const char* begin() const {
|
||||
return _str->c_str();
|
||||
}
|
||||
|
||||
typedef storage_policies::store_by_copy storage_policy;
|
||||
|
||||
private:
|
||||
|
||||
@@ -39,6 +39,10 @@ class ConstRamStringAdapter {
|
||||
return _str;
|
||||
}
|
||||
|
||||
const char* begin() const {
|
||||
return _str;
|
||||
}
|
||||
|
||||
typedef storage_policies::store_by_address storage_policy;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
@@ -42,6 +43,10 @@ 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:
|
||||
|
||||
44
src/ArduinoJson/Strings/FlashStringIterator.hpp
Normal file
44
src/ArduinoJson/Strings/FlashStringIterator.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// 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,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
@@ -41,6 +42,10 @@ class SizedFlashStringAdapter {
|
||||
return _size;
|
||||
}
|
||||
|
||||
FlashStringIterator begin() const {
|
||||
return FlashStringIterator(_str);
|
||||
}
|
||||
|
||||
typedef storage_policies::store_by_copy storage_policy;
|
||||
|
||||
private:
|
||||
|
||||
@@ -36,6 +36,10 @@ class SizedRamStringAdapter {
|
||||
return _size;
|
||||
}
|
||||
|
||||
const char* begin() const {
|
||||
return _str;
|
||||
}
|
||||
|
||||
typedef storage_policies::store_by_copy storage_policy;
|
||||
|
||||
private:
|
||||
|
||||
@@ -41,6 +41,10 @@ class StlStringAdapter {
|
||||
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