diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-18 20:54:07 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-18 20:54:07 -0500 |
commit | 8a4984e0e15fcfb0be6db242ab3f60325b80abd8 (patch) | |
tree | b71eb3ec8e715164a9347cb6ce7d6d83298309d0 /string32.c | |
parent | 530001a433c847b40d109d08cd8ff0958efdca1c (diff) |
bug fixes, narrow file list based on search term
Diffstat (limited to 'string32.c')
-rw-r--r-- | string32.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -91,18 +91,17 @@ size_t str32_count_char(String32 s, char32_t c) { // returns number of characters deleted from s size_t str32_remove_all_instances_of_char(String32 *s, char32_t c) { - bool increment = true; char32_t *str = s->str; size_t ndeleted = 0; - for (size_t i = 0; i < s->len; i += increment, increment = true) { - if (str[i] == c) { - --s->len; - if (i < s->len) { - str[i] = str[i+1]; - } + size_t len = s->len; + size_t out = 0; + for (size_t in = 0; in < len; ++in) { + if (str[in] == c) { ++ndeleted; - increment = false; + } else { + str[out++] = str[in]; } } + s->len = out; return ndeleted; } |