123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "pcre_internal.h"
- BOOL
- PRIV(xclass)(pcre_uint32 c, const pcre_uchar *data, BOOL utf)
- {
- pcre_uchar t;
- BOOL negated = (*data & XCL_NOT) != 0;
- (void)utf;
- #ifdef COMPILE_PCRE8
- utf = TRUE;
- #endif
- if (c < 256)
- {
- if ((*data & XCL_HASPROP) == 0)
- {
- if ((*data & XCL_MAP) == 0) return negated;
- return (((pcre_uint8 *)(data + 1))[c/8] & (1 << (c&7))) != 0;
- }
- if ((*data & XCL_MAP) != 0 &&
- (((pcre_uint8 *)(data + 1))[c/8] & (1 << (c&7))) != 0)
- return !negated;
- }
- if ((*data++ & XCL_MAP) != 0) data += 32 / sizeof(pcre_uchar);
- while ((t = *data++) != XCL_END)
- {
- pcre_uint32 x, y;
- if (t == XCL_SINGLE)
- {
- #ifdef SUPPORT_UTF
- if (utf)
- {
- GETCHARINC(x, data);
- }
- else
- #endif
- x = *data++;
- if (c == x) return !negated;
- }
- else if (t == XCL_RANGE)
- {
- #ifdef SUPPORT_UTF
- if (utf)
- {
- GETCHARINC(x, data);
- GETCHARINC(y, data);
- }
- else
- #endif
- {
- x = *data++;
- y = *data++;
- }
- if (c >= x && c <= y) return !negated;
- }
- #ifdef SUPPORT_UCP
- else
- {
- const ucd_record *prop = GET_UCD(c);
- BOOL isprop = t == XCL_PROP;
- switch(*data)
- {
- case PT_ANY:
- if (isprop) return !negated;
- break;
- case PT_LAMP:
- if ((prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
- prop->chartype == ucp_Lt) == isprop) return !negated;
- break;
- case PT_GC:
- if ((data[1] == PRIV(ucp_gentype)[prop->chartype]) == isprop)
- return !negated;
- break;
- case PT_PC:
- if ((data[1] == prop->chartype) == isprop) return !negated;
- break;
- case PT_SC:
- if ((data[1] == prop->script) == isprop) return !negated;
- break;
- case PT_ALNUM:
- if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
- PRIV(ucp_gentype)[prop->chartype] == ucp_N) == isprop)
- return !negated;
- break;
-
- case PT_SPACE:
- case PT_PXSPACE:
- switch(c)
- {
- HSPACE_CASES:
- VSPACE_CASES:
- if (isprop) return !negated;
- break;
- default:
- if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == isprop)
- return !negated;
- break;
- }
- break;
- case PT_WORD:
- if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
- PRIV(ucp_gentype)[prop->chartype] == ucp_N || c == CHAR_UNDERSCORE)
- == isprop)
- return !negated;
- break;
- case PT_UCNC:
- if (c < 0xa0)
- {
- if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
- c == CHAR_GRAVE_ACCENT) == isprop)
- return !negated;
- }
- else
- {
- if ((c < 0xd800 || c > 0xdfff) == isprop)
- return !negated;
- }
- break;
-
-
- case PT_PXGRAPH:
- if ((PRIV(ucp_gentype)[prop->chartype] != ucp_Z &&
- (PRIV(ucp_gentype)[prop->chartype] != ucp_C ||
- (prop->chartype == ucp_Cf &&
- c != 0x061c && c != 0x180e && (c < 0x2066 || c > 0x2069))
- )) == isprop)
- return !negated;
- break;
-
- case PT_PXPRINT:
- if ((prop->chartype != ucp_Zl &&
- prop->chartype != ucp_Zp &&
- (PRIV(ucp_gentype)[prop->chartype] != ucp_C ||
- (prop->chartype == ucp_Cf &&
- c != 0x061c && (c < 0x2066 || c > 0x2069))
- )) == isprop)
- return !negated;
- break;
-
- case PT_PXPUNCT:
- if ((PRIV(ucp_gentype)[prop->chartype] == ucp_P ||
- (c < 128 && PRIV(ucp_gentype)[prop->chartype] == ucp_S)) == isprop)
- return !negated;
- break;
-
- default:
- return FALSE;
- }
- data += 2;
- }
- #endif
- }
- return negated;
- }
|