summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--str.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/str.h b/str.h
index 3f2028d..bafec19 100644
--- a/str.h
+++ b/str.h
@@ -21,6 +21,7 @@ size_t slen(const string);
void scats(string *, strv_t);
void scatc(string *, char);
void sfree(string);
+void sreplace(string *str, size_t i, size_t n, strv_t with);
string sfmt(const char *fmt, ...);
string sdup(const char *);
@@ -81,5 +82,15 @@ string sdup(const char *s) {
return d;
}
+void sreplace(string *str, size_t i, size_t n, strv_t with) {
+ string s = *str;
+ size_t new_n = DA_LEN(s) + with.n - n;
+ DA_FIT(s, new_n);
+ memmove(&s[i + with.n], &s[i + n], slen(s) - (i + n));
+ memcpy(&s[i], with.s, with.n);
+ s[new_n - 1] = 0;
+ DA_LEN(s) = new_n;
+}
+
#endif
#endif