aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-10-31 18:39:55 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-10-31 18:39:55 +0100
commit82f51c7e91fce6e080924ba369358830d4d1e5d2 (patch)
tree31ccc47dbb19930dbc2ef4af15a22a9048ad905f /src
parent5a64fd9bdefdafa149fe2ff318d8046191961959 (diff)
Allow escaping the regex delimeter
Diffstat (limited to 'src')
-rw-r--r--src/main.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 33e5869..eeb9f1f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -275,13 +275,18 @@ pattern_comp(u8view_t pat)
rune ldelim, rdelim;
if ((w = ucsnext(&ldelim, &pat)) == 0)
cerr(EXIT_FATAL, "Premature end of pattern");
+ if (ldelim == '\\')
+ cerr(EXIT_FATAL, "Cannot use %s\\%s as a delimeter", lquot, rquot);
rdelim = uprop_get_bpb(ldelim);
/* Find the right delimeter, which is optional for the last
operator */
u8view_t re = {pat.p, -1};
while ((w = ucsnext(&ch, &pat)) != 0) {
- if (ch == rdelim) {
+ if (ch == '\\') {
+ if (ucsnext(nullptr, &pat) == 0)
+ cerr(EXIT_FATAL, "Premature end of pattern");
+ } else if (ch == rdelim) {
re.len = pat.p - re.p - w;
break;
}