summaryrefslogtreecommitdiff
path: root/xs_regex.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-08-17 17:38:39 +0200
committerdefault <nobody@localhost>2023-08-17 17:38:39 +0200
commit6ede6497ad2a63e5ff2b57abba827d0da469f923 (patch)
treea183cf6a66ff73b3a524fdc8955036f58ecea454 /xs_regex.h
parentb3b4a4ef61da620d97e1373b16b9844fa6777370 (diff)
Convert 'Link' attachments that have a media extension to something more useful.
Diffstat (limited to 'xs_regex.h')
-rw-r--r--xs_regex.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/xs_regex.h b/xs_regex.h
index 6fb6cca..7e1c80f 100644
--- a/xs_regex.h
+++ b/xs_regex.h
@@ -8,8 +8,10 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count);
#define xs_regex_split(str, rx) xs_regex_split_n(str, rx, XS_ALL)
xs_list *xs_regex_match_n(const char *str, const char *rx, int count);
#define xs_regex_match(str, rx) xs_regex_match_n(str, rx, XS_ALL)
-xs_list *xs_regex_replace_n(const char *str, const char *rx, const char *rep, int count);
-#define xs_regex_replace(str, rx, rep) xs_regex_replace_n(str, rx, rep, XS_ALL)
+xs_list *xs_regex_replace_in(xs_str *str, const char *rx, const char *rep, int count);
+#define xs_regex_replace_i(str, rx, rep) xs_regex_replace_in(str, rx, rep, XS_ALL)
+#define xs_regex_replace_n(str, rx, rep, count) xs_regex_replace_in(xs_dup(str), rx, rep, count)
+#define xs_regex_replace(str, rx, rep) xs_regex_replace_in(xs_dup(str), rx, rep, XS_ALL)
#ifdef XS_IMPLEMENTATION
@@ -78,7 +80,7 @@ xs_list *xs_regex_match_n(const char *str, const char *rx, int count)
}
-xs_list *xs_regex_replace_n(const char *str, const char *rx, const char *rep, int count)
+xs_list *xs_regex_replace_in(xs_str *str, const char *rx, const char *rep, int count)
/* replaces all matches with the rep string. If it contains unescaped &,
they are replaced with the match */
{
@@ -121,6 +123,8 @@ xs_list *xs_regex_replace_n(const char *str, const char *rx, const char *rep, in
n++;
}
+ xs_free(str);
+
return s;
}