diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2021-02-11 12:58:06 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2021-02-11 12:58:06 +0100 |
| commit | 1ace7169372444d319740c8219b7131e5120428f (patch) | |
| tree | cc52b9529d67da99b747f8a2a15362d5099bf57e | |
| parent | 367764b679ae5addcab6f968149ea25cc98663b9 (diff) | |
| download | vis-1ace7169372444d319740c8219b7131e5120428f.tar.gz vis-1ace7169372444d319740c8219b7131e5120428f.tar.xz | |
sam: simplify trailing match handling for x/y commands
Should be no functional change, just a simpler implementation.
| -rw-r--r-- | sam.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -1393,15 +1393,13 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti Text *txt = win->file->text; if (cmd->regex) { - bool trailing_match = false; size_t start = range->start, end = range->end; size_t last_start = argv[0][0] == 'x' ? EPOS : start; size_t nsub = 1 + text_regex_nsub(cmd->regex); if (nsub > MAX_REGEX_SUB) nsub = MAX_REGEX_SUB; RegexMatch match[MAX_REGEX_SUB]; - while (start < end || trailing_match) { - trailing_match = false; + while (start <= end) { char c; int flags = start > range->start && text_byte_get(txt, start - 1, &c) && c != '\n' ? @@ -1418,7 +1416,6 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti if (match[0].start == match[0].end) { if (last_start == match[0].start) { start++; - trailing_match = start == end; continue; } /* in Plan 9's regexp library ^ matches the beginning @@ -1433,11 +1430,10 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti } else { start = match[0].end; } - trailing_match = start == end; } else { if (argv[0][0] == 'y') r = text_range_new(start, end); - start = end; + start = end + 1; } if (text_range_valid(&r)) { |
