mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 08:48:30 +01:00
JsonArray::remove() and JsonObject::remove() now release the memory of strings
This commit is contained in:
@@ -11,25 +11,43 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class StringBuilder {
|
||||
public:
|
||||
explicit StringBuilder(MemoryPool* parent)
|
||||
: _parent(parent), _start(0), _size(0) {
|
||||
_start = _parent->alloc(1);
|
||||
typedef StringInMemoryPool StringType;
|
||||
|
||||
explicit StringBuilder(MemoryPool* parent) : _parent(parent), _size(0) {
|
||||
_slot = _parent->allocExpandableString();
|
||||
}
|
||||
|
||||
void append(const char* s) {
|
||||
while (*s) append(*s++);
|
||||
}
|
||||
|
||||
void append(const char* s, size_t n) {
|
||||
while (n-- > 0) append(*s++);
|
||||
}
|
||||
|
||||
void append(char c) {
|
||||
_start = _parent->realloc(_start, _size + 1, _size + 2);
|
||||
if (_start) _start[_size++] = c;
|
||||
if (!_slot) return;
|
||||
|
||||
if (_size >= _slot->size) {
|
||||
_slot = _parent->expandString(_slot);
|
||||
if (!_slot) return;
|
||||
}
|
||||
|
||||
_slot->value[_size++] = c;
|
||||
}
|
||||
|
||||
StringInMemoryPool complete() {
|
||||
if (_start) _start[_size] = 0;
|
||||
return _start;
|
||||
StringType complete() {
|
||||
append('\0');
|
||||
if (_slot) {
|
||||
_parent->freezeString(_slot, _size);
|
||||
}
|
||||
return _slot;
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryPool* _parent;
|
||||
char* _start;
|
||||
size_t _size;
|
||||
StringSlot* _slot;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user