Added string deduplication (closes #1303)

This commit is contained in:
Benoit Blanchon
2020-07-21 20:15:31 +02:00
parent 8ef226bcb8
commit 764ff2cd53
31 changed files with 574 additions and 156 deletions

View File

@@ -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:

View File

@@ -39,6 +39,10 @@ class ConstRamStringAdapter {
return _str;
}
const char* begin() const {
return _str;
}
typedef storage_policies::store_by_address storage_policy;
protected:

View File

@@ -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:

View 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

View File

@@ -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:

View File

@@ -36,6 +36,10 @@ class SizedRamStringAdapter {
return _size;
}
const char* begin() const {
return _str;
}
typedef storage_policies::store_by_copy storage_policy;
private:

View File

@@ -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: