diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-09 18:39:49 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-09 18:39:49 -0800 |
commit | ac6004730fa54a756d1627a4e8450cd32df86f75 (patch) | |
tree | 8cb4d59438a1252fa069788b2ffb78b2a1bbad3e /include/better_string.h | |
parent | 6ccf0572469dfc8cd8fa7b8537b2ac6c265d2df6 (diff) |
reorganize directory structure
Diffstat (limited to 'include/better_string.h')
-rw-r--r-- | include/better_string.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/better_string.h b/include/better_string.h new file mode 100644 index 0000000..03bc6f6 --- /dev/null +++ b/include/better_string.h @@ -0,0 +1,28 @@ +#ifndef BETTER_STRING_H +#define BETTER_STRING_H +#include <stdlib.h> +/* We want better strings to realloc less and keep track of the length of the + * string so we don't have to call strlen every time */ +typedef struct STRING_STRUCT { + /* length of string */ + size_t length; + /* Size of current value buffer */ + size_t bufsize; + char *value; +} string_t; + +/* Allocates memory for new string */ +string_t *init_string(char *value); + +/* Copies string to another string */ +string_t *string_copy(string_t *s); + +/* Concatenates a string_t type and a char * type */ +void string_concat(string_t *s1, string_t *s2); + +/* Appends single characters */ +void string_append(string_t *s, char c); + +/* Frees space for string */ +void string_free(string_t *s); +#endif |