aboutsummaryrefslogtreecommitdiff
path: root/strbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'strbuf.cpp')
-rw-r--r--strbuf.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/strbuf.cpp b/strbuf.cpp
index 7b63c58d..45c63beb 100644
--- a/strbuf.cpp
+++ b/strbuf.cpp
@@ -1,6 +1,7 @@
#include "strbuf.h"
#include <cstdlib>
+#include <cstring>
strbuf::strbuf (const strbuf& other) {
this->alloc = other.len + 1;
@@ -28,5 +29,28 @@ strbuf& strbuf::operator+=(char c) {
this->mem[this->len] = c;
this->ptr = ++this->len;
+
return *this;
}
+
+bool strbuf::operator==(strbuf& other) {
+ return strncmp(this->mem, other.mem, this->len) == 0;
+}
+
+bool strbuf::operator==(const char* other) {
+ std::cerr << __FILE__ << ':' << __LINE__ << ' ' << this->c_str() << "==" << other << std::endl;
+ return strncmp(this->mem, other, this->len) == 0 ;
+}
+
+std::ostream& operator << (std::ostream& out, strbuf& str) {
+ out << (str.to_string());
+ return out;
+}
+
+// TODO this leaks memmory
+char* strbuf::c_str() {
+ char* buf = static_cast<char*>(malloc(this->len + 1));
+ memcpy(buf, this->mem, this->len);
+ buf[this->len] = '\0';
+ return buf;
+}