From aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 19 Feb 2019 00:27:43 +0100 Subject: Started full rewrite in C++. --- strbuf.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 strbuf.cpp (limited to 'strbuf.cpp') diff --git a/strbuf.cpp b/strbuf.cpp new file mode 100644 index 00000000..3864b271 --- /dev/null +++ b/strbuf.cpp @@ -0,0 +1,26 @@ +#include "strbuf.h" + +#include + +void strbuf::realloc (size_t len) { + this->mem = static_cast(std::realloc(this->mem, len)); + this->alloc = len; +} + +strbuf::~strbuf() { + free (this->mem); + this->mem = NULL; + this->alloc = 0; + this->len = 0; +} + +strbuf& strbuf::operator+=(char c) { + if (this->len + 1 > this->alloc) { + this->alloc <<= 1; + this->mem = static_cast (std::realloc(this->mem, this->alloc)); + } + + this->mem[this->len] = c; + this->ptr = ++this->len; + return *this; +} -- cgit v1.2.3