in src/couch_quickjs/quickjs/libregexp.c [1029:1078]
static int re_parse_captures(REParseState *s, int *phas_named_captures,
const char *capture_name)
{
const uint8_t *p;
int capture_index;
char name[TMP_BUF_SIZE];
capture_index = 1;
*phas_named_captures = 0;
for (p = s->buf_start; p < s->buf_end; p++) {
switch (*p) {
case '(':
if (p[1] == '?') {
if (p[2] == '<' && p[3] != '=' && p[3] != '!') {
*phas_named_captures = 1;
/* potential named capture */
if (capture_name) {
p += 3;
if (re_parse_group_name(name, sizeof(name), &p) == 0) {
if (!strcmp(name, capture_name))
return capture_index;
}
}
capture_index++;
if (capture_index >= CAPTURE_COUNT_MAX)
goto done;
}
} else {
capture_index++;
if (capture_index >= CAPTURE_COUNT_MAX)
goto done;
}
break;
case '\\':
p++;
break;
case '[':
for (p += 1 + (*p == ']'); p < s->buf_end && *p != ']'; p++) {
if (*p == '\\')
p++;
}
break;
}
}
done:
if (capture_name)
return -1;
else
return capture_index;
}