Inverted dependency between MemoryPool and string adapters.

Inserted a null after each raw string in the pool.
This commit is contained in:
Benoit Blanchon
2020-07-08 09:38:27 +02:00
parent 7e58347fbe
commit 04c59985a1
25 changed files with 143 additions and 119 deletions

View File

@@ -4,7 +4,6 @@
#pragma once
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
@@ -33,14 +32,8 @@ class FlashStringAdapter {
return !_str;
}
char* save(MemoryPool* pool) const {
if (!_str)
return NULL;
size_t n = size() + 1; // copy the terminator
char* dup = pool->allocFrozenString(n);
if (dup)
memcpy_P(dup, reinterpret_cast<const char*>(_str), n);
return dup;
void copyTo(char* p, size_t n) const {
memcpy_P(p, reinterpret_cast<const char*>(_str), n);
}
size_t size() const {
@@ -49,7 +42,7 @@ class FlashStringAdapter {
return strlen_P(reinterpret_cast<const char*>(_str));
}
typedef storage_policy::store_by_copy storage_policy;
typedef storage_policies::store_by_copy storage_policy;
private:
const __FlashStringHelper* _str;