53#define MAX_CACHE_BACKREF 128
57#define SET_BIT(c) re->start_bitmap[(c)/8] |= (1u << ((c)&7))
109int prev_cap_recno = -1;
111int prev_recurse_recno = -1;
112int prev_recurse_d = 0;
113uint32_t once_fudge = 0;
130if ((*countptr)++ > 1000)
return -1;
141 if (branchlength >= UINT16_MAX)
143 branchlength = UINT16_MAX;
158 cs = cc +
GET(cc, 1);
164 goto PROCESS_NON_CAPTURE;
186 d = find_minlength(re, cc, startcode, utf, recurses, countptr,
190 do cc +=
GET(cc, 1);
while (*cc ==
OP_ALT);
204 if (dupcapused || recno != prev_cap_recno)
206 prev_cap_recno = recno;
207 prev_cap_d = find_minlength(re, cc, startcode, utf, recurses, countptr,
209 if (prev_cap_d < 0)
return prev_cap_d;
211 branchlength += prev_cap_d;
212 do cc +=
GET(cc, 1);
while (*cc ==
OP_ALT);
236 if (length < 0 || (!had_recurse && branchlength < length))
237 length = branchlength;
238 if (op !=
OP_ALT || length == 0)
return length;
239 nextbranch = cc +
GET(cc, 1);
253 do cc +=
GET(cc, 1);
while (*cc ==
OP_ALT);
293 do cc +=
GET(cc, 1);
while (*cc ==
OP_ALT);
317#ifdef SUPPORT_UNICODE
318 if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
336 branchlength +=
GET2(cc,1);
338#ifdef SUPPORT_UNICODE
339 if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
344 branchlength +=
GET2(cc,1);
386#ifdef SUPPORT_UNICODE
418#ifdef SUPPORT_WIDE_CHARS
450 branchlength +=
GET2(cc,1);
493 recno =
GET2(slot, 0);
495 if (recno <= backref_cache[0] && backref_cache[recno] >= 0)
496 dd = backref_cache[recno];
500 if (cs ==
NULL)
return -2;
501 do ce +=
GET(ce, 1);
while (*ce ==
OP_ALT);
507 if (cc > cs && cc < ce)
514 for (r = recurses; r !=
NULL; r = r->
prev)
515 if (r->
group == cs)
break;
522 this_recurse.
prev = recurses;
523 this_recurse.
group = cs;
524 dd = find_minlength(re, cs, startcode, utf, &this_recurse,
525 countptr, backref_cache);
526 if (dd < 0)
return dd;
531 backref_cache[recno] = dd;
532 for (i = backref_cache[0] + 1; i < recno; i++) backref_cache[i] = -1;
533 backref_cache[0] = recno;
543 goto REPEAT_BACK_REFERENCE;
551 if (recno <= backref_cache[0] && backref_cache[recno] >= 0)
552 d = backref_cache[recno];
561 if (cs ==
NULL)
return -2;
562 do ce +=
GET(ce, 1);
while (*ce ==
OP_ALT);
567 if (cc > cs && cc < ce)
574 for (r = recurses; r !=
NULL; r = r->
prev)
if (r->
group == cs)
break;
581 this_recurse.
prev = recurses;
582 this_recurse.
group = cs;
583 d = find_minlength(re, cs, startcode, utf, &this_recurse, countptr,
591 backref_cache[recno] = d;
592 for (i = backref_cache[0] + 1; i < recno; i++) backref_cache[i] = -1;
593 backref_cache[0] = recno;
600 REPEAT_BACK_REFERENCE:
636 if ((d > 0 && (
INT_MAX/d) <
min) || UINT16_MAX - branchlength <
min*d)
637 branchlength = UINT16_MAX;
638 else branchlength +=
min * d;
648 if (recno == prev_recurse_recno)
650 branchlength += prev_recurse_d;
654 do ce +=
GET(ce, 1);
while (*ce ==
OP_ALT);
655 if (cc > cs && cc < ce)
660 for (r = recurses; r !=
NULL; r = r->
prev)
if (r->
group == cs)
break;
665 this_recurse.
prev = recurses;
666 this_recurse.
group = cs;
667 prev_recurse_d = find_minlength(re, cs, startcode, utf, &this_recurse,
668 countptr, backref_cache);
669 if (prev_recurse_d < 0)
return prev_recurse_d;
670 prev_recurse_recno = recno;
671 branchlength += prev_recurse_d;
727#ifdef SUPPORT_UNICODE
728 if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
795#if PCRE2_CODE_UNIT_WIDTH != 8
796if (c > 0xff)
SET_BIT(0xff);
else
804#ifdef SUPPORT_UNICODE
807#if PCRE2_CODE_UNIT_WIDTH == 8
809#elif PCRE2_CODE_UNIT_WIDTH == 16
810 if ((c & 0xfc00) == 0xd800) GETUTF16INC(c,
p);
819#ifdef SUPPORT_UNICODE
823#if PCRE2_CODE_UNIT_WIDTH == 8
869set_type_bits(
pcre2_real_code *re,
int cbit_type,
unsigned int table_limit)
872for (c = 0; c < table_limit; c++)
874#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
875if (table_limit == 32)
return;
876for (c = 128; c < 256; c++)
910set_nottype_bits(
pcre2_real_code *re,
int cbit_type,
unsigned int table_limit)
913for (c = 0; c < table_limit; c++)
915#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
916if (table_limit != 32)
for (c = 24; c < 32; c++) re->
start_bitmap[c] = 0xff;
962#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
963int table_limit = utf? 16:32;
983 uint8_t *classmap =
NULL;
984#ifdef SUPPORT_WIDE_CHARS
1088 const uint32_t *
p =
PRIV(ucd_caseless_sets) + tcode[2];
1091#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
1121 ncode = tcode +
GET(tcode, 1);
1122 while (*ncode ==
OP_ALT) ncode +=
GET(ncode, 1);
1137 ncode +=
GET(ncode, 1);
1138 while (*ncode ==
OP_ALT) ncode +=
GET(ncode, 1);
1214 rc = set_start_bits(re, tcode, utf, ucp, depthptr);
1221 do tcode +=
GET(tcode, 1);
while (*tcode ==
OP_ALT);
1261 do tcode +=
GET(tcode, 1);
while (*tcode ==
OP_ALT);
1270 rc = set_start_bits(re, ++tcode, utf, ucp, depthptr);
1272 do tcode +=
GET(tcode,1);
while (*tcode ==
OP_ALT);
1280 do tcode +=
GET(tcode,1);
while (*tcode ==
OP_ALT);
1292 tcode = set_table_bit(re, tcode + 1,
FALSE, utf, ucp);
1301 tcode = set_table_bit(re, tcode + 1,
TRUE, utf, ucp);
1309 tcode = set_table_bit(re, tcode + 1 +
IMM2_SIZE,
FALSE, utf, ucp);
1315 tcode = set_table_bit(re, tcode + 1 +
IMM2_SIZE,
TRUE, utf, ucp);
1327 (
void)set_table_bit(re, tcode + 1,
FALSE, utf, ucp);
1338 (
void)set_table_bit(re, tcode + 1,
TRUE, utf, ucp);
1355#if PCRE2_CODE_UNIT_WIDTH != 8
1362#ifdef SUPPORT_UNICODE
1394#if PCRE2_CODE_UNIT_WIDTH != 8
1401#ifdef SUPPORT_UNICODE
1424 set_nottype_bits(re,
cbit_digit, table_limit);
1434 set_nottype_bits(re,
cbit_space, table_limit);
1444 set_nottype_bits(re,
cbit_word, table_limit);
1449 set_type_bits(re,
cbit_word, table_limit);
1494#if PCRE2_CODE_UNIT_WIDTH != 8
1501#ifdef SUPPORT_UNICODE
1531#if PCRE2_CODE_UNIT_WIDTH != 8
1538#ifdef SUPPORT_UNICODE
1554 set_nottype_bits(re,
cbit_digit, table_limit);
1562 set_nottype_bits(re,
cbit_space, table_limit);
1570 set_nottype_bits(re,
cbit_word, table_limit);
1574 set_type_bits(re,
cbit_word, table_limit);
1588#ifdef SUPPORT_WIDE_CHARS
1604#if PCRE2_CODE_UNIT_WIDTH == 8
1605 if (utf && (xclassflags &
XCL_NOT) == 0)
1609 tcode +=
GET(tcode, 1);
1611 for (;;)
switch (*
p++)
1615 while ((*
p & 0xc0) == 0x80)
p++;
1621 while ((*
p & 0xc0) == 0x80)
p++;
1623 while ((*
p & 0xc0) == 0x80)
p++;
1629 goto HANDLE_CLASSMAP;
1650#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
1656#elif PCRE2_CODE_UNIT_WIDTH != 8
1668 classmap = (uint8_t *)(++tcode);
1679#if defined SUPPORT_WIDE_CHARS && PCRE2_CODE_UNIT_WIDTH == 8
1682 if (classmap !=
NULL)
1684#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8
1687 for (c = 0; c < 16; c++) re->
start_bitmap[c] |= classmap[c];
1688 for (c = 128; c < 256; c++)
1690 if ((classmap[c/8] & (1u << (c&7))) != 0)
1692 int d = (c >> 6) | 0xc0;
1694 c = (c & 0xc0) + 0x40 - 1;
1703 for (c = 0; c < 32; c++) re->
start_bitmap[c] |= classmap[c];
1725 else try_next =
FALSE;
1736 code +=
GET(code, 1);
1781 int rc = set_start_bits(re, code, utf, ucp, &depth);
1800 for (i = 0; i < 256;
p++, i += 8)
1806 uint8_t y = x & (~x + 1);
1807 if (y != x)
goto DONE;
1812#if PCRE2_CODE_UNIT_WIDTH != 8
1813 if (i == 248 && x == 0x80)
goto DONE;
1822 case 2: c += 1;
break;
case 4: c += 2;
break;
1823 case 8: c += 3;
break;
case 16: c += 4;
break;
1824 case 32: c += 5;
break;
case 64: c += 6;
break;
1825 case 128: c += 7;
break;
1832#if PCRE2_CODE_UNIT_WIDTH == 8
1833 if (utf && c > 127)
goto DONE;
1840#ifdef SUPPORT_UNICODE
1848 if (d !=
a)
goto DONE;
1866 (b < 0 || re->last_codeunit != (uint32_t)b)
1893 backref_cache[0] = 0;
1894 min = find_minlength(re, code, code, utf,
NULL, &
count, backref_cache);
count(Countable|array $value, int $mode=COUNT_NORMAL)
memset(ptr, 0, type->size)
#define PCRE2_MATCH_UNSET_BACKREF
PCRE2_SPTR PRIV find_bracket(PCRE2_SPTR code, BOOL utf, int number)
@ OP_NOT_UCP_WORD_BOUNDARY
#define PCRE2_FIRSTMAPSET
#define GETUTF8INC(c, eptr)
#define PCRE2_FIRSTCASELESS
#define UCD_OTHERCASE(ch)
#define PCRE2_MATCH_EMPTY
#define TABLE_GET(c, table, default)
unsigned int PRIV ord2utf(uint32_t cvalue, PCRE2_UCHAR *buffer)
int PRIV study(pcre2_real_code *re)
#define MAX_CACHE_BACKREF
struct recurse_check * prev
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)