Path: blob/master/thirdparty/pcre2/src/pcre2_tables.c
9898 views
/*************************************************1* Perl-Compatible Regular Expressions *2*************************************************/34/* PCRE is a library of functions to support regular expressions whose syntax5and semantics are as close as possible to those of the Perl 5 language.67Written by Philip Hazel8Original API code Copyright (c) 1997-2012 University of Cambridge9New API code Copyright (c) 2016-2024 University of Cambridge1011-----------------------------------------------------------------------------12Redistribution and use in source and binary forms, with or without13modification, are permitted provided that the following conditions are met:1415* Redistributions of source code must retain the above copyright notice,16this list of conditions and the following disclaimer.1718* Redistributions in binary form must reproduce the above copyright19notice, this list of conditions and the following disclaimer in the20documentation and/or other materials provided with the distribution.2122* Neither the name of the University of Cambridge nor the names of its23contributors may be used to endorse or promote products derived from24this software without specific prior written permission.2526THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE36POSSIBILITY OF SUCH DAMAGE.37-----------------------------------------------------------------------------38*/3940/* This module contains some fixed tables that are used by more than one of the41PCRE2 code modules. The tables are also #included by the pcre2test program,42which uses macros to change their names from _pcre2_xxx to xxxx, thereby43avoiding name clashes with the library. In this case, PCRE2_PCRE2TEST is44defined. */4546#ifndef PCRE2_PCRE2TEST /* We're compiling the library */47#ifdef HAVE_CONFIG_H48#include "config.h"49#endif50#include "pcre2_internal.h"51#endif /* PCRE2_PCRE2TEST */5253/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that54the definition is next to the definition of the opcodes in pcre2_internal.h.55This is mode-dependent, so it is skipped when this file is included by56pcre2test. */5758#ifndef PCRE2_PCRE2TEST59const uint8_t PRIV(OP_lengths)[] = { OP_LENGTHS };60#endif6162/* Tables of horizontal and vertical whitespace characters, suitable for63adding to classes. */6465const uint32_t PRIV(hspace_list)[] = { HSPACE_LIST };66const uint32_t PRIV(vspace_list)[] = { VSPACE_LIST };6768/* These tables are the pairs of delimiters that are valid for callout string69arguments. For each starting delimiter there must be a matching ending70delimiter, which in fact is different only for bracket-like delimiters. */7172const uint32_t PRIV(callout_start_delims)[] = {73CHAR_GRAVE_ACCENT, CHAR_APOSTROPHE, CHAR_QUOTATION_MARK,74CHAR_CIRCUMFLEX_ACCENT, CHAR_PERCENT_SIGN, CHAR_NUMBER_SIGN,75CHAR_DOLLAR_SIGN, CHAR_LEFT_CURLY_BRACKET, 0 };7677const uint32_t PRIV(callout_end_delims[]) = {78CHAR_GRAVE_ACCENT, CHAR_APOSTROPHE, CHAR_QUOTATION_MARK,79CHAR_CIRCUMFLEX_ACCENT, CHAR_PERCENT_SIGN, CHAR_NUMBER_SIGN,80CHAR_DOLLAR_SIGN, CHAR_RIGHT_CURLY_BRACKET, 0 };818283/*************************************************84* Tables for UTF-8 support *85*************************************************/8687/* These tables are required by pcre2test in 16- or 32-bit mode, as well88as for the library in 8-bit mode, because pcre2test uses UTF-8 internally for89handling wide characters. */9091#if defined PCRE2_PCRE2TEST || \92(defined SUPPORT_UNICODE && \93defined PCRE2_CODE_UNIT_WIDTH && \94PCRE2_CODE_UNIT_WIDTH == 8)9596/* These are the breakpoints for different numbers of bytes in a UTF-897character. */9899const int PRIV(utf8_table1)[] =100{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff};101102const int PRIV(utf8_table1_size) = sizeof(PRIV(utf8_table1)) / sizeof(int);103104/* These are the indicator bits and the mask for the data bits to set in the105first byte of a character, indexed by the number of additional bytes. */106107const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc};108const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};109110/* Table of the number of extra bytes, indexed by the first byte masked with1110x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */112113const uint8_t PRIV(utf8_table4)[] = {1141,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1151,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1162,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1173,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };118119#endif /* UTF-8 support needed */120121/* Tables concerned with Unicode properties are relevant only when Unicode122support is enabled. See also the pcre2_ucptables.c file, which is generated by123a Python script from Unicode data files. */124125#ifdef SUPPORT_UNICODE126127/* Table to translate from particular type value to the general value. */128129const uint32_t PRIV(ucp_gentype)[] = {130ucp_C, ucp_C, ucp_C, ucp_C, ucp_C, /* Cc, Cf, Cn, Co, Cs */131ucp_L, ucp_L, ucp_L, ucp_L, ucp_L, /* Ll, Lu, Lm, Lo, Lt */132ucp_M, ucp_M, ucp_M, /* Mc, Me, Mn */133ucp_N, ucp_N, ucp_N, /* Nd, Nl, No */134ucp_P, ucp_P, ucp_P, ucp_P, ucp_P, /* Pc, Pd, Pe, Pf, Pi */135ucp_P, ucp_P, /* Ps, Po */136ucp_S, ucp_S, ucp_S, ucp_S, /* Sc, Sk, Sm, So */137ucp_Z, ucp_Z, ucp_Z /* Zl, Zp, Zs */138};139140/* This table encodes the rules for finding the end of an extended grapheme141cluster. Every code point has a grapheme break property which is one of the142ucp_gbXX values defined in pcre2_ucp.h. These changed between Unicode versions14310 and 11. The 2-dimensional table is indexed by the properties of two adjacent144code points. The left property selects a word from the table, and the right145property selects a bit from that word like this:146147PRIV(ucp_gbtable)[left-property] & (1u << right-property)148149The value is non-zero if a grapheme break is NOT permitted between the relevant150two code points. The breaking rules are as follows:1511521. Break at the start and end of text (pretty obviously).1531542. Do not break between a CR and LF; otherwise, break before and after155controls.1561573. Do not break Hangul syllable sequences, the rules for which are:158159L may be followed by L, V, LV or LVT160LV or V may be followed by V or T161LVT or T may be followed by T1621634. Do not break before extending characters or zero-width-joiner (ZWJ).164165The following rules are only for extended grapheme clusters (but that's what we166are implementing).1671685. Do not break before SpacingMarks.1691706. Do not break after Prepend characters.1711727. Do not break within emoji modifier sequences or emoji zwj sequences. That173is, do not break between characters with the Extended_Pictographic property174if a ZWJ intervenes. Extend characters are allowed between the characters;175this cannot be represented in this table, the code has to deal with it.1761778. Do not break within emoji flag sequences. That is, do not break between178regional indicator (RI) symbols if there are an odd number of RI characters179before the break point. This table encodes "join RI characters"; the code180has to deal with checking for previous adjoining RIs.1811829. Otherwise, break everywhere.183*/184185#define ESZ (1<<ucp_gbExtend)|(1<<ucp_gbSpacingMark)|(1<<ucp_gbZWJ)186187const uint32_t PRIV(ucp_gbtable)[] = {188(1u<<ucp_gbLF), /* 0 CR */1890, /* 1 LF */1900, /* 2 Control */191ESZ, /* 3 Extend */192ESZ|(1u<<ucp_gbPrepend)| /* 4 Prepend */193(1u<<ucp_gbL)|(1u<<ucp_gbV)|(1u<<ucp_gbT)|194(1u<<ucp_gbLV)|(1u<<ucp_gbLVT)|(1u<<ucp_gbOther)|195(1u<<ucp_gbRegional_Indicator),196ESZ, /* 5 SpacingMark */197ESZ|(1u<<ucp_gbL)|(1u<<ucp_gbV)|(1u<<ucp_gbLV)| /* 6 L */198(1u<<ucp_gbLVT),199ESZ|(1u<<ucp_gbV)|(1u<<ucp_gbT), /* 7 V */200ESZ|(1u<<ucp_gbT), /* 8 T */201ESZ|(1u<<ucp_gbV)|(1u<<ucp_gbT), /* 9 LV */202ESZ|(1u<<ucp_gbT), /* 10 LVT */203(1u<<ucp_gbRegional_Indicator), /* 11 Regional Indicator */204ESZ, /* 12 Other */205ESZ|(1u<<ucp_gbExtended_Pictographic), /* 13 ZWJ */206ESZ /* 14 Extended Pictographic */207};208209#undef ESZ210211#ifdef SUPPORT_JIT212/* This table reverses PRIV(ucp_gentype). We can save the cost213of a memory load. */214215const int PRIV(ucp_typerange)[] = {216ucp_Cc, ucp_Cs,217ucp_Ll, ucp_Lu,218ucp_Mc, ucp_Mn,219ucp_Nd, ucp_No,220ucp_Pc, ucp_Ps,221ucp_Sc, ucp_So,222ucp_Zl, ucp_Zs,223};224#endif /* SUPPORT_JIT */225226/* Finally, include the tables that are auto-generated from the Unicode data227files. */228229#include "pcre2_ucptables.c"230231#endif /* SUPPORT_UNICODE */232233/* End of pcre2_tables.c */234235236