From f30d75ae5dba339bfc95229894b22fd73e3fdc14 Mon Sep 17 00:00:00 2001 From: rajdakin Date: Sat, 7 Sep 2024 20:53:51 +0200 Subject: [WRAPPERHELPER] General improvements (#1804) * [WRAPPERHELPER] Automatic headers detection, various bug fixes, added some cast support * [WRAPPERHELPER] Keep comments untouched --- wrapperhelper/src/cstring.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'wrapperhelper/src/cstring.c') diff --git a/wrapperhelper/src/cstring.c b/wrapperhelper/src/cstring.c index aecfb52e..86536915 100644 --- a/wrapperhelper/src/cstring.c +++ b/wrapperhelper/src/cstring.c @@ -71,6 +71,15 @@ int string_reserve_grow(string_t *s, size_t cap) { return 1; } +int string_trim(string_t *s) { + if (s->ssize == s->scap) return 1; + void *new_buf = realloc(s->buf, sizeof(char) * (s->ssize + 1)); + if (!new_buf) return 0; + s->buf = new_buf; + s->scap = s->ssize; + return 1; +} + void string_del(string_t *s) { if (s->buf) free(s->buf); free(s); @@ -118,6 +127,16 @@ void string_pop(string_t *s) { } } +void string_clear(string_t *s) { + if (!s->ssize) return; + if (!s->scap) return; + s->buf[s->ssize = 0] = '\0'; + void *new_buf = realloc(s->buf, sizeof(char)); + if (!new_buf) return; // We don't really care if the realloc fails, we just need to not update anything + s->buf = new_buf; + s->scap = 0; +} + string_t *string_dup(string_t const *s) { string_t *ret = string_new_cap(s->ssize); if (!ret) return NULL; -- cgit 1.4.1