diff options
Diffstat (limited to '')
-rw-r--r-- | strbuf.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h new file mode 100644 index 00000000..ef6ea61f --- /dev/null +++ b/strbuf.h @@ -0,0 +1,65 @@ +#ifndef STRBUF_H +#define STRBUF_H + +#include <stdlib.h> + +typedef struct { + char* mem; + size_t ptr; + size_t alloc; + size_t len; +} string; + +/* + * TODO rename everything to be on the form + * strbuf_.* + * + * TODO Check memmory allocation for last +1 byte for null. + */ + +/* + * Constructor + */ +int init_string(string* str, size_t len); + +/* + * Like realloc, but for strbuf + */ +int realloc_string(string* str, size_t len); + +/* + * Free's contents of str, but keeps str. + */ +int free_string(string* str); + +/* + * Copy contents from src to dest. + * Assumes that dest is already initialized. + * + * also see: strbuf_alloc_copy + */ +int copy_strbuf(string* dest, string* src); +int strbuf_cmp(string* a, string* b); +int strbuf_c(string* a, char* b); +int strbuf_append(string* a, char c); +int strbuf_reset(string* s); +char* charat(string* s, int idx); +char* strbuf_cur(string* s); + +/* + * Sets the length and seek ptr to 0, but doesn't touch the memmory. + */ +int strbuf_soft_reset(string* s); + +/* + * Returns the character after the last, so where null hopefully is. + */ +char* strbuf_end(string* s); + +/* + * Copies contents from src to dest, also allocating dest in the + * process. dest should not be initialized before this call. + */ +int strbuf_init_copy(string* dest, string* src); + +#endif /* STRBUF_H */ |