Skip to content

Commit

Permalink
sam: simplify trailing match handling for x/y commands
Browse files Browse the repository at this point in the history
Should be no functional change, just a simpler implementation.
  • Loading branch information
martanne committed Feb 11, 2021
1 parent 367764b commit 1ace716
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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' ?
Expand All @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit 1ace716

Please sign in to comment.