aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-11-04 12:21:54 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-11-04 12:50:08 +0100
commitfb414a7a85c6b8843d18030f07db0b8c80cc0251 (patch)
tree6a0612784bd7e89e1fabe061e93729f1057cd30a
parent64df94f24a6194428c884f86622439d5c6d7c9ba (diff)
downloadvis-fb414a7a85c6b8843d18030f07db0b8c80cc0251.tar.gz
vis-fb414a7a85c6b8843d18030f07db0b8c80cc0251.tar.xz
sam: y should also loop over empty trailing matches
The following x/example/ y/e/ i/-/ should produce `-e-xample-` where before it would wrongly result in `-e-xample`.
-rw-r--r--sam.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sam.c b/sam.c
index 669fdf9..e238825 100644
--- a/sam.c
+++ b/sam.c
@@ -895,9 +895,11 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
Text *txt = win->file->text;
if (cmd->regex) {
+ bool trailing_match = false;
size_t start = range->start, end = range->end, last_start = EPOS;
RegexMatch match[1];
- while (start < end) {
+ while (start < end || trailing_match) {
+ trailing_match = false;
bool found = text_search_range_forward(txt, start,
end - start, cmd->regex, 1, match,
start > range->start ? REG_NOTBOL : 0) == 0;
@@ -921,6 +923,8 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
break;
}
start = match[0].end;
+ if (start == end)
+ trailing_match = true;
} else {
if (argv[0][0] == 'y')
r = text_range_new(start, end);