diff options
| author | Tyge Løvset <[email protected]> | 2022-06-01 21:43:30 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-01 21:43:30 +0200 |
| commit | 89424a2ff3a46dbd82a6954f97a25f973e981c98 (patch) | |
| tree | 2b72d8066cebaa580c3686bf477456e10d3e37fc | |
| parent | 239276667b547dc795678cf3ac3c28c5ccf72532 (diff) | |
| download | STC-modified-89424a2ff3a46dbd82a6954f97a25f973e981c98.tar.gz STC-modified-89424a2ff3a46dbd82a6954f97a25f973e981c98.zip | |
Renamed cstr_replace() => cstr_replace_at(), and cstr_replace_one() => cstr_replace(self, start, search, replace).
| -rw-r--r-- | docs/cstr_api.md | 8 | ||||
| -rw-r--r-- | examples/demos.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 6 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 2 | ||||
| -rw-r--r-- | include/stc/alt/cstr.h | 2 | ||||
| -rw-r--r-- | include/stc/cstr.h | 4 |
6 files changed, 12 insertions, 12 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 989f59df..ca6a7d3f 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -78,11 +78,11 @@ 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); -void cstr_replace(cstr* self, size_t pos, size_t len, const char* repl); +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); +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); -size_t cstr_replace_one(cstr* self, size_t startpos, const char* search, const char* repl); -void cstr_replace_all(cstr* self, const char* search, const char* repl); void cstr_erase(cstr* self, size_t pos); void cstr_erase_n(cstr* self, size_t pos, size_t n); @@ -149,7 +149,7 @@ int main() { cstr_erase_n(&s1, 7, 5); // -nine printf("%s\n", cstr_str(&s1)); - cstr_replace(&s1, cstr_find(s1, "seven"), 5, "four"); + cstr_replace_at(&s1, cstr_find(s1, "seven"), 5, "four"); printf("%s\n", cstr_str(&s1)); // reassign: diff --git a/examples/demos.c b/examples/demos.c index a6b23bc4..04d579db 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_one(&cs, 0, "seven", "four"); + cstr_replace(&cs, 0, "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/replace.c b/examples/replace.c index a70fcc8e..eba8e813 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -16,15 +16,15 @@ int main () cstr_append(&m, cstr_str(&m)); printf("%s\n", cstr_str(&m)); - cstr_replace(&s, 9, 5, s2); // "this is an example string." (1) + cstr_replace_at(&s, 9, 5, s2); // "this is an example string." (1) printf("(1) %s\n", cstr_str(&s)); cstr_replace_n(&s, 19, 6, s3+7, 6); // "this is an example phrase." (2) printf("(2) %s\n", cstr_str(&s)); - cstr_replace(&s, 8, 10, "just a"); // "this is just a phrase." (3) + cstr_replace_at(&s, 8, 10, "just a"); // "this is just a phrase." (3) printf("(3) %s\n", cstr_str(&s)); cstr_replace_n(&s, 8, 6,"a shorty", 7); // "this is a short phrase." (4) printf("(4) %s\n", cstr_str(&s)); - cstr_replace(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) + cstr_replace_at(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) printf("(5) %s\n", cstr_str(&s)); } } diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index 89d5375f..27f33761 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_one(&hello, 0, "🐨", "ø"); + cstr_replace(&hello, 0, "🐨", "ø"); printf("%s\n", cstr_str(&hello)); c_foreach (c, cstr, hello) diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 32dec09d..da3776bd 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -102,7 +102,7 @@ STC_INLINE void cstr_insert(cstr* self, const size_t pos, const char* st { cstr_replace_n(self, pos, 0, str, strlen(str)); } STC_INLINE void cstr_insert_s(cstr* self, const size_t pos, cstr s) { cstr_replace_n(self, pos, 0, s.str, _cstr_p(&s)->size); } -STC_INLINE void cstr_replace(cstr* self, const size_t pos, const size_t len, const char* str) +STC_INLINE void cstr_replace_at(cstr* self, const size_t pos, const size_t len, const char* str) { cstr_replace_n(self, pos, len, str, strlen(str)); } STC_INLINE void cstr_replace_s(cstr* self, const size_t pos, const size_t len, cstr s) { cstr_replace_n(self, pos, len, s.str, _cstr_p(&s)->size); } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 1bf58a18..19dc0d67 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -317,10 +317,10 @@ STC_INLINE void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* r memcpy(d + pos, repl, n); } -STC_INLINE void cstr_replace(cstr* self, size_t pos, size_t len, const char* repl) +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_one(cstr* self, size_t pos, const char* search, const char* repl) { +STC_INLINE size_t cstr_replace(cstr* self, size_t pos, const char* search, const char* repl) { pos = cstr_find_from(*self, pos, search); if (pos == cstr_npos) return pos; |
