diff options
Diffstat (limited to 'String.c')
| -rw-r--r-- | String.c | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -3,6 +3,8 @@ #include <stdio.h> #include <string.h> +/** Metadata **/ + struct StringMeta { MemoryManager *mm; usize length; @@ -13,6 +15,8 @@ S_metadata(String s) { return (struct StringMeta*)(s - sizeof(struct StringMeta)); } +/** Helpers **/ + static inline void* S_start(MemoryManager *mm, usize length) { if (NULL == mm) @@ -34,6 +38,8 @@ S_start(MemoryManager *mm, usize length) { return start + sizeof(sm); } +/* Create */ + String S_new(MemoryManager *mm, const char *str) { if (NULL == str) @@ -149,13 +155,20 @@ S_printf(MemoryManager *mm, const char *fmt, ...) { return result; } -usize -S_length(String s) { +/* Free */ + +Result +S_free(String *s) { if (NULL == s) - return 0; - return S_metadata(s)->length; + return R_NullArgument; + + struct StringMeta *sm = S_metadata(*s); + *s = (char*)sm; + return sm->mm->free(*sm->mm, (void*)s); } +/* Modify */ + static inline Result S_resize(String *s, usize length) { if (NULL == s || NULL == *s) @@ -207,6 +220,15 @@ S_prepend(String *s, const char *str) { return R_Ok; } +/* Get */ + +usize +S_length(String s) { + if (NULL == s) + return 0; + return S_metadata(s)->length; +} + usize S_find(String s, char c) { if (NULL == s) |
