diff options
| author | Tyge Løvset <[email protected]> | 2023-03-13 12:40:07 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-13 12:40:07 +0100 |
| commit | 5ef0986e98ef021e5ce2f46cdaba244c2c51bc4c (patch) | |
| tree | 1ea17905ceeafe0e4fd4c748d3fb11dbc0a72191 /include/stc | |
| parent | fddae5ef07fc0e9a018e56a9843e059a737e4db7 (diff) | |
| download | STC-modified-5ef0986e98ef021e5ce2f46cdaba244c2c51bc4c.tar.gz STC-modified-5ef0986e98ef021e5ce2f46cdaba244c2c51bc4c.zip | |
Fixed bug and improved generic c_eraseremove_if().
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/ccommon.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 33446982..ad6063e4 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -254,10 +254,12 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_eraseremove_if(it, C, cnt, pred) do { \ C* _cnt = &cnt; \ intptr_t _n = 0; \ - C##_iter _first = C##_begin(_cnt), it = _first; \ - for (; it.ref; C##_next(&it)) \ - if (pred) ++_n; \ - else C##_value_drop(_first.ref), *_first.ref = *it.ref, C##_next(&_first); \ + C##_iter it = C##_begin(_cnt), _i; \ + while (it.ref && !(pred)) \ + C##_next(&it); \ + for (_i = it; it.ref; C##_next(&it)) \ + if (pred) C##_value_drop(it.ref), ++_n; \ + else *_i.ref = *it.ref, C##_next(&_i); \ _cnt->_len -= _n; \ } while (0) |
