summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-01-25 14:20:01 -0500
committerAndrew Opalach <andrew@akon.city> 2025-01-25 14:20:01 -0500
commitc64a199b732f9803866f5af8c374e04cf92f6239 (patch)
tree796e2a3a5cad0ba41d8d4b6a84673a72dcce92d9 /include
parent562c730ac38749fb43ae5b7b53ae5f3043166bd1 (diff)
downloadlibalabaster-c64a199b732f9803866f5af8c374e04cf92f6239.tar.gz
libalabaster-c64a199b732f9803866f5af8c374e04cf92f6239.tar.bz2
libalabaster-c64a199b732f9803866f5af8c374e04cf92f6239.zip
wstr: Port some str functions
Not properly tested. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include')
-rw-r--r--include/al/str.h4
-rw-r--r--include/al/wstr.h34
2 files changed, 36 insertions, 2 deletions
diff --git a/include/al/str.h b/include/al/str.h
index 5ee51d0..fce2486 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -92,7 +92,9 @@ static inline void al_str_insert(str *s, u32 i, str *c)
{
s->alloc = al_str_reserve(s, s->length + c->length);
char *data = s->data + i;
- al_memmove(data + c->length, data, s->length - i);
+ if (i < s->length) {
+ al_memmove(data + c->length, data, s->length - i);
+ }
al_memcpy(data, c->data, c->length);
s->length += c->length;
}
diff --git a/include/al/wstr.h b/include/al/wstr.h
index c5734ba..118a447 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -101,7 +101,7 @@ static inline void al_wstr_from_str(wstr *w, str *s)
// This is horrible.
static inline bool al_wstr_to_str(wstr *w, str *s)
{
- // This is broken on windows. locale issue?
+ // This is broken on Windows. Locale issue?
#ifdef AL_HAVE_WIDE_STRING
wstr copy;
// We have to make a copy here incase w->length is less than the
@@ -126,6 +126,38 @@ static inline bool al_wstr_to_str(wstr *w, str *s)
#endif
}
+static inline void al_wstr_cat(wstr *w, wstr *c)
+{
+ w->alloc = al_wstr_reserve(w, ((w->length + c->length) + 1) * sizeof(wchar_t));
+ al_memcpy(w->data + w->length, c->data, c->length * sizeof(wchar_t));
+ w->length += c->length;
+ w->data[w->length] = L'\0';
+}
+
+static inline void al_wstr_insert(wstr *w, u32 i, wstr *c)
+{
+ w->alloc = al_wstr_reserve(w, ((w->length + c->length) + 1) * sizeof(wchar_t));
+ wchar_t *data = w->data + i;
+ if (i < w->length) {
+ al_memmove(data + c->length, data, (w->length - i) * sizeof(wchar_t));
+ }
+ al_memcpy(data, c->data, c->length * sizeof(wchar_t));
+ w->length += c->length;
+ w->data[w->length] = L'\0';
+}
+
+static inline void al_wstr_remove_at(wstr *w, u32 i)
+{
+ if (i >= w->length) {
+ return;
+ } else if (i != w->length - 1) {
+ wchar_t *data = w->data + i;
+ al_memmove(data, data + 1, (w->length - i - 1) * sizeof(wchar_t));
+ }
+ w->length--;
+ w->data[w->length] = L'\0';
+}
+
static inline s32 al_wstr_width(wstr *w)
{
#ifdef AL_HAVE_WIDE_STRING_WIDTH