aboutsummaryrefslogtreecommitdiff
path: root/src/common/better_string.c
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2025-01-30 21:02:42 -0800
committerPreston Pan <ret2pop@gmail.com>2025-01-30 21:02:42 -0800
commit3780f207f924f14734cb839fd015bd883fe52ff1 (patch)
treede13568dbf97ffe477943854bcb3ea6001b46cf8 /src/common/better_string.c
parentef9ab1fd141f4057d41f2d6ed8ab8d67c44894d5 (diff)
restructure projectHEADmain
Diffstat (limited to 'src/common/better_string.c')
-rw-r--r--src/common/better_string.c15
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;