summaryrefslogtreecommitdiff
path: root/string32.c
diff options
context:
space:
mode:
Diffstat (limited to 'string32.c')
-rw-r--r--string32.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/string32.c b/string32.c
index 35aa1a2..4d033c0 100644
--- a/string32.c
+++ b/string32.c
@@ -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;
}