From 82f51c7e91fce6e080924ba369358830d4d1e5d2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 31 Oct 2024 18:39:55 +0100 Subject: Allow escaping the regex delimeter --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3