diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-31 18:39:55 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-31 18:39:55 +0100 |
commit | 82f51c7e91fce6e080924ba369358830d4d1e5d2 (patch) | |
tree | 31ccc47dbb19930dbc2ef4af15a22a9048ad905f | |
parent | 5a64fd9bdefdafa149fe2ff318d8046191961959 (diff) |
Allow escaping the regex delimeter
-rw-r--r-- | src/main.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; } |