From 3780f207f924f14734cb839fd015bd883fe52ff1 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Thu, 30 Jan 2025 21:02:42 -0800 Subject: restructure project --- src/common/better_string.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/common/better_string.c') 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 +#include #include 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; -- cgit