vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e8a596a29e8c9163a8a56069f4e4ef4599780c52 parent 4036cbe92d8a39fdb568f8cdf98f5c8c71cedfab Author: Marc André Tanner <mat@brain-dump.org> Date: Sun, 13 Mar 2016 21:21:50 +0100 sam: fix regex parsing This fixes y/\n/i/FOO Diffstat:
| M | sam.c | | | 37 | +++++-------------------------------- |
1 file changed, 5 insertions(+), 32 deletions(-)
diff --git a/sam.c b/sam.c @@ -197,38 +197,11 @@ static char *parse_text(const char **s) { } static Regex *parse_regex(Vis *vis, const char **s) { - Buffer buf; - bool escaped = false; - char delim = **s; - buffer_init(&buf); - - for ((*s)++; **s && (**s != delim || escaped); (*s)++) { - if (!escaped && **s == '\\') { - escaped = true; - continue; - } - if (escaped) { - escaped = false; - if (**s != delim) - buffer_append(&buf, "\\", 1); - } - if (!buffer_append(&buf, *s, 1)) { - buffer_release(&buf); - return NULL; - } - } - - buffer_append(&buf, "\0", 1); - - Regex *regex = NULL; - - if (**s == delim || **s == '\0') { - if (**s == delim) - (*s)++; - regex = vis_regex(vis, buffer_length0(&buf) ? buf.data : NULL); - } - - buffer_release(&buf); + char *pattern = parse_delimited_text(s); + if (!pattern) + return NULL; + Regex *regex = vis_regex(vis, *pattern ? pattern : NULL); + free(pattern); return regex; }