diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-06 12:08:58 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-06 12:08:58 +0100 |
commit | af3cc906185d7273cf82b1339b63843062898120 (patch) | |
tree | 01d9cff85d6c4dfee3185a2402745d721f3636e8 /strbuf.h | |
parent | Remove GC. (diff) | |
download | calp-af3cc906185d7273cf82b1339b63843062898120.tar.gz calp-af3cc906185d7273cf82b1339b63843062898120.tar.xz |
Code cleanup and add documentation.
Diffstat (limited to 'strbuf.h')
-rw-r--r-- | strbuf.h | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -4,6 +4,14 @@ #include <stdlib.h> #include "macro.h" +/* + * 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 + * string. + * + * Also comes with a number of functions which allow for safe(er) + * access to the memmory. + */ typedef struct { char* mem; /* TODO add support for negative ptr */ @@ -33,7 +41,6 @@ int strbuf_realloc(strbuf* str, size_t len); /* * Free's contents of str, but keeps str. */ -// int strbuf_free(strbuf* str); FREE_F(strbuf); /* @@ -57,8 +64,21 @@ int strbuf_append(strbuf* s, char c); * Calls strbuf_append with NULL. */ int strbuf_cap(strbuf* s); + +/* + * Resets the seek for strbuf to 0. + */ int strbuf_reset(strbuf* s); + +/* + * Returns a pointer to character at index. Allows mutation of the + * value pointed to by the return address. + */ char* charat(strbuf* s, unsigned int idx); + +/* + * Same as `charat`, But returns the current character. + */ char* strbuf_cur(strbuf* s); /* |