From b306f72050a8ff2512cff2977a5425c67d35790e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 30 Oct 2022 16:50:19 -0400 Subject: Another fix to numbered captures --- match.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/match.c b/match.c index 6602f45..8d02109 100644 --- a/match.c +++ b/match.c @@ -897,9 +897,6 @@ bool next_match(match_t **m, const char *start, const char *end, pat_t *pat, pat __attribute__((nonnull)) static match_t *_get_numbered_capture(match_t *m, int *n) { - if (m->pat->type == BP_CAPTURE && m->pat->args.capture.namelen > 0) - return NULL; - if ((m->pat->type == BP_CAPTURE && m->pat->args.capture.namelen == 0) || m->pat->type == BP_TAGGED) { if (*n == 1) { return m; @@ -908,6 +905,10 @@ static match_t *_get_numbered_capture(match_t *m, int *n) return NULL; } } + + if (m->pat->type == BP_CAPTURE || m->pat->type == BP_TAGGED) + return NULL; + if (m->children) { for (int i = 0; m->children[i]; i++) { match_t *cap = _get_numbered_capture(m->children[i], n); @@ -924,6 +925,7 @@ match_t *get_numbered_capture(match_t *m, int n) { if (n <= 0) return m; if (m->pat->type == BP_TAGGED || m->pat->type == BP_CAPTURE) { + if (n == 1) return m; if (m->children) { for (int i = 0; m->children[i]; i++) { match_t *cap = _get_numbered_capture(m->children[i], &n); -- cgit v1.2.3