aboutsummaryrefslogtreecommitdiff
path: root/strbuf.cpp
blob: 3864b27123c6606628dd844c0381ba8b495ded68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
}