diff options
| author | Tyge Løvset <[email protected]> | 2022-06-01 21:57:03 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-01 21:57:03 +0200 |
| commit | ccfef3a4f82ce48facde6499c53e62ab1065cd8b (patch) | |
| tree | e6a67de45b4cddca09b8721c3582e7906f3c3f56 | |
| parent | 89424a2ff3a46dbd82a6954f97a25f973e981c98 (diff) | |
| download | STC-modified-ccfef3a4f82ce48facde6499c53e62ab1065cd8b.tar.gz STC-modified-ccfef3a4f82ce48facde6499c53e62ab1065cd8b.zip | |
Change: Split replace into two: cstr_replace(s, search, repl), cstr_replace_from(s, pos, search, repl): matches cstr_find() + cstr_find_from().
| -rw-r--r-- | docs/cstr_api.md | 3 | ||||
| -rw-r--r-- | examples/demos.c | 2 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 2 | ||||
| -rw-r--r-- | include/stc/cstr.h | 5 |
4 files changed, 8 insertions, 4 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index ca6a7d3f..09ca6592 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -78,8 +78,9 @@ void cstr_insert(cstr* self, size_t pos, const char* ins); void cstr_insert_s(cstr* self, size_t pos, cstr ins); void cstr_insert_n(cstr* self, size_t pos, const char* ins, size_t n); -size_t cstr_replace(cstr* self, size_t start, const char* search, const char* repl); void cstr_replace_all(cstr* self, const char* search, const char* repl); +size_t cstr_replace(cstr* self, const char* search, const char* repl); +size_t cstr_replace_from(cstr* self, size_t pos, const char* search, const char* repl); void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl); void cstr_replace_s(cstr* self, size_t pos, size_t len, cstr repl); void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* repl, size_t n); diff --git a/examples/demos.c b/examples/demos.c index 04d579db..7c5b9a4b 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -13,7 +13,7 @@ void stringdemo1() cstr_erase_n(&cs, 7, 5); // -nine printf("%s.\n", cstr_str(&cs)); - cstr_replace(&cs, 0, "seven", "four"); + cstr_replace(&cs, "seven", "four"); printf("%s.\n", cstr_str(&cs)); cstr_take(&cs, cstr_from_fmt("%s *** %s", cstr_str(&cs), cstr_str(&cs))); diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index 27f33761..c38b37e4 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -13,7 +13,7 @@ int main() { ); printf("%s\n", cstr_str(&hello)); - cstr_replace(&hello, 0, "🐨", "ø"); + cstr_replace(&hello, "🐨", "ø"); printf("%s\n", cstr_str(&hello)); c_foreach (c, cstr, hello) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 19dc0d67..71206301 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -320,7 +320,7 @@ STC_INLINE void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* r STC_INLINE void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl) { cstr_replace_n(self, pos, len, repl, strlen(repl)); } -STC_INLINE size_t cstr_replace(cstr* self, size_t pos, const char* search, const char* repl) { +STC_INLINE size_t cstr_replace_from(cstr* self, size_t pos, const char* search, const char* repl) { pos = cstr_find_from(*self, pos, search); if (pos == cstr_npos) return pos; @@ -329,6 +329,9 @@ STC_INLINE size_t cstr_replace(cstr* self, size_t pos, const char* search, const return pos + rlen; } +STC_INLINE size_t cstr_replace(cstr* self, const char* search, const char* repl) + { return cstr_replace_from(self, 0, search, repl); } + STC_INLINE void cstr_replace_s(cstr* self, size_t pos, size_t len, cstr s) { csview sv = cstr_sv(&s); cstr_replace_n(self, pos, len, sv.str, sv.size); |
