summaryrefslogtreecommitdiff
path: root/str.h
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-01-25 16:00:20 -0500
committerCarson Fleming <[email protected]>2026-01-25 16:00:20 -0500
commitb364a39849fc4a6f6837f8558b7520efc24ae96c (patch)
tree2f1d3be07c225bd2c29b219df8ec184c256a9e4f /str.h
parentaecec4204b5830fcb97ab93a56a6a29018519ca2 (diff)
downloadsafec-b364a39849fc4a6f6837f8558b7520efc24ae96c.tar.gz
bring in some library functions and restructure
Diffstat (limited to 'str.h')
-rw-r--r--str.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/str.h b/str.h
new file mode 100644
index 0000000..f87f68e
--- /dev/null
+++ b/str.h
@@ -0,0 +1,37 @@
+#ifndef __SAFEC_STR_H
+#define __SAFEC_STR_H
+#include "types.h"
+
+typedef struct {
+ size_t length;
+ char* __data;
+} str_t;
+
+// TODO: heap-allocing the pointer is stupid just return a value
+// should just heap-alloc __data
+
+char* str_at(const str_t str, size_t idx);
+str_t str_slice(const str_t str, size_t start, size_t length);
+int str_cmp(const str_t s1, const str_t s2);
+
+/* not found = -1 */
+ssize_t str_indexof(const str_t str, char c);
+ssize_t str_rindexof(const str_t str, char c);
+
+str_t str_heap_dup(const str_t str);
+str_t str_heap_cat(const str_t s1, const str_t s2);
+
+/* TODO: implement string.h functions for this new string construct */
+
+/* `dst` will be overwritten with the contents of `src` */
+void str_to_c_str(char* dst, size_t dst_size, const str_t* src);
+char* str_to_heap_c_str(const str_t str);
+
+str_t str_init(char* data, size_t length);
+
+str_t str_heap_alloc(size_t length);
+str_t str_heap_alloc_iv(const char* c_str);
+str_t str_heap_alloc_iv_slice(const char* c_str, size_t start, size_t length);
+void str_heap_destroy(str_t str);
+
+#endif