aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-20 16:12:46 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-20 16:12:46 -0800
commitc46a8227d0bfc31e4f71b6441303348f5c31174b (patch)
treea06e3747fa09c0d737f724000f0e516f9c853b32 /match.c
parentb50ad0cad099c99d4e739fc465b69779f661b77d (diff)
Added --skip flag for skipping over patterns
Diffstat (limited to 'match.c')
-rw-r--r--match.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/match.c b/match.c
index e89abd4..c57bfcf 100644
--- a/match.c
+++ b/match.c
@@ -128,7 +128,7 @@ static const char *match_backref(const char *str, match_t *cap, bool ignorecase)
//
// Find the next match after prev (or the first match if prev is NULL)
//
-match_t *next_match(def_t *defs, file_t *f, match_t *prev, pat_t *pat, bool ignorecase)
+match_t *next_match(def_t *defs, file_t *f, match_t *prev, pat_t *pat, pat_t *skip, bool ignorecase)
{
const char *str;
if (prev) {
@@ -137,9 +137,14 @@ match_t *next_match(def_t *defs, file_t *f, match_t *prev, pat_t *pat, bool igno
} else {
str = f->contents;
}
- for (; str < f->end; ++str) {
+ while (str < f->end) {
match_t *m = match(defs, f, str, pat, ignorecase);
if (m) return m;
+ match_t *s;
+ if (skip && (s = match(defs, f, str, skip, ignorecase))) {
+ str = s->end > str ? s->end : str + 1;
+ recycle_if_unused(&s);
+ } else ++str;
}
return NULL;
}