diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2021-02-11 10:47:27 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2021-02-11 10:47:27 +0100 |
| commit | 367764b679ae5addcab6f968149ea25cc98663b9 (patch) | |
| tree | 4bbe0e7c270b57ef720283e8559c664c0fdc8881 | |
| parent | c8a098317468371d95c1bc64775aad790d9fae6d (diff) | |
| download | vis-367764b679ae5addcab6f968149ea25cc98663b9.tar.gz vis-367764b679ae5addcab6f968149ea25cc98663b9.tar.xz | |
sam: tweak handling of zero length matches in y commands
In sam(1) a command like x/[a-z]+/ y/-?/ matches every character
individually, whereas in vis it would produce a zero length match before
each character as is correctly the case for the x counter part.
| -rw-r--r-- | sam.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1394,7 +1394,8 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti if (cmd->regex) { bool trailing_match = false; - size_t start = range->start, end = range->end, last_start = EPOS; + 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; @@ -1413,7 +1414,7 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti if (argv[0][0] == 'x') r = text_range_new(match[0].start, match[0].end); else - r = text_range_new(start, match[0].start); + r = text_range_new(last_start, match[0].start); if (match[0].start == match[0].end) { if (last_start == match[0].start) { start++; @@ -1428,8 +1429,10 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti if (end == match[0].start && start > range->start && text_byte_get(txt, end-1, &c) && c == '\n') break; + start = match[0].end + 1; + } else { + start = match[0].end; } - start = match[0].end; trailing_match = start == end; } else { if (argv[0][0] == 'y') @@ -1443,12 +1446,14 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti Register *reg = &vis->registers[VIS_REG_AMPERSAND+i]; register_put_range(vis, reg, txt, &match[i]); } + last_start = match[0].end; + } else { + last_start = start; } if (simulate) count++; else ret &= sam_execute(vis, win, cmd->cmd, NULL, &r); - last_start = start; } } } else { |
