diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-13 21:21:50 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-03 13:22:14 +0200 |
| commit | ae9f7e9a55a7ebb7e0ccc67b6b063274efbc2cc3 (patch) | |
| tree | 729ded449730f1b9ddce233e0dd66a920e292a66 | |
| parent | 9c769add824b090c7c5073e945aee0df2a109a91 (diff) | |
| download | vis-ae9f7e9a55a7ebb7e0ccc67b6b063274efbc2cc3.tar.gz vis-ae9f7e9a55a7ebb7e0ccc67b6b063274efbc2cc3.tar.xz | |
sam: fix regex parsing
This fixes y/\n/i/FOO
| -rw-r--r-- | sam.c | 37 |
1 files changed, 5 insertions, 32 deletions
@@ -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; } |
