diff options
Diffstat (limited to 'string.h')
| -rw-r--r-- | string.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/string.h b/string.h new file mode 100644 index 0000000..17e6bc6 --- /dev/null +++ b/string.h @@ -0,0 +1,37 @@ +#ifndef STRING_H +#define STRING_H + +#include <stddef.h> + +#define SV(sp, str) sv_create(sp, str, sizeof(str)); + +struct StringView { + char *buf; + size_t len; +}; + +#define STRING_CONST {NULL, 0} + +struct StringPool { + void *mem; + size_t size; + size_t offset; +}; + +#define STRINGPOOL_CONST {NULL, 0, 0} + +typedef struct StringView StringView; +typedef struct StringPool StringPool; + +void sp_init(StringPool *sp, size_t len); +void* sp_reserve(StringPool *sp, size_t len); + +StringView sv_create(StringPool *sp, char *str, size_t len); +StringView sv_concat_ss(StringPool *sp, StringView a, StringView b); +StringView sv_concat_ss_n(StringPool *sp, int n, ...); + +StringView sv_sizet_to_string(StringPool *sp, size_t s); + +void sv_printf_cs(char *fmt, ...); + +#endif |
