aboutsummaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-06 12:08:58 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-06 12:08:58 +0100
commitaf3cc906185d7273cf82b1339b63843062898120 (patch)
tree01d9cff85d6c4dfee3185a2402745d721f3636e8 /strbuf.h
parentRemove GC. (diff)
downloadcalp-af3cc906185d7273cf82b1339b63843062898120.tar.gz
calp-af3cc906185d7273cf82b1339b63843062898120.tar.xz
Code cleanup and add documentation.
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/strbuf.h b/strbuf.h
index 8a4de030..77a401b5 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -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);
/*