aboutsummaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/strbuf.h b/strbuf.h
index 38a45b09..9bf603a9 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -3,9 +3,11 @@
#include <unistd.h>
#include <cstdlib>
-#include <cstring>
+// #include <cstring>
#include <string>
+#include <iostream>
+
/*
* A high level string type which holds it's own length, how much
* memmory it has allocated for itself, and a seek pointer into the
@@ -15,12 +17,13 @@
* access to the memmory.
*/
struct strbuf {
- char* mem;
/* TODO add support for negative ptr */
- int ptr = 0;
- size_t alloc;
+ int ptr = 0;
+ size_t alloc = 0;
size_t len = 0;
+ char* mem;
+
strbuf () : strbuf (1) { };
strbuf (const strbuf& other);
@@ -36,11 +39,9 @@ struct strbuf {
*/
void realloc (size_t len);
- bool operator==(strbuf& other)
- { return strncmp(this->mem, other.mem, this->len) == 0; }
+ bool operator==(strbuf& other);
- bool operator==(const char* other)
- { return strncmp(this->mem, other, this->len) == 0 ; }
+ bool operator==(const char* other);
strbuf& operator=(strbuf* other);
@@ -72,15 +73,16 @@ struct strbuf {
this->ptr = 0; this->len = 0;
};
- std::string to_string() {
- return std::string (this->mem);
- }
- char* c_str() {
- return this->mem;
+ char* c_str();
+
+ std::string to_string() {
+ return std::string (this->c_str());
}
};
+std::ostream& operator << (std::ostream& out, strbuf& str);
+
/*
* Reallocs dest to be the same size as src, and copies the contents
* of src into dest.