diff options
Diffstat (limited to 'include/al')
| -rw-r--r-- | include/al/str.h | 4 | ||||
| -rw-r--r-- | include/al/wstr.h | 34 |
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 |