Merged the two StringBuilder classes into one

This commit is contained in:
Benoit Blanchon
2018-10-18 17:54:33 +02:00
parent 1a4515c0b9
commit ae089dcff7
9 changed files with 91 additions and 102 deletions

View File

@@ -0,0 +1,35 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#pragma once
#include "../Strings/StringInMemoryPool.hpp"
#include "MemoryPool.hpp"
namespace ARDUINOJSON_NAMESPACE {
class StringBuilder {
public:
explicit StringBuilder(MemoryPool* parent)
: _parent(parent), _start(0), _size(0) {
_start = _parent->alloc(1);
}
void append(char c) {
_start = _parent->realloc(_start, _size + 1, _size + 2);
if (_start) _start[_size++] = c;
}
StringInMemoryPool complete() {
if (_start) _start[_size] = 0;
return _start;
}
private:
MemoryPool* _parent;
char* _start;
size_t _size;
};
} // namespace ARDUINOJSON_NAMESPACE