aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-10-30 16:50:19 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-10-30 16:50:19 -0400
commitb306f72050a8ff2512cff2977a5425c67d35790e (patch)
tree8e45e794c678355491bbbf2f63e0bb5823ed1877
parent3296ce42d9c97d24ee753c3ce911db75cfe01296 (diff)
Another fix to numbered captures
-rw-r--r--match.c8
1 files 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);