aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-17 08:05:54 +0900
committernsfisis <nsfisis@gmail.com>2025-08-17 08:05:54 +0900
commit89a723320a8b7f387948f3edd9c1ce12824424d6 (patch)
treec83691af082fe9e0c32834154f513516d4f7aa11 /common.c
parent48d5ca9bcf08a0995008759bf5bb9fec5a1631bc (diff)
downloadducc-89a723320a8b7f387948f3edd9c1ce12824424d6.tar.gz
ducc-89a723320a8b7f387948f3edd9c1ce12824424d6.tar.zst
ducc-89a723320a8b7f387948f3edd9c1ce12824424d6.zip
refactor: define TokenValue to store semantic value
Diffstat (limited to 'common.c')
-rw-r--r--common.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/common.c b/common.c
index badb1ed..2c1fb37 100644
--- a/common.c
+++ b/common.c
@@ -12,7 +12,7 @@ void fatal_error(const char* msg, ...) {
#define unimplemented() fatal_error("%s:%d: unimplemented", __FILE__, __LINE__)
struct String {
- char* data;
+ const char* data;
size_t len;
};
typedef struct String String;
@@ -23,6 +23,13 @@ char* string_to_cstr(const String* s) {
return buf;
}
+String* cstr_to_new_string(const char* cstr) {
+ String* s = calloc(1, sizeof(String));
+ s->len = strlen(cstr);
+ s->data = strndup(cstr, s->len);
+ return s;
+}
+
BOOL string_equals(const String* s1, const String* s2) {
return s1->len == s2->len && strncmp(s1->data, s2->data, s1->len) == 0;
}