summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-10-15 15:23:58 -0400
committerpommicket <pommicket@gmail.com>2023-10-15 15:23:58 -0400
commita01d4de1e2feda34a20bb8dd65ec76fef3c20d6b (patch)
treec24f71d8536663d6758a14194b50508041cc03ec /util.h
parent479219152b85b2cf12e5bfee6fdebca033355beb (diff)
use reference-counted strings for string settings
this lets us remove the length limitations which were previously imposed
Diffstat (limited to 'util.h')
-rw-r--r--util.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/util.h b/util.h
index edbcbe3..1d60cf9 100644
--- a/util.h
+++ b/util.h
@@ -41,7 +41,26 @@ typedef struct {
size_t len;
} String32;
+/// reference-counted string
+typedef struct RcStr RcStr;
+/// allocate new ref-counted string
+///
+/// if `len == -1`, `s` is assumed to be null-terminated. otherwise,
+/// at most `len` bytes are copied from `s`.
+RcStr *rc_str_new(const char *s, i64 len);
+/// increases the reference count of `str`.
+///
+/// does nothing if `str` is `NULL`.
+void rc_str_incref(RcStr *str);
+/// decrease reference count of `*str` and set `*str` to `NULL`.
+///
+/// this frees `*str` if the reference count hits 0.
+///
+/// does nothing if `*str` is NULL.
+void rc_str_decref(RcStr **str);
+/// get rc string with default value if `s == NULL`
+const char *rc_str(RcStr *s, const char *value_if_null);
/// `isword` for 32-bit chars.
bool is32_word(char32_t c);
/// `isspace` for 32-bit chars.