1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-16 14:00:40 +00:00

pcre2: Update to 10.45

This commit is contained in:
Jakub Marcowski
2025-03-23 16:50:13 +01:00
parent 2303ce843a
commit 2c3e302c75
75 changed files with 24071 additions and 12755 deletions

View File

@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
New API code Copyright (c) 2016-2023 University of Cambridge
New API code Copyright (c) 2016-2024 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -38,9 +38,9 @@ POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/
/* This module contains an internal function that is used to match an extended
class. It is used by pcre2_auto_possessify() and by both pcre2_match() and
pcre2_def_match(). */
/* This module contains two internal functions that are used to match
OP_XCLASS and OP_ECLASS. It is used by pcre2_auto_possessify() and by both
pcre2_match() and pcre2_dfa_match(). */
#ifdef HAVE_CONFIG_H
@@ -66,114 +66,75 @@ Returns: TRUE if character matches, else FALSE
*/
BOOL
PRIV(xclass)(uint32_t c, PCRE2_SPTR data, BOOL utf)
PRIV(xclass)(uint32_t c, PCRE2_SPTR data, const uint8_t *char_lists_end, BOOL utf)
{
/* Update PRIV(update_classbits) when this function is changed. */
PCRE2_UCHAR t;
BOOL negated = (*data & XCL_NOT) != 0;
BOOL not_negated = (*data & XCL_NOT) == 0;
uint32_t type, max_index, min_index, value;
const uint8_t *next_char;
#if PCRE2_CODE_UNIT_WIDTH == 8
/* In 8 bit mode, this must always be TRUE. Help the compiler to know that. */
utf = TRUE;
#endif
/* Code points < 256 are matched against a bitmap, if one is present. If not,
we still carry on, because there may be ranges that start below 256 in the
additional data. */
/* Code points < 256 are matched against a bitmap, if one is present. */
if (c < 256)
if ((*data++ & XCL_MAP) != 0)
{
if ((*data & XCL_HASPROP) == 0)
{
if ((*data & XCL_MAP) == 0) return negated;
return (((uint8_t *)(data + 1))[c/8] & (1u << (c&7))) != 0;
}
if ((*data & XCL_MAP) != 0 &&
(((uint8_t *)(data + 1))[c/8] & (1u << (c&7))) != 0)
return !negated; /* char found */
if (c < 256)
return (((const uint8_t *)data)[c/8] & (1u << (c&7))) != 0;
/* Skip bitmap. */
data += 32 / sizeof(PCRE2_UCHAR);
}
/* First skip the bit map if present. Then match against the list of Unicode
properties or large chars or ranges that end with a large char. We won't ever
/* Match against the list of Unicode properties. We won't ever
encounter XCL_PROP or XCL_NOTPROP when UTF support is not compiled. */
if ((*data++ & XCL_MAP) != 0) data += 32 / sizeof(PCRE2_UCHAR);
while ((t = *data++) != XCL_END)
#ifdef SUPPORT_UNICODE
if (*data == XCL_PROP || *data == XCL_NOTPROP)
{
uint32_t x, y;
if (t == XCL_SINGLE)
{
#ifdef SUPPORT_UNICODE
if (utf)
{
GETCHARINC(x, data); /* macro generates multiple statements */
}
else
#endif
x = *data++;
if (c == x) return !negated;
}
else if (t == XCL_RANGE)
{
#ifdef SUPPORT_UNICODE
if (utf)
{
GETCHARINC(x, data); /* macro generates multiple statements */
GETCHARINC(y, data); /* macro generates multiple statements */
}
else
#endif
{
x = *data++;
y = *data++;
}
if (c >= x && c <= y) return !negated;
}
/* The UCD record is the same for all properties. */
const ucd_record *prop = GET_UCD(c);
#ifdef SUPPORT_UNICODE
else /* XCL_PROP & XCL_NOTPROP */
do
{
int chartype;
const ucd_record *prop = GET_UCD(c);
BOOL isprop = t == XCL_PROP;
BOOL isprop = (*data++) == XCL_PROP;
BOOL ok;
switch(*data)
{
case PT_ANY:
if (isprop) return !negated;
break;
case PT_LAMP:
chartype = prop->chartype;
if ((chartype == ucp_Lu || chartype == ucp_Ll ||
chartype == ucp_Lt) == isprop) return !negated;
chartype == ucp_Lt) == isprop) return not_negated;
break;
case PT_GC:
if ((data[1] == PRIV(ucp_gentype)[prop->chartype]) == isprop)
return !negated;
return not_negated;
break;
case PT_PC:
if ((data[1] == prop->chartype) == isprop) return !negated;
if ((data[1] == prop->chartype) == isprop) return not_negated;
break;
case PT_SC:
if ((data[1] == prop->script) == isprop) return !negated;
if ((data[1] == prop->script) == isprop) return not_negated;
break;
case PT_SCX:
ok = (data[1] == prop->script ||
MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), data[1]) != 0);
if (ok == isprop) return !negated;
if (ok == isprop) return not_negated;
break;
case PT_ALNUM:
chartype = prop->chartype;
if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
PRIV(ucp_gentype)[chartype] == ucp_N) == isprop)
return !negated;
return not_negated;
break;
/* Perl space used to exclude VT, but from Perl 5.18 it is included,
@@ -186,12 +147,12 @@ while ((t = *data++) != XCL_END)
{
HSPACE_CASES:
VSPACE_CASES:
if (isprop) return !negated;
if (isprop) return not_negated;
break;
default:
if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == isprop)
return !negated;
return not_negated;
break;
}
break;
@@ -201,7 +162,7 @@ while ((t = *data++) != XCL_END)
if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
PRIV(ucp_gentype)[chartype] == ucp_N ||
chartype == ucp_Mn || chartype == ucp_Pc) == isprop)
return !negated;
return not_negated;
break;
case PT_UCNC:
@@ -209,24 +170,24 @@ while ((t = *data++) != XCL_END)
{
if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
c == CHAR_GRAVE_ACCENT) == isprop)
return !negated;
return not_negated;
}
else
{
if ((c < 0xd800 || c > 0xdfff) == isprop)
return !negated;
return not_negated;
}
break;
case PT_BIDICL:
if ((UCD_BIDICLASS_PROP(prop) == data[1]) == isprop)
return !negated;
return not_negated;
break;
case PT_BOOL:
ok = MAPBIT(PRIV(ucd_boolprop_sets) +
UCD_BPROPS_PROP(prop), data[1]) != 0;
if (ok == isprop) return !negated;
if (ok == isprop) return not_negated;
break;
/* The following three properties can occur only in an XCLASS, as there
@@ -248,7 +209,7 @@ while ((t = *data++) != XCL_END)
(chartype == ucp_Cf &&
c != 0x061c && c != 0x180e && (c < 0x2066 || c > 0x2069))
)) == isprop)
return !negated;
return not_negated;
break;
/* Printable character: same as graphic, with the addition of Zs, i.e.
@@ -262,7 +223,7 @@ while ((t = *data++) != XCL_END)
(chartype == ucp_Cf &&
c != 0x061c && (c < 0x2066 || c > 0x2069))
)) == isprop)
return !negated;
return not_negated;
break;
/* Punctuation: all Unicode punctuation, plus ASCII characters that
@@ -273,7 +234,7 @@ while ((t = *data++) != XCL_END)
chartype = prop->chartype;
if ((PRIV(ucp_gentype)[chartype] == ucp_P ||
(c < 128 && PRIV(ucp_gentype)[chartype] == ucp_S)) == isprop)
return !negated;
return not_negated;
break;
/* Perl has two sets of hex digits */
@@ -285,24 +246,300 @@ while ((t = *data++) != XCL_END)
(c >= 0xff10 && c <= 0xff19) || /* Fullwidth digits */
(c >= 0xff21 && c <= 0xff26) || /* Fullwidth letters */
(c >= 0xff41 && c <= 0xff46)) == isprop)
return !negated;
return not_negated;
break;
/* This should never occur, but compilers may mutter if there is no
default. */
default:
PCRE2_DEBUG_UNREACHABLE();
return FALSE;
}
data += 2;
}
while (*data == XCL_PROP || *data == XCL_NOTPROP);
}
#else
(void)utf; /* Avoid compiler warning */
#endif /* SUPPORT_UNICODE */
/* Match against large chars or ranges that end with a large char. */
if (*data < XCL_LIST)
{
while ((t = *data++) != XCL_END)
{
uint32_t x, y;
#ifdef SUPPORT_UNICODE
if (utf)
{
GETCHARINC(x, data); /* macro generates multiple statements */
}
else
#endif
x = *data++;
if (t == XCL_SINGLE)
{
/* Since character ranges follow the properties, and they are
sorted, early return is possible for all characters <= x. */
if (c <= x) return (c == x) ? not_negated : !not_negated;
continue;
}
PCRE2_ASSERT(t == XCL_RANGE);
#ifdef SUPPORT_UNICODE
if (utf)
{
GETCHARINC(y, data); /* macro generates multiple statements */
}
else
#endif
y = *data++;
/* Since character ranges follow the properties, and they are
sorted, early return is possible for all characters <= y. */
if (c <= y) return (c >= x) ? not_negated : !not_negated;
}
return !not_negated; /* char did not match */
}
return negated; /* char did not match */
#if PCRE2_CODE_UNIT_WIDTH == 8
type = (uint32_t)(data[0] << 8) | data[1];
data += 2;
#else
type = data[0];
data++;
#endif /* CODE_UNIT_WIDTH */
/* Align characters. */
next_char = char_lists_end - (GET(data, 0) << 1);
type &= XCL_TYPE_MASK;
/* Alignment check. */
PCRE2_ASSERT(((uintptr_t)next_char & 0x1) == 0);
if (c >= XCL_CHAR_LIST_HIGH_16_START)
{
max_index = type & XCL_ITEM_COUNT_MASK;
if (max_index == XCL_ITEM_COUNT_MASK)
{
max_index = *(const uint16_t*)next_char;
PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK);
next_char += 2;
}
next_char += max_index << 1;
type >>= XCL_TYPE_BIT_LEN;
}
if (c < XCL_CHAR_LIST_LOW_32_START)
{
max_index = type & XCL_ITEM_COUNT_MASK;
c = (uint16_t)((c << XCL_CHAR_SHIFT) | XCL_CHAR_END);
if (max_index == XCL_ITEM_COUNT_MASK)
{
max_index = *(const uint16_t*)next_char;
PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK);
next_char += 2;
}
if (max_index == 0 || c < *(const uint16_t*)next_char)
return ((type & XCL_BEGIN_WITH_RANGE) != 0) == not_negated;
min_index = 0;
value = ((const uint16_t*)next_char)[--max_index];
if (c >= value)
return (value == c || (value & XCL_CHAR_END) == 0) == not_negated;
max_index--;
/* Binary search of a range. */
while (TRUE)
{
uint32_t mid_index = (min_index + max_index) >> 1;
value = ((const uint16_t*)next_char)[mid_index];
if (c < value)
max_index = mid_index - 1;
else if (((const uint16_t*)next_char)[mid_index + 1] <= c)
min_index = mid_index + 1;
else
return (value == c || (value & XCL_CHAR_END) == 0) == not_negated;
}
}
/* Skip the 16 bit ranges. */
max_index = type & XCL_ITEM_COUNT_MASK;
if (max_index == XCL_ITEM_COUNT_MASK)
{
max_index = *(const uint16_t*)next_char;
PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK);
next_char += 2;
}
next_char += (max_index << 1);
type >>= XCL_TYPE_BIT_LEN;
/* Alignment check. */
PCRE2_ASSERT(((uintptr_t)next_char & 0x3) == 0);
max_index = type & XCL_ITEM_COUNT_MASK;
#if PCRE2_CODE_UNIT_WIDTH == 32
if (c >= XCL_CHAR_LIST_HIGH_32_START)
{
if (max_index == XCL_ITEM_COUNT_MASK)
{
max_index = *(const uint32_t*)next_char;
PCRE2_ASSERT(max_index >= XCL_ITEM_COUNT_MASK);
next_char += 4;
}
next_char += max_index << 2;
type >>= XCL_TYPE_BIT_LEN;
max_index = type & XCL_ITEM_COUNT_MASK;
}
#endif
c = (uint32_t)((c << XCL_CHAR_SHIFT) | XCL_CHAR_END);
if (max_index == XCL_ITEM_COUNT_MASK)
{
max_index = *(const uint32_t*)next_char;
next_char += 4;
}
if (max_index == 0 || c < *(const uint32_t*)next_char)
return ((type & XCL_BEGIN_WITH_RANGE) != 0) == not_negated;
min_index = 0;
value = ((const uint32_t*)next_char)[--max_index];
if (c >= value)
return (value == c || (value & XCL_CHAR_END) == 0) == not_negated;
max_index--;
/* Binary search of a range. */
while (TRUE)
{
uint32_t mid_index = (min_index + max_index) >> 1;
value = ((const uint32_t*)next_char)[mid_index];
if (c < value)
max_index = mid_index - 1;
else if (((const uint32_t*)next_char)[mid_index + 1] <= c)
min_index = mid_index + 1;
else
return (value == c || (value & XCL_CHAR_END) == 0) == not_negated;
}
}
/*************************************************
* Match character against an ECLASS *
*************************************************/
/* This function is called to match a character against an extended class
used for describing characters using boolean operations on sets.
Arguments:
c the character
data_start points to the start of the ECLASS data
data_end points one-past-the-last of the ECLASS data
utf TRUE if in UTF mode
Returns: TRUE if character matches, else FALSE
*/
BOOL
PRIV(eclass)(uint32_t c, PCRE2_SPTR data_start, PCRE2_SPTR data_end,
const uint8_t *char_lists_end, BOOL utf)
{
PCRE2_SPTR ptr = data_start;
PCRE2_UCHAR flags;
uint32_t stack = 0;
int stack_depth = 0;
PCRE2_ASSERT(data_start < data_end);
flags = *ptr++;
PCRE2_ASSERT((flags & ECL_MAP) == 0 ||
(data_end - ptr) >= 32 / (int)sizeof(PCRE2_UCHAR));
/* Code points < 256 are matched against a bitmap, if one is present.
Otherwise all codepoints are checked later. */
if ((flags & ECL_MAP) != 0)
{
if (c < 256)
return (((const uint8_t *)ptr)[c/8] & (1u << (c&7))) != 0;
/* Skip the bitmap. */
ptr += 32 / sizeof(PCRE2_UCHAR);
}
/* Do a little loop, until we reach the end of the ECLASS. */
while (ptr < data_end)
{
switch (*ptr)
{
case ECL_AND:
++ptr;
stack = (stack >> 1) & (stack | ~(uint32_t)1u);
PCRE2_ASSERT(stack_depth >= 2);
--stack_depth;
break;
case ECL_OR:
++ptr;
stack = (stack >> 1) | (stack & (uint32_t)1u);
PCRE2_ASSERT(stack_depth >= 2);
--stack_depth;
break;
case ECL_XOR:
++ptr;
stack = (stack >> 1) ^ (stack & (uint32_t)1u);
PCRE2_ASSERT(stack_depth >= 2);
--stack_depth;
break;
case ECL_NOT:
++ptr;
stack ^= (uint32_t)1u;
PCRE2_ASSERT(stack_depth >= 1);
break;
case ECL_XCLASS:
{
uint32_t matched = PRIV(xclass)(c, ptr + 1 + LINK_SIZE, char_lists_end, utf);
ptr += GET(ptr, 1);
stack = (stack << 1) | matched;
++stack_depth;
break;
}
/* This should never occur, but compilers may mutter if there is no
default. */
default:
PCRE2_DEBUG_UNREACHABLE();
return FALSE;
}
}
PCRE2_ASSERT(stack_depth == 1);
(void)stack_depth; /* Ignore unused variable, if assertions are disabled. */
/* The final bit left on the stack now holds the match result. */
return (stack & 1u) != 0;
}
/* End of pcre2_xclass.c */