diff options
Diffstat (limited to '')
-rw-r--r-- | strbuf.h | 40 |
1 files changed, 19 insertions, 21 deletions
@@ -2,41 +2,39 @@ #define STRBUF_H #include <stdlib.h> +#include "macro.h" typedef struct { char* mem; size_t ptr; size_t alloc; size_t len; -} string; +} strbuf; /* - * TODO rename everything to be on the form - * strbuf_.* - * * TODO Check memmory allocation for last +1 byte for null. */ /* - * Init string to size of 0 + * Init strbuf to size of 0 * Doesnt't call malloc. */ -int strbuf_init_0(string* str); +int CONSTRUCTOR_DECL(strbuf); /* * Constructor */ -int strbuf_init_1(string* str, size_t len); +int CONSTRUCTOR_DECL(strbuf, size_t len); /* * Like realloc, but for strbuf */ -int realloc_string(string* str, size_t len); +int strbuf_realloc(strbuf* str, size_t len); /* * Free's contents of str, but keeps str. */ -int free_string(string* str); +int strbuf_free(strbuf* str); /* * Copy contents from src to dest. @@ -44,37 +42,37 @@ int free_string(string* str); * * 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_copy(strbuf* dest, strbuf* src); +int strbuf_cmp(strbuf* a, strbuf* b); +int strbuf_c(strbuf* a, char* b); /* - * Append char to end of string, determined by s->len. + * Append char to end of strbuf, determined by s->len. */ -int strbuf_append(string* s, char c); +int strbuf_append(strbuf* s, char c); /* * Calls strbuf_append with NULL. */ -int strbuf_cap(string* s); -int strbuf_reset(string* s); -char* charat(string* s, int idx); -char* strbuf_cur(string* s); +int strbuf_cap(strbuf* s); +int strbuf_reset(strbuf* s); +char* charat(strbuf* s, int idx); +char* strbuf_cur(strbuf* s); /* * Sets the length and seek ptr to 0, but doesn't touch the memmory. */ -int strbuf_soft_reset(string* s); +int strbuf_soft_reset(strbuf* s); /* * Returns the character after the last, so where null hopefully is. */ -char* strbuf_end(string* s); +char* strbuf_end(strbuf* 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); +int strbuf_init_copy(strbuf* dest, strbuf* src); #endif /* STRBUF_H */ |