diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-19 00:27:43 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-19 00:27:43 +0100 |
commit | aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8 (patch) | |
tree | 305f1287a8cc6a896318a4de5f2b43686e7223b3 /strbuf.cpp | |
parent | Made to compile as C++. (diff) | |
download | calp-aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8.tar.gz calp-aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8.tar.xz |
Started full rewrite in C++.
Diffstat (limited to 'strbuf.cpp')
-rw-r--r-- | strbuf.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
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 <cstdlib> + +void strbuf::realloc (size_t len) { + this->mem = static_cast<char*>(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<char*> (std::realloc(this->mem, this->alloc)); + } + + this->mem[this->len] = c; + this->ptr = ++this->len; + return *this; +} |