summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-06-01 21:57:03 +0200
committerTyge Løvset <[email protected]>2022-06-01 21:57:03 +0200
commitccfef3a4f82ce48facde6499c53e62ab1065cd8b (patch)
treee6a67de45b4cddca09b8721c3582e7906f3c3f56 /include
parent89424a2ff3a46dbd82a6954f97a25f973e981c98 (diff)
downloadSTC-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().
Diffstat (limited to 'include')
-rw-r--r--include/stc/cstr.h5
1 files changed, 4 insertions, 1 deletions
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);