diff options
Diffstat (limited to 'src/common/better_string.c')
-rw-r--r-- | src/common/better_string.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/better_string.c b/src/common/better_string.c index 7863da0..0788aab 100644 --- a/src/common/better_string.c +++ b/src/common/better_string.c @@ -1,6 +1,7 @@ #include "../include/better_string.h" #include "../include/helpers.h" #include <stdlib.h> +#include <stdbool.h> #include <string.h> string_t *init_string(const char *src) { @@ -17,6 +18,16 @@ string_t *init_string(const char *src) { return s; } +string_t *string_copy(string_t *s) { + return init_string(s->buf); +} + +char *string_copy_raw(string_t *s) { + char *raw = calloc(s->len + 1, sizeof(char)); + strncpy(raw, s->buf, s->len); + return raw; +} + void string_push(string_t *s, char c) { if (s->len >= s->size - 3) { s->size *= 2; @@ -44,6 +55,10 @@ void string_concat(string_t *s1, string_t *s2) { } } +bool string_cmp(string_t *s1, string_t *s2) { + return strcmp(s1->buf, s2->buf) == 0; +} + void string_free(void *x) { string_t *s = x; |