diff options
Diffstat (limited to 'include/al')
| -rw-r--r-- | include/al/str.h | 17 | ||||
| -rw-r--r-- | include/al/wstr.h | 9 |
2 files changed, 20 insertions, 6 deletions
diff --git a/include/al/str.h b/include/al/str.h index 4ff936b..e9ac8f2 100644 --- a/include/al/str.h +++ b/include/al/str.h @@ -103,6 +103,23 @@ static inline void al_str_prepend(str *s, str *c) al_str_insert(s, 0, c); } +static inline void al_str_remove_at(str *s, u32 i) +{ + al_assert(i < s->length); + if (i != --s->length) { + al_memmove(s->data + i, s->data + i + 1, s->length - i); + } +} + +static inline void al_str_replace(str *s, char c, char n) +{ + for (u32 i = 0; i < s->length; i++) { + if (al_str_at(s, i) == c) { + al_str_at(s, i) = n; + } + } +} + static inline s32 al_str_cmp(str *s, str *c, u32 start, u32 length) { if (length > c->length) return 1; diff --git a/include/al/wstr.h b/include/al/wstr.h index efecbfe..f700037 100644 --- a/include/al/wstr.h +++ b/include/al/wstr.h @@ -147,13 +147,10 @@ static inline void al_wstr_insert(wstr *w, u32 i, wstr *c) 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)); + al_assert(i < w->length); + if (i != --w->length) { + al_memmove(w->data + i, w->data + i + 1, (w->length - i) * sizeof(wchar_t)); } - w->length--; w->data[w->length] = L'\0'; } |