aboutsummaryrefslogtreecommitdiff
path: root/strbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'strbuf.cpp')
-rw-r--r--strbuf.cpp26
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;
+}