/* * Ported from get_first_set() in pcre_get.c in pcre source. */ static int matchres_first_set(cs_matchres_t *mr, const char *group_name) { cs_regexp_t *regexp = mr->regexp; pcre *re = regexp->re; pcre_extra *extra = regexp->extra; unsigned long options; int jchanged; pcre_fullinfo(re, extra, PCRE_INFO_OPTIONS, &options); pcre_fullinfo(re, extra, PCRE_INFO_JCHANGED, &jchanged); if (options & PCRE_DUPNAMES || jchanged) { char *first; char *last; uchar *entry; int entry_len = pcre_get_stringtable_entries(re, group_name, &first, &last); if (entry_len < 0) { return entry_len; } for (entry = (uchar *)first; entry <= (uchar *)last; entry += entry_len) { int n = entry[0] << 8 | entry[1]; if (mr->ovector[n * 2] >= 0) { return n; } } return entry[0] << 8 | entry[1]; } else { return pcre_get_stringnumber(re, group_name); } }
static int get_first_set(const pcre16 *code, PCRE_SPTR16 stringname, int *ovector) #endif { const REAL_PCRE *re = (const REAL_PCRE *)code; int entrysize; pcre_uchar *entry; #ifdef COMPILE_PCRE8 char *first, *last; #else PCRE_UCHAR16 *first, *last; #endif #ifdef COMPILE_PCRE8 if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0) return pcre_get_stringnumber(code, stringname); entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last); #else if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0) return pcre16_get_stringnumber(code, stringname); entrysize = pcre16_get_stringtable_entries(code, stringname, &first, &last); #endif if (entrysize <= 0) return entrysize; for (entry = (pcre_uchar *)first; entry <= (pcre_uchar *)last; entry += entrysize) { int n = GET2(entry, 0); if (ovector[n*2] >= 0) return n; } return GET2(entry, 0); }
static int get_first_set(const pcre *code, const char *stringname, int *ovector) { const real_pcre *re = (const real_pcre *)code; int entrysize; char *first, *last; uschar *entry; if( (re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0 ) return pcre_get_stringnumber(code, stringname); entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last); if( entrysize <= 0 ) return entrysize; for( entry = (uschar *)first; entry <= (uschar *)last; entry += entrysize ) { int n = (entry[0] << 8) + entry[1]; if (ovector[n*2] >= 0) return n; } return (first[0] << 8) + first[1]; }