1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
5 /* PCRE2 is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
8 Written by Philip Hazel
9 Original API code Copyright (c) 1997-2012 University of Cambridge
10 New API code Copyright (c) 2016-2018 University of Cambridge
12 -----------------------------------------------------------------------------
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
19 * Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
23 * Neither the name of the University of Cambridge nor the names of its
24 contributors may be used to endorse or promote products derived from
25 this software without specific prior written permission.
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 -----------------------------------------------------------------------------
41 #ifndef PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
42 #define PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
44 /* We do not support both EBCDIC and Unicode at the same time. The "configure"
45 script prevents both being selected, but not everybody uses "configure". EBCDIC
46 is only supported for the 8-bit library, but the check for this has to be later
47 in this file, because the first part is not width-dependent, and is included by
48 pcre2test.c with CODE_UNIT_WIDTH == 0. */
50 #if defined EBCDIC && defined SUPPORT_UNICODE
51 #error The use of both EBCDIC and SUPPORT_UNICODE is not supported.
54 /* Standard C headers */
63 /* Macros to make boolean values more obvious. The #ifndef is to pacify
64 compiler warnings in environments where these macros are defined elsewhere.
65 Unfortunately, there is no way to do the same for the typedef. */
73 /* Valgrind (memcheck) support */
75 #ifdef SUPPORT_VALGRIND
76 #include <valgrind/memcheck.h>
79 /* Older versions of MSVC lack snprintf(). This define allows for
80 warning/error-free compilation and testing with MSVC compilers back to at least
81 MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */
83 #if defined(_MSC_VER) && (_MSC_VER < 1900)
84 #define snprintf _snprintf
87 /* When compiling a DLL for Windows, the exported symbols have to be declared
88 using some MS magic. I found some useful information on this web page:
89 http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
90 information there, using __declspec(dllexport) without "extern" we have a
91 definition; with "extern" we have a declaration. The settings here override the
92 setting in pcre2.h (which is included below); it defines only PCRE2_EXP_DECL,
93 which is all that is needed for applications (they just import the symbols). We
96 PCRE2_EXP_DECL for declarations
97 PCRE2_EXP_DEFN for definitions
99 The reason for wrapping this in #ifndef PCRE2_EXP_DECL is so that pcre2test,
100 which is an application, but needs to import this file in order to "peek" at
101 internals, can #include pcre2.h first to get an application's-eye view.
103 In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
104 special-purpose environments) might want to stick other stuff in front of
105 exported symbols. That's why, in the non-Windows case, we set PCRE2_EXP_DEFN
106 only if it is not already set. */
108 #ifndef PCRE2_EXP_DECL
110 # ifndef PCRE2_STATIC
111 # define PCRE2_EXP_DECL extern __declspec(dllexport)
112 # define PCRE2_EXP_DEFN __declspec(dllexport)
114 # define PCRE2_EXP_DECL extern
115 # define PCRE2_EXP_DEFN
119 # define PCRE2_EXP_DECL extern "C"
121 # define PCRE2_EXP_DECL extern
123 # ifndef PCRE2_EXP_DEFN
124 # define PCRE2_EXP_DEFN PCRE2_EXP_DECL
129 /* Include the public PCRE2 header and the definitions of UCP character
130 property values. This must follow the setting of PCRE2_EXP_DECL above. */
133 #include "pcre2_ucp.h"
135 /* When PCRE2 is compiled as a C++ library, the subject pointer can be replaced
136 with a custom type. This makes it possible, for example, to allow pcre2_match()
137 to process subject strings that are discontinuous by using a smart pointer
138 class. It must always be possible to inspect all of the subject string in
139 pcre2_match() because of the way it backtracks. */
141 /* WARNING: This is as yet untested for PCRE2. */
143 #ifdef CUSTOM_SUBJECT_PTR
145 #define PCRE2_SPTR CUSTOM_SUBJECT_PTR
148 /* When checking for integer overflow in pcre2_compile(), we need to handle
149 large integers. If a 64-bit integer type is available, we can use that.
150 Otherwise we have to cast to double, which of course requires floating point
151 arithmetic. Handle this by defining a macro for the appropriate type. If
152 stdint.h is available, include it; it may define INT64_MAX. Systems that do not
153 have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set
156 #if defined HAVE_STDINT_H
158 #elif defined HAVE_INTTYPES_H
159 #include <inttypes.h>
162 #if defined INT64_MAX || defined int64_t
163 #define INT64_OR_DOUBLE int64_t
165 #define INT64_OR_DOUBLE double
168 /* External (in the C sense) functions and tables that are private to the
169 libraries are always referenced using the PRIV macro. This makes it possible
170 for pcre2test.c to include some of the source files from the libraries using a
171 different PRIV definition to avoid name clashes. It also makes it clear in the
172 code that a non-static object is being referenced. */
175 #define PRIV(name) _pcre2_##name
178 /* When compiling for use with the Virtual Pascal compiler, these functions
179 need to have their names changed. PCRE2 must be compiled with the -DVPCOMPAT
180 option on the command line. */
183 #define strlen(s) _strlen(s)
184 #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
185 #define memcmp(s,c,n) _memcmp(s,c,n)
186 #define memcpy(d,s,n) _memcpy(d,s,n)
187 #define memmove(d,s,n) _memmove(d,s,n)
188 #define memset(s,c,n) _memset(s,c,n)
191 /* Otherwise, to cope with SunOS4 and other systems that lack memmove(), define
192 a macro that calls an emulating function. */
195 #undef memmove /* Some systems may have a macro */
196 #define memmove(a, b, c) PRIV(memmove)(a, b, c)
197 #endif /* not HAVE_MEMMOVE */
198 #endif /* not VPCOMPAT */
200 /* This is an unsigned int value that no UTF character can ever have, as
201 Unicode doesn't go beyond 0x0010ffff. */
203 #define NOTACHAR 0xffffffff
205 /* This is the largest valid UTF/Unicode code point. */
207 #define MAX_UTF_CODE_POINT 0x10ffff
209 /* Compile-time positive error numbers (all except UTF errors, which are
210 negative) start at this value. It should probably never be changed, in case
211 some application is checking for specific numbers. There is a copy of this
212 #define in pcre2posix.c (which now no longer includes this file). Ideally, a
213 way of having a single definition should be found, but as the number is
214 unlikely to change, this is not a pressing issue. The original reason for
215 having a base other than 0 was to keep the absolute values of compile-time and
216 run-time error numbers numerically different, but in the event the code does
219 #define COMPILE_ERROR_BASE 100
221 /* The initial frames vector for remembering backtracking points in
222 pcre2_match() is allocated on the system stack, of this size (bytes). The size
223 must be a multiple of sizeof(PCRE2_SPTR) in all environments, so making it a
224 multiple of 8 is best. Typical frame sizes are a few hundred bytes (it depends
225 on the number of capturing parentheses) so 20KiB handles quite a few frames. A
226 larger vector on the heap is obtained for patterns that need more frames. The
227 maximum size of this can be limited. */
229 #define START_FRAMES_SIZE 20480
231 /* Similarly, for DFA matching, an initial internal workspace vector is
232 allocated on the stack. */
234 #define DFA_START_RWS_SIZE 30720
236 /* Define the default BSR convention. */
239 #define BSR_DEFAULT PCRE2_BSR_ANYCRLF
241 #define BSR_DEFAULT PCRE2_BSR_UNICODE
245 /* ---------------- Basic UTF-8 macros ---------------- */
247 /* These UTF-8 macros are always defined because they are used in pcre2test for
248 handling wide characters in 16-bit and 32-bit modes, even if an 8-bit library
251 /* Tests whether a UTF-8 code point needs extra bytes to decode. */
253 #define HASUTF8EXTRALEN(c) ((c) >= 0xc0)
255 /* The following macros were originally written in the form of loops that used
256 data from the tables whose names start with PRIV(utf8_table). They were
257 rewritten by a user so as not to use loops, because in some environments this
258 gives a significant performance advantage, and it seems never to do any harm.
261 /* Base macro to pick up the remaining bytes of a UTF-8 character, not
262 advancing the pointer. */
264 #define GETUTF8(c, eptr) \
266 if ((c & 0x20u) == 0) \
267 c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
268 else if ((c & 0x10u) == 0) \
269 c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
270 else if ((c & 0x08u) == 0) \
271 c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
272 ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
273 else if ((c & 0x04u) == 0) \
274 c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
275 ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
278 c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
279 ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
280 ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
283 /* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
286 #define GETUTF8INC(c, eptr) \
288 if ((c & 0x20u) == 0) \
289 c = ((c & 0x1fu) << 6) | (*eptr++ & 0x3fu); \
290 else if ((c & 0x10u) == 0) \
292 c = ((c & 0x0fu) << 12) | ((*eptr & 0x3fu) << 6) | (eptr[1] & 0x3fu); \
295 else if ((c & 0x08u) == 0) \
297 c = ((c & 0x07u) << 18) | ((*eptr & 0x3fu) << 12) | \
298 ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
301 else if ((c & 0x04u) == 0) \
303 c = ((c & 0x03u) << 24) | ((*eptr & 0x3fu) << 18) | \
304 ((eptr[1] & 0x3fu) << 12) | ((eptr[2] & 0x3fu) << 6) | \
310 c = ((c & 0x01u) << 30) | ((*eptr & 0x3fu) << 24) | \
311 ((eptr[1] & 0x3fu) << 18) | ((eptr[2] & 0x3fu) << 12) | \
312 ((eptr[3] & 0x3fu) << 6) | (eptr[4] & 0x3fu); \
317 /* Base macro to pick up the remaining bytes of a UTF-8 character, not
318 advancing the pointer, incrementing the length. */
320 #define GETUTF8LEN(c, eptr, len) \
322 if ((c & 0x20u) == 0) \
324 c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
327 else if ((c & 0x10u) == 0) \
329 c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
332 else if ((c & 0x08u) == 0) \
334 c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
335 ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
338 else if ((c & 0x04u) == 0) \
340 c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
341 ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
347 c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
348 ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
349 ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
354 /* --------------- Whitespace macros ---------------- */
356 /* Tests for Unicode horizontal and vertical whitespace characters must check a
357 number of different values. Using a switch statement for this generates the
358 fastest code (no loop, no memory access), and there are several places in the
359 interpreter code where this happens. In order to ensure that all the case lists
360 remain in step, we use macros so that there is only one place where the lists
363 These values are also required as lists in pcre2_compile.c when processing \h,
364 \H, \v and \V in a character class. The lists are defined in pcre2_tables.c,
365 but macros that define the values are here so that all the definitions are
366 together. The lists must be in ascending character order, terminated by
367 NOTACHAR (which is 0xffffffff).
369 Any changes should ensure that the various macros are kept in step with each
370 other. NOTE: The values also appear in pcre2_jit_compile.c. */
372 /* -------------- ASCII/Unicode environments -------------- */
376 /* Character U+180E (Mongolian Vowel Separator) is not included in the list of
377 spaces in the Unicode file PropList.txt, and Perl does not recognize it as a
378 space. However, in many other sources it is listed as a space and has been in
379 PCRE (both APIs) for a long time. */
381 #define HSPACE_LIST \
382 CHAR_HT, CHAR_SPACE, CHAR_NBSP, \
383 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \
384 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \
387 #define HSPACE_MULTIBYTE_CASES \
388 case 0x1680: /* OGHAM SPACE MARK */ \
389 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \
390 case 0x2000: /* EN QUAD */ \
391 case 0x2001: /* EM QUAD */ \
392 case 0x2002: /* EN SPACE */ \
393 case 0x2003: /* EM SPACE */ \
394 case 0x2004: /* THREE-PER-EM SPACE */ \
395 case 0x2005: /* FOUR-PER-EM SPACE */ \
396 case 0x2006: /* SIX-PER-EM SPACE */ \
397 case 0x2007: /* FIGURE SPACE */ \
398 case 0x2008: /* PUNCTUATION SPACE */ \
399 case 0x2009: /* THIN SPACE */ \
400 case 0x200A: /* HAIR SPACE */ \
401 case 0x202f: /* NARROW NO-BREAK SPACE */ \
402 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \
403 case 0x3000 /* IDEOGRAPHIC SPACE */
405 #define HSPACE_BYTE_CASES \
410 #define HSPACE_CASES \
412 HSPACE_MULTIBYTE_CASES
414 #define VSPACE_LIST \
415 CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR
417 #define VSPACE_MULTIBYTE_CASES \
418 case 0x2028: /* LINE SEPARATOR */ \
419 case 0x2029 /* PARAGRAPH SEPARATOR */
421 #define VSPACE_BYTE_CASES \
428 #define VSPACE_CASES \
430 VSPACE_MULTIBYTE_CASES
432 /* -------------- EBCDIC environments -------------- */
435 #define HSPACE_LIST CHAR_HT, CHAR_SPACE, CHAR_NBSP, NOTACHAR
437 #define HSPACE_BYTE_CASES \
442 #define HSPACE_CASES HSPACE_BYTE_CASES
445 #define VSPACE_LIST \
446 CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR
448 #define VSPACE_LIST \
449 CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR
452 #define VSPACE_BYTE_CASES \
459 #define VSPACE_CASES VSPACE_BYTE_CASES
462 /* -------------- End of whitespace macros -------------- */
465 /* PCRE2 is able to support several different kinds of newline (CR, LF, CRLF,
466 "any" and "anycrlf" at present). The following macros are used to package up
467 testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
468 modules to indicate in which datablock the parameters exist, and what the
469 start/end of string field names are. */
471 #define NLTYPE_FIXED 0 /* Newline is a fixed length string */
472 #define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
473 #define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
475 /* This macro checks for a newline at the given position */
477 #define IS_NEWLINE(p) \
478 ((NLBLOCK->nltype != NLTYPE_FIXED)? \
479 ((p) < NLBLOCK->PSEND && \
480 PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \
481 &(NLBLOCK->nllen), utf)) \
483 ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
484 UCHAR21TEST(p) == NLBLOCK->nl[0] && \
485 (NLBLOCK->nllen == 1 || UCHAR21TEST(p+1) == NLBLOCK->nl[1]) \
489 /* This macro checks for a newline immediately preceding the given position */
491 #define WAS_NEWLINE(p) \
492 ((NLBLOCK->nltype != NLTYPE_FIXED)? \
493 ((p) > NLBLOCK->PSSTART && \
494 PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
495 &(NLBLOCK->nllen), utf)) \
497 ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
498 UCHAR21TEST(p - NLBLOCK->nllen) == NLBLOCK->nl[0] && \
499 (NLBLOCK->nllen == 1 || UCHAR21TEST(p - NLBLOCK->nllen + 1) == NLBLOCK->nl[1]) \
503 /* Private flags containing information about the compiled pattern. The first
504 three must not be changed, because whichever is set is actually the number of
505 bytes in a code unit in that mode. */
507 #define PCRE2_MODE8 0x00000001 /* compiled in 8 bit mode */
508 #define PCRE2_MODE16 0x00000002 /* compiled in 16 bit mode */
509 #define PCRE2_MODE32 0x00000004 /* compiled in 32 bit mode */
510 #define PCRE2_FIRSTSET 0x00000010 /* first_code unit is set */
511 #define PCRE2_FIRSTCASELESS 0x00000020 /* caseless first code unit */
512 #define PCRE2_FIRSTMAPSET 0x00000040 /* bitmap of first code units is set */
513 #define PCRE2_LASTSET 0x00000080 /* last code unit is set */
514 #define PCRE2_LASTCASELESS 0x00000100 /* caseless last code unit */
515 #define PCRE2_STARTLINE 0x00000200 /* start after \n for multiline */
516 #define PCRE2_JCHANGED 0x00000400 /* j option used in pattern */
517 #define PCRE2_HASCRORLF 0x00000800 /* explicit \r or \n in pattern */
518 #define PCRE2_HASTHEN 0x00001000 /* pattern contains (*THEN) */
519 #define PCRE2_MATCH_EMPTY 0x00002000 /* pattern can match empty string */
520 #define PCRE2_BSR_SET 0x00004000 /* BSR was set in the pattern */
521 #define PCRE2_NL_SET 0x00008000 /* newline was set in the pattern */
522 #define PCRE2_NOTEMPTY_SET 0x00010000 /* (*NOTEMPTY) used ) keep */
523 #define PCRE2_NE_ATST_SET 0x00020000 /* (*NOTEMPTY_ATSTART) used) together */
524 #define PCRE2_DEREF_TABLES 0x00040000 /* release character tables */
525 #define PCRE2_NOJIT 0x00080000 /* (*NOJIT) used */
526 #define PCRE2_HASBKPORX 0x00100000 /* contains \P, \p, or \X */
527 #define PCRE2_DUPCAPUSED 0x00200000 /* contains (?| */
528 #define PCRE2_HASBKC 0x00400000 /* contains \C */
530 #define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32)
532 /* Values for the matchedby field in a match data block. */
534 enum { PCRE2_MATCHEDBY_INTERPRETER, /* pcre2_match() */
535 PCRE2_MATCHEDBY_DFA_INTERPRETER, /* pcre2_dfa_match() */
536 PCRE2_MATCHEDBY_JIT }; /* pcre2_jit_match() */
538 /* Magic number to provide a small check against being handed junk. */
540 #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
542 /* The maximum remaining length of subject we are prepared to search for a
543 req_unit match. In 8-bit mode, memchr() is used and is much faster than the
544 search loop that has to be used in 16-bit and 32-bit modes. */
546 #if PCRE2_CODE_UNIT_WIDTH == 8
547 #define REQ_CU_MAX 2000
549 #define REQ_CU_MAX 1000
552 /* Offsets for the bitmap tables in the cbits set of tables. Each table
553 contains a set of bits for a class map. Some classes are built by combining
556 #define cbit_space 0 /* [:space:] or \s */
557 #define cbit_xdigit 32 /* [:xdigit:] */
558 #define cbit_digit 64 /* [:digit:] or \d */
559 #define cbit_upper 96 /* [:upper:] */
560 #define cbit_lower 128 /* [:lower:] */
561 #define cbit_word 160 /* [:word:] or \w */
562 #define cbit_graph 192 /* [:graph:] */
563 #define cbit_print 224 /* [:print:] */
564 #define cbit_punct 256 /* [:punct:] */
565 #define cbit_cntrl 288 /* [:cntrl:] */
566 #define cbit_length 320 /* Length of the cbits table */
568 /* Bit definitions for entries in the ctypes table. Do not change these values
569 without checking pcre2_jit_compile.c, which has an assertion to ensure that
570 ctype_word has the value 16. */
572 #define ctype_space 0x01
573 #define ctype_letter 0x02
574 #define ctype_digit 0x04
575 #define ctype_xdigit 0x08 /* not actually used any more */
576 #define ctype_word 0x10 /* alphanumeric or '_' */
578 /* Offsets of the various tables from the base tables pointer, and
579 total length of the tables. */
581 #define lcc_offset 0 /* Lower case */
582 #define fcc_offset 256 /* Flip case */
583 #define cbits_offset 512 /* Character classes */
584 #define ctypes_offset (cbits_offset + cbit_length) /* Character types */
585 #define tables_length (ctypes_offset + 256)
588 /* -------------------- Character and string names ------------------------ */
590 /* If PCRE2 is to support UTF-8 on EBCDIC platforms, we cannot use normal
591 character constants like '*' because the compiler would emit their EBCDIC code,
592 which is different from their ASCII/UTF-8 code. Instead we define macros for
593 the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
594 is enabled. When UTF-8 support is not enabled, the definitions use character
595 literals. Both character and string versions of each character are needed, and
596 there are some longer strings as well.
598 This means that, on EBCDIC platforms, the PCRE2 library can handle either
599 EBCDIC, or UTF-8, but not both. To support both in the same compiled library
600 would need different lookups depending on whether PCRE2_UTF was set or not.
601 This would make it impossible to use characters in switch/case statements,
602 which would reduce performance. For a theoretical use (which nobody has asked
603 for) in a minority area (EBCDIC platforms), this is not sensible. Any
604 application that did need both could compile two versions of the library, using
605 macros to give the functions distinct names. */
607 #ifndef SUPPORT_UNICODE
609 /* UTF-8 support is not enabled; use the platform-dependent character literals
610 so that PCRE2 works in both ASCII and EBCDIC environments, but only in non-UTF
611 mode. Newline characters are problematic in EBCDIC. Though it has CR and LF
612 characters, a common practice has been to use its NL (0x15) character as the
613 line terminator in C-like processing environments. However, sometimes the LF
614 (0x25) character is used instead, according to this Unicode document:
616 http://unicode.org/standard/reports/tr13/tr13-5.html
618 PCRE2 defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25
619 instead. Whichever is *not* chosen is defined as NEL.
621 In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the
627 #define CHAR_NL '\x15'
628 #define CHAR_NEL '\x25'
629 #define STR_NL "\x15"
630 #define STR_NEL "\x25"
632 #define CHAR_NL '\x25'
633 #define CHAR_NEL '\x15'
634 #define STR_NL "\x25"
635 #define STR_NEL "\x15"
638 #define CHAR_LF CHAR_NL
639 #define STR_LF STR_NL
641 #define CHAR_ESC '\047'
642 #define CHAR_DEL '\007'
643 #define CHAR_NBSP ((unsigned char)'\x41')
644 #define STR_ESC "\047"
645 #define STR_DEL "\007"
647 #else /* Not EBCDIC */
649 /* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for
650 compatibility. NEL is the Unicode newline character; make sure it is
654 #define CHAR_NL CHAR_LF
655 #define CHAR_NEL ((unsigned char)'\x85')
656 #define CHAR_ESC '\033'
657 #define CHAR_DEL '\177'
658 #define CHAR_NBSP ((unsigned char)'\xa0')
661 #define STR_NL STR_LF
662 #define STR_NEL "\x85"
663 #define STR_ESC "\033"
664 #define STR_DEL "\177"
668 /* The remaining definitions work in both environments. */
670 #define CHAR_NUL '\0'
676 #define CHAR_BEL '\a'
678 #define CHAR_SPACE ' '
679 #define CHAR_EXCLAMATION_MARK '!'
680 #define CHAR_QUOTATION_MARK '"'
681 #define CHAR_NUMBER_SIGN '#'
682 #define CHAR_DOLLAR_SIGN '$'
683 #define CHAR_PERCENT_SIGN '%'
684 #define CHAR_AMPERSAND '&'
685 #define CHAR_APOSTROPHE '\''
686 #define CHAR_LEFT_PARENTHESIS '('
687 #define CHAR_RIGHT_PARENTHESIS ')'
688 #define CHAR_ASTERISK '*'
689 #define CHAR_PLUS '+'
690 #define CHAR_COMMA ','
691 #define CHAR_MINUS '-'
693 #define CHAR_SLASH '/'
704 #define CHAR_COLON ':'
705 #define CHAR_SEMICOLON ';'
706 #define CHAR_LESS_THAN_SIGN '<'
707 #define CHAR_EQUALS_SIGN '='
708 #define CHAR_GREATER_THAN_SIGN '>'
709 #define CHAR_QUESTION_MARK '?'
710 #define CHAR_COMMERCIAL_AT '@'
737 #define CHAR_LEFT_SQUARE_BRACKET '['
738 #define CHAR_BACKSLASH '\\'
739 #define CHAR_RIGHT_SQUARE_BRACKET ']'
740 #define CHAR_CIRCUMFLEX_ACCENT '^'
741 #define CHAR_UNDERSCORE '_'
742 #define CHAR_GRAVE_ACCENT '`'
769 #define CHAR_LEFT_CURLY_BRACKET '{'
770 #define CHAR_VERTICAL_LINE '|'
771 #define CHAR_RIGHT_CURLY_BRACKET '}'
772 #define CHAR_TILDE '~'
781 #define STR_SPACE " "
782 #define STR_EXCLAMATION_MARK "!"
783 #define STR_QUOTATION_MARK "\""
784 #define STR_NUMBER_SIGN "#"
785 #define STR_DOLLAR_SIGN "$"
786 #define STR_PERCENT_SIGN "%"
787 #define STR_AMPERSAND "&"
788 #define STR_APOSTROPHE "'"
789 #define STR_LEFT_PARENTHESIS "("
790 #define STR_RIGHT_PARENTHESIS ")"
791 #define STR_ASTERISK "*"
793 #define STR_COMMA ","
794 #define STR_MINUS "-"
796 #define STR_SLASH "/"
807 #define STR_COLON ":"
808 #define STR_SEMICOLON ";"
809 #define STR_LESS_THAN_SIGN "<"
810 #define STR_EQUALS_SIGN "="
811 #define STR_GREATER_THAN_SIGN ">"
812 #define STR_QUESTION_MARK "?"
813 #define STR_COMMERCIAL_AT "@"
840 #define STR_LEFT_SQUARE_BRACKET "["
841 #define STR_BACKSLASH "\\"
842 #define STR_RIGHT_SQUARE_BRACKET "]"
843 #define STR_CIRCUMFLEX_ACCENT "^"
844 #define STR_UNDERSCORE "_"
845 #define STR_GRAVE_ACCENT "`"
872 #define STR_LEFT_CURLY_BRACKET "{"
873 #define STR_VERTICAL_LINE "|"
874 #define STR_RIGHT_CURLY_BRACKET "}"
875 #define STR_TILDE "~"
877 #define STRING_ACCEPT0 "ACCEPT\0"
878 #define STRING_COMMIT0 "COMMIT\0"
879 #define STRING_F0 "F\0"
880 #define STRING_FAIL0 "FAIL\0"
881 #define STRING_MARK0 "MARK\0"
882 #define STRING_PRUNE0 "PRUNE\0"
883 #define STRING_SKIP0 "SKIP\0"
884 #define STRING_THEN "THEN"
886 #define STRING_alpha0 "alpha\0"
887 #define STRING_lower0 "lower\0"
888 #define STRING_upper0 "upper\0"
889 #define STRING_alnum0 "alnum\0"
890 #define STRING_ascii0 "ascii\0"
891 #define STRING_blank0 "blank\0"
892 #define STRING_cntrl0 "cntrl\0"
893 #define STRING_digit0 "digit\0"
894 #define STRING_graph0 "graph\0"
895 #define STRING_print0 "print\0"
896 #define STRING_punct0 "punct\0"
897 #define STRING_space0 "space\0"
898 #define STRING_word0 "word\0"
899 #define STRING_xdigit "xdigit"
901 #define STRING_DEFINE "DEFINE"
902 #define STRING_VERSION "VERSION"
903 #define STRING_WEIRD_STARTWORD "[:<:]]"
904 #define STRING_WEIRD_ENDWORD "[:>:]]"
906 #define STRING_CR_RIGHTPAR "CR)"
907 #define STRING_LF_RIGHTPAR "LF)"
908 #define STRING_CRLF_RIGHTPAR "CRLF)"
909 #define STRING_ANY_RIGHTPAR "ANY)"
910 #define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)"
911 #define STRING_NUL_RIGHTPAR "NUL)"
912 #define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
913 #define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
914 #define STRING_UTF8_RIGHTPAR "UTF8)"
915 #define STRING_UTF16_RIGHTPAR "UTF16)"
916 #define STRING_UTF32_RIGHTPAR "UTF32)"
917 #define STRING_UTF_RIGHTPAR "UTF)"
918 #define STRING_UCP_RIGHTPAR "UCP)"
919 #define STRING_NO_AUTO_POSSESS_RIGHTPAR "NO_AUTO_POSSESS)"
920 #define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR "NO_DOTSTAR_ANCHOR)"
921 #define STRING_NO_JIT_RIGHTPAR "NO_JIT)"
922 #define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)"
923 #define STRING_NOTEMPTY_RIGHTPAR "NOTEMPTY)"
924 #define STRING_NOTEMPTY_ATSTART_RIGHTPAR "NOTEMPTY_ATSTART)"
925 #define STRING_LIMIT_HEAP_EQ "LIMIT_HEAP="
926 #define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH="
927 #define STRING_LIMIT_DEPTH_EQ "LIMIT_DEPTH="
928 #define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION="
929 #define STRING_MARK "MARK"
931 #else /* SUPPORT_UNICODE */
933 /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This
934 works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode
937 #define CHAR_HT '\011'
938 #define CHAR_VT '\013'
939 #define CHAR_FF '\014'
940 #define CHAR_CR '\015'
941 #define CHAR_LF '\012'
942 #define CHAR_NL CHAR_LF
943 #define CHAR_NEL ((unsigned char)'\x85')
944 #define CHAR_BS '\010'
945 #define CHAR_BEL '\007'
946 #define CHAR_ESC '\033'
947 #define CHAR_DEL '\177'
949 #define CHAR_NUL '\0'
950 #define CHAR_SPACE '\040'
951 #define CHAR_EXCLAMATION_MARK '\041'
952 #define CHAR_QUOTATION_MARK '\042'
953 #define CHAR_NUMBER_SIGN '\043'
954 #define CHAR_DOLLAR_SIGN '\044'
955 #define CHAR_PERCENT_SIGN '\045'
956 #define CHAR_AMPERSAND '\046'
957 #define CHAR_APOSTROPHE '\047'
958 #define CHAR_LEFT_PARENTHESIS '\050'
959 #define CHAR_RIGHT_PARENTHESIS '\051'
960 #define CHAR_ASTERISK '\052'
961 #define CHAR_PLUS '\053'
962 #define CHAR_COMMA '\054'
963 #define CHAR_MINUS '\055'
964 #define CHAR_DOT '\056'
965 #define CHAR_SLASH '\057'
966 #define CHAR_0 '\060'
967 #define CHAR_1 '\061'
968 #define CHAR_2 '\062'
969 #define CHAR_3 '\063'
970 #define CHAR_4 '\064'
971 #define CHAR_5 '\065'
972 #define CHAR_6 '\066'
973 #define CHAR_7 '\067'
974 #define CHAR_8 '\070'
975 #define CHAR_9 '\071'
976 #define CHAR_COLON '\072'
977 #define CHAR_SEMICOLON '\073'
978 #define CHAR_LESS_THAN_SIGN '\074'
979 #define CHAR_EQUALS_SIGN '\075'
980 #define CHAR_GREATER_THAN_SIGN '\076'
981 #define CHAR_QUESTION_MARK '\077'
982 #define CHAR_COMMERCIAL_AT '\100'
983 #define CHAR_A '\101'
984 #define CHAR_B '\102'
985 #define CHAR_C '\103'
986 #define CHAR_D '\104'
987 #define CHAR_E '\105'
988 #define CHAR_F '\106'
989 #define CHAR_G '\107'
990 #define CHAR_H '\110'
991 #define CHAR_I '\111'
992 #define CHAR_J '\112'
993 #define CHAR_K '\113'
994 #define CHAR_L '\114'
995 #define CHAR_M '\115'
996 #define CHAR_N '\116'
997 #define CHAR_O '\117'
998 #define CHAR_P '\120'
999 #define CHAR_Q '\121'
1000 #define CHAR_R '\122'
1001 #define CHAR_S '\123'
1002 #define CHAR_T '\124'
1003 #define CHAR_U '\125'
1004 #define CHAR_V '\126'
1005 #define CHAR_W '\127'
1006 #define CHAR_X '\130'
1007 #define CHAR_Y '\131'
1008 #define CHAR_Z '\132'
1009 #define CHAR_LEFT_SQUARE_BRACKET '\133'
1010 #define CHAR_BACKSLASH '\134'
1011 #define CHAR_RIGHT_SQUARE_BRACKET '\135'
1012 #define CHAR_CIRCUMFLEX_ACCENT '\136'
1013 #define CHAR_UNDERSCORE '\137'
1014 #define CHAR_GRAVE_ACCENT '\140'
1015 #define CHAR_a '\141'
1016 #define CHAR_b '\142'
1017 #define CHAR_c '\143'
1018 #define CHAR_d '\144'
1019 #define CHAR_e '\145'
1020 #define CHAR_f '\146'
1021 #define CHAR_g '\147'
1022 #define CHAR_h '\150'
1023 #define CHAR_i '\151'
1024 #define CHAR_j '\152'
1025 #define CHAR_k '\153'
1026 #define CHAR_l '\154'
1027 #define CHAR_m '\155'
1028 #define CHAR_n '\156'
1029 #define CHAR_o '\157'
1030 #define CHAR_p '\160'
1031 #define CHAR_q '\161'
1032 #define CHAR_r '\162'
1033 #define CHAR_s '\163'
1034 #define CHAR_t '\164'
1035 #define CHAR_u '\165'
1036 #define CHAR_v '\166'
1037 #define CHAR_w '\167'
1038 #define CHAR_x '\170'
1039 #define CHAR_y '\171'
1040 #define CHAR_z '\172'
1041 #define CHAR_LEFT_CURLY_BRACKET '\173'
1042 #define CHAR_VERTICAL_LINE '\174'
1043 #define CHAR_RIGHT_CURLY_BRACKET '\175'
1044 #define CHAR_TILDE '\176'
1045 #define CHAR_NBSP ((unsigned char)'\xa0')
1047 #define STR_HT "\011"
1048 #define STR_VT "\013"
1049 #define STR_FF "\014"
1050 #define STR_CR "\015"
1051 #define STR_NL "\012"
1052 #define STR_BS "\010"
1053 #define STR_BEL "\007"
1054 #define STR_ESC "\033"
1055 #define STR_DEL "\177"
1057 #define STR_SPACE "\040"
1058 #define STR_EXCLAMATION_MARK "\041"
1059 #define STR_QUOTATION_MARK "\042"
1060 #define STR_NUMBER_SIGN "\043"
1061 #define STR_DOLLAR_SIGN "\044"
1062 #define STR_PERCENT_SIGN "\045"
1063 #define STR_AMPERSAND "\046"
1064 #define STR_APOSTROPHE "\047"
1065 #define STR_LEFT_PARENTHESIS "\050"
1066 #define STR_RIGHT_PARENTHESIS "\051"
1067 #define STR_ASTERISK "\052"
1068 #define STR_PLUS "\053"
1069 #define STR_COMMA "\054"
1070 #define STR_MINUS "\055"
1071 #define STR_DOT "\056"
1072 #define STR_SLASH "\057"
1073 #define STR_0 "\060"
1074 #define STR_1 "\061"
1075 #define STR_2 "\062"
1076 #define STR_3 "\063"
1077 #define STR_4 "\064"
1078 #define STR_5 "\065"
1079 #define STR_6 "\066"
1080 #define STR_7 "\067"
1081 #define STR_8 "\070"
1082 #define STR_9 "\071"
1083 #define STR_COLON "\072"
1084 #define STR_SEMICOLON "\073"
1085 #define STR_LESS_THAN_SIGN "\074"
1086 #define STR_EQUALS_SIGN "\075"
1087 #define STR_GREATER_THAN_SIGN "\076"
1088 #define STR_QUESTION_MARK "\077"
1089 #define STR_COMMERCIAL_AT "\100"
1090 #define STR_A "\101"
1091 #define STR_B "\102"
1092 #define STR_C "\103"
1093 #define STR_D "\104"
1094 #define STR_E "\105"
1095 #define STR_F "\106"
1096 #define STR_G "\107"
1097 #define STR_H "\110"
1098 #define STR_I "\111"
1099 #define STR_J "\112"
1100 #define STR_K "\113"
1101 #define STR_L "\114"
1102 #define STR_M "\115"
1103 #define STR_N "\116"
1104 #define STR_O "\117"
1105 #define STR_P "\120"
1106 #define STR_Q "\121"
1107 #define STR_R "\122"
1108 #define STR_S "\123"
1109 #define STR_T "\124"
1110 #define STR_U "\125"
1111 #define STR_V "\126"
1112 #define STR_W "\127"
1113 #define STR_X "\130"
1114 #define STR_Y "\131"
1115 #define STR_Z "\132"
1116 #define STR_LEFT_SQUARE_BRACKET "\133"
1117 #define STR_BACKSLASH "\134"
1118 #define STR_RIGHT_SQUARE_BRACKET "\135"
1119 #define STR_CIRCUMFLEX_ACCENT "\136"
1120 #define STR_UNDERSCORE "\137"
1121 #define STR_GRAVE_ACCENT "\140"
1122 #define STR_a "\141"
1123 #define STR_b "\142"
1124 #define STR_c "\143"
1125 #define STR_d "\144"
1126 #define STR_e "\145"
1127 #define STR_f "\146"
1128 #define STR_g "\147"
1129 #define STR_h "\150"
1130 #define STR_i "\151"
1131 #define STR_j "\152"
1132 #define STR_k "\153"
1133 #define STR_l "\154"
1134 #define STR_m "\155"
1135 #define STR_n "\156"
1136 #define STR_o "\157"
1137 #define STR_p "\160"
1138 #define STR_q "\161"
1139 #define STR_r "\162"
1140 #define STR_s "\163"
1141 #define STR_t "\164"
1142 #define STR_u "\165"
1143 #define STR_v "\166"
1144 #define STR_w "\167"
1145 #define STR_x "\170"
1146 #define STR_y "\171"
1147 #define STR_z "\172"
1148 #define STR_LEFT_CURLY_BRACKET "\173"
1149 #define STR_VERTICAL_LINE "\174"
1150 #define STR_RIGHT_CURLY_BRACKET "\175"
1151 #define STR_TILDE "\176"
1153 #define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
1154 #define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
1155 #define STRING_F0 STR_F "\0"
1156 #define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
1157 #define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
1158 #define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
1159 #define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
1160 #define STRING_THEN STR_T STR_H STR_E STR_N
1162 #define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
1163 #define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
1164 #define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
1165 #define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
1166 #define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
1167 #define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
1168 #define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
1169 #define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
1170 #define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
1171 #define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
1172 #define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
1173 #define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
1174 #define STRING_word0 STR_w STR_o STR_r STR_d "\0"
1175 #define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
1177 #define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
1178 #define STRING_VERSION STR_V STR_E STR_R STR_S STR_I STR_O STR_N
1179 #define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
1180 #define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
1182 #define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS
1183 #define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS
1184 #define STRING_CRLF_RIGHTPAR STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1185 #define STRING_ANY_RIGHTPAR STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS
1186 #define STRING_ANYCRLF_RIGHTPAR STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1187 #define STRING_NUL_RIGHTPAR STR_N STR_U STR_L STR_RIGHT_PARENTHESIS
1188 #define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
1189 #define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS
1190 #define STRING_UTF8_RIGHTPAR STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS
1191 #define STRING_UTF16_RIGHTPAR STR_U STR_T STR_F STR_1 STR_6 STR_RIGHT_PARENTHESIS
1192 #define STRING_UTF32_RIGHTPAR STR_U STR_T STR_F STR_3 STR_2 STR_RIGHT_PARENTHESIS
1193 #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_RIGHT_PARENTHESIS
1194 #define STRING_UCP_RIGHTPAR STR_U STR_C STR_P STR_RIGHT_PARENTHESIS
1195 #define STRING_NO_AUTO_POSSESS_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_A STR_U STR_T STR_O STR_UNDERSCORE STR_P STR_O STR_S STR_S STR_E STR_S STR_S STR_RIGHT_PARENTHESIS
1196 #define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_D STR_O STR_T STR_S STR_T STR_A STR_R STR_UNDERSCORE STR_A STR_N STR_C STR_H STR_O STR_R STR_RIGHT_PARENTHESIS
1197 #define STRING_NO_JIT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_J STR_I STR_T STR_RIGHT_PARENTHESIS
1198 #define STRING_NO_START_OPT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_S STR_T STR_A STR_R STR_T STR_UNDERSCORE STR_O STR_P STR_T STR_RIGHT_PARENTHESIS
1199 #define STRING_NOTEMPTY_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_RIGHT_PARENTHESIS
1200 #define STRING_NOTEMPTY_ATSTART_RIGHTPAR STR_N STR_O STR_T STR_E STR_M STR_P STR_T STR_Y STR_UNDERSCORE STR_A STR_T STR_S STR_T STR_A STR_R STR_T STR_RIGHT_PARENTHESIS
1201 #define STRING_LIMIT_HEAP_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_H STR_E STR_A STR_P STR_EQUALS_SIGN
1202 #define STRING_LIMIT_MATCH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_M STR_A STR_T STR_C STR_H STR_EQUALS_SIGN
1203 #define STRING_LIMIT_DEPTH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_D STR_E STR_P STR_T STR_H STR_EQUALS_SIGN
1204 #define STRING_LIMIT_RECURSION_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_R STR_E STR_C STR_U STR_R STR_S STR_I STR_O STR_N STR_EQUALS_SIGN
1205 #define STRING_MARK STR_M STR_A STR_R STR_K
1207 #endif /* SUPPORT_UNICODE */
1209 /* -------------------- End of character and string names -------------------*/
1211 /* -------------------- Definitions for compiled patterns -------------------*/
1213 /* Codes for different types of Unicode property */
1215 #define PT_ANY 0 /* Any property - matches all chars */
1216 #define PT_LAMP 1 /* L& - the union of Lu, Ll, Lt */
1217 #define PT_GC 2 /* Specified general characteristic (e.g. L) */
1218 #define PT_PC 3 /* Specified particular characteristic (e.g. Lu) */
1219 #define PT_SC 4 /* Script (e.g. Han) */
1220 #define PT_ALNUM 5 /* Alphanumeric - the union of L and N */
1221 #define PT_SPACE 6 /* Perl space - Z plus 9,10,12,13 */
1222 #define PT_PXSPACE 7 /* POSIX space - Z plus 9,10,11,12,13 */
1223 #define PT_WORD 8 /* Word - L plus N plus underscore */
1224 #define PT_CLIST 9 /* Pseudo-property: match character list */
1225 #define PT_UCNC 10 /* Universal Character nameable character */
1226 #define PT_TABSIZE 11 /* Size of square table for autopossessify tests */
1228 /* The following special properties are used only in XCLASS items, when POSIX
1229 classes are specified and PCRE2_UCP is set - in other words, for Unicode
1230 handling of these classes. They are not available via the \p or \P escapes like
1231 those in the above list, and so they do not take part in the autopossessifying
1234 #define PT_PXGRAPH 11 /* [:graph:] - characters that mark the paper */
1235 #define PT_PXPRINT 12 /* [:print:] - [:graph:] plus non-control spaces */
1236 #define PT_PXPUNCT 13 /* [:punct:] - punctuation characters */
1238 /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
1239 contain characters with values greater than 255. */
1241 #define XCL_NOT 0x01 /* Flag: this is a negative class */
1242 #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */
1243 #define XCL_HASPROP 0x04 /* Flag: property checks are present. */
1245 #define XCL_END 0 /* Marks end of individual items */
1246 #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */
1247 #define XCL_RANGE 2 /* A range (two multibyte chars) follows */
1248 #define XCL_PROP 3 /* Unicode property (2-byte property code follows) */
1249 #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */
1251 /* These are escaped items that aren't just an encoding of a particular data
1252 value such as \n. They must have non-zero values, as check_escape() returns 0
1253 for a data character. In the escapes[] table in pcre2_compile.c their values
1254 are negated in order to distinguish them from data values.
1256 They must appear here in the same order as in the opcode definitions below, up
1257 to ESC_z. There's a dummy for OP_ALLANY because it corresponds to "." in DOTALL
1258 mode rather than an escape sequence. It is also used for [^] in JavaScript
1259 compatibility mode, and for \C in non-utf mode. In non-DOTALL mode, "." behaves
1262 Negative numbers are used to encode a backreference (\1, \2, \3, etc.) in
1263 check_escape(). There are tests in the code for an escape greater than ESC_b
1264 and less than ESC_Z to detect the types that may be repeated. These are the
1265 types that consume characters. If any new escapes are put in between that don't
1266 consume a character, that code will have to change. */
1268 enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
1269 ESC_W, ESC_w, ESC_N, ESC_dum, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
1270 ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z,
1271 ESC_E, ESC_Q, ESC_g, ESC_k };
1274 /********************** Opcode definitions ******************/
1276 /****** NOTE NOTE NOTE ******
1278 Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in
1279 order to the list of escapes immediately above. Furthermore, values up to
1280 OP_DOLLM must not be changed without adjusting the table called autoposstab in
1281 pcre2_auto_possess.c
1283 Whenever this list is updated, the two macro definitions that follow must be
1284 updated to match. The possessification table called "opcode_possessify" in
1285 pcre2_compile.c must also be updated, and also the tables called "coptable"
1286 and "poptable" in pcre2_dfa_match.c.
1288 ****** NOTE NOTE NOTE ******/
1291 /* The values between FIRST_AUTOTAB_OP and LAST_AUTOTAB_RIGHT_OP, inclusive,
1292 are used in a table for deciding whether a repeated character type can be
1293 auto-possessified. */
1295 #define FIRST_AUTOTAB_OP OP_NOT_DIGIT
1296 #define LAST_AUTOTAB_LEFT_OP OP_EXTUNI
1297 #define LAST_AUTOTAB_RIGHT_OP OP_DOLLM
1300 OP_END, /* 0 End of pattern */
1302 /* Values corresponding to backslashed metacharacters */
1304 OP_SOD, /* 1 Start of data: \A */
1305 OP_SOM, /* 2 Start of match (subject + offset): \G */
1306 OP_SET_SOM, /* 3 Set start of match (\K) */
1307 OP_NOT_WORD_BOUNDARY, /* 4 \B */
1308 OP_WORD_BOUNDARY, /* 5 \b */
1309 OP_NOT_DIGIT, /* 6 \D */
1310 OP_DIGIT, /* 7 \d */
1311 OP_NOT_WHITESPACE, /* 8 \S */
1312 OP_WHITESPACE, /* 9 \s */
1313 OP_NOT_WORDCHAR, /* 10 \W */
1314 OP_WORDCHAR, /* 11 \w */
1316 OP_ANY, /* 12 Match any character except newline (\N) */
1317 OP_ALLANY, /* 13 Match any character */
1318 OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
1319 OP_NOTPROP, /* 15 \P (not Unicode property) */
1320 OP_PROP, /* 16 \p (Unicode property) */
1321 OP_ANYNL, /* 17 \R (any newline sequence) */
1322 OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */
1323 OP_HSPACE, /* 19 \h (horizontal whitespace) */
1324 OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */
1325 OP_VSPACE, /* 21 \v (vertical whitespace) */
1326 OP_EXTUNI, /* 22 \X (extended Unicode sequence */
1327 OP_EODN, /* 23 End of data or \n at end of data (\Z) */
1328 OP_EOD, /* 24 End of data (\z) */
1330 /* Line end assertions */
1332 OP_DOLL, /* 25 End of line - not multiline */
1333 OP_DOLLM, /* 26 End of line - multiline */
1334 OP_CIRC, /* 27 Start of line - not multiline */
1335 OP_CIRCM, /* 28 Start of line - multiline */
1337 /* Single characters; caseful must precede the caseless ones, and these
1338 must remain in this order, and adjacent. */
1340 OP_CHAR, /* 29 Match one character, casefully */
1341 OP_CHARI, /* 30 Match one character, caselessly */
1342 OP_NOT, /* 31 Match one character, not the given one, casefully */
1343 OP_NOTI, /* 32 Match one character, not the given one, caselessly */
1345 /* The following sets of 13 opcodes must always be kept in step because
1346 the offset from the first one is used to generate the others. */
1348 /* Repeated characters; caseful must precede the caseless ones */
1350 OP_STAR, /* 33 The maximizing and minimizing versions of */
1351 OP_MINSTAR, /* 34 these six opcodes must come in pairs, with */
1352 OP_PLUS, /* 35 the minimizing one second. */
1353 OP_MINPLUS, /* 36 */
1355 OP_MINQUERY, /* 38 */
1357 OP_UPTO, /* 39 From 0 to n matches of one character, caseful*/
1358 OP_MINUPTO, /* 40 */
1359 OP_EXACT, /* 41 Exactly n matches */
1361 OP_POSSTAR, /* 42 Possessified star, caseful */
1362 OP_POSPLUS, /* 43 Possessified plus, caseful */
1363 OP_POSQUERY, /* 44 Posesssified query, caseful */
1364 OP_POSUPTO, /* 45 Possessified upto, caseful */
1366 /* Repeated characters; caseless must follow the caseful ones */
1369 OP_MINSTARI, /* 47 */
1371 OP_MINPLUSI, /* 49 */
1373 OP_MINQUERYI, /* 51 */
1375 OP_UPTOI, /* 52 From 0 to n matches of one character, caseless */
1376 OP_MINUPTOI, /* 53 */
1379 OP_POSSTARI, /* 55 Possessified star, caseless */
1380 OP_POSPLUSI, /* 56 Possessified plus, caseless */
1381 OP_POSQUERYI, /* 57 Posesssified query, caseless */
1382 OP_POSUPTOI, /* 58 Possessified upto, caseless */
1384 /* The negated ones must follow the non-negated ones, and match them */
1385 /* Negated repeated character, caseful; must precede the caseless ones */
1387 OP_NOTSTAR, /* 59 The maximizing and minimizing versions of */
1388 OP_NOTMINSTAR, /* 60 these six opcodes must come in pairs, with */
1389 OP_NOTPLUS, /* 61 the minimizing one second. They must be in */
1390 OP_NOTMINPLUS, /* 62 exactly the same order as those above. */
1391 OP_NOTQUERY, /* 63 */
1392 OP_NOTMINQUERY, /* 64 */
1394 OP_NOTUPTO, /* 65 From 0 to n matches, caseful */
1395 OP_NOTMINUPTO, /* 66 */
1396 OP_NOTEXACT, /* 67 Exactly n matches */
1398 OP_NOTPOSSTAR, /* 68 Possessified versions, caseful */
1399 OP_NOTPOSPLUS, /* 69 */
1400 OP_NOTPOSQUERY, /* 70 */
1401 OP_NOTPOSUPTO, /* 71 */
1403 /* Negated repeated character, caseless; must follow the caseful ones */
1405 OP_NOTSTARI, /* 72 */
1406 OP_NOTMINSTARI, /* 73 */
1407 OP_NOTPLUSI, /* 74 */
1408 OP_NOTMINPLUSI, /* 75 */
1409 OP_NOTQUERYI, /* 76 */
1410 OP_NOTMINQUERYI, /* 77 */
1412 OP_NOTUPTOI, /* 78 From 0 to n matches, caseless */
1413 OP_NOTMINUPTOI, /* 79 */
1414 OP_NOTEXACTI, /* 80 Exactly n matches */
1416 OP_NOTPOSSTARI, /* 81 Possessified versions, caseless */
1417 OP_NOTPOSPLUSI, /* 82 */
1418 OP_NOTPOSQUERYI, /* 83 */
1419 OP_NOTPOSUPTOI, /* 84 */
1421 /* Character types */
1423 OP_TYPESTAR, /* 85 The maximizing and minimizing versions of */
1424 OP_TYPEMINSTAR, /* 86 these six opcodes must come in pairs, with */
1425 OP_TYPEPLUS, /* 87 the minimizing one second. These codes must */
1426 OP_TYPEMINPLUS, /* 88 be in exactly the same order as those above. */
1427 OP_TYPEQUERY, /* 89 */
1428 OP_TYPEMINQUERY, /* 90 */
1430 OP_TYPEUPTO, /* 91 From 0 to n matches */
1431 OP_TYPEMINUPTO, /* 92 */
1432 OP_TYPEEXACT, /* 93 Exactly n matches */
1434 OP_TYPEPOSSTAR, /* 94 Possessified versions */
1435 OP_TYPEPOSPLUS, /* 95 */
1436 OP_TYPEPOSQUERY, /* 96 */
1437 OP_TYPEPOSUPTO, /* 97 */
1439 /* These are used for character classes and back references; only the
1440 first six are the same as the sets above. */
1442 OP_CRSTAR, /* 98 The maximizing and minimizing versions of */
1443 OP_CRMINSTAR, /* 99 all these opcodes must come in pairs, with */
1444 OP_CRPLUS, /* 100 the minimizing one second. These codes must */
1445 OP_CRMINPLUS, /* 101 be in exactly the same order as those above. */
1446 OP_CRQUERY, /* 102 */
1447 OP_CRMINQUERY, /* 103 */
1449 OP_CRRANGE, /* 104 These are different to the three sets above. */
1450 OP_CRMINRANGE, /* 105 */
1452 OP_CRPOSSTAR, /* 106 Possessified versions */
1453 OP_CRPOSPLUS, /* 107 */
1454 OP_CRPOSQUERY, /* 108 */
1455 OP_CRPOSRANGE, /* 109 */
1457 /* End of quantifier opcodes */
1459 OP_CLASS, /* 110 Match a character class, chars < 256 only */
1460 OP_NCLASS, /* 111 Same, but the bitmap was created from a negative
1461 class - the difference is relevant only when a
1462 character > 255 is encountered. */
1463 OP_XCLASS, /* 112 Extended class for handling > 255 chars within the
1464 class. This does both positive and negative. */
1465 OP_REF, /* 113 Match a back reference, casefully */
1466 OP_REFI, /* 114 Match a back reference, caselessly */
1467 OP_DNREF, /* 115 Match a duplicate name backref, casefully */
1468 OP_DNREFI, /* 116 Match a duplicate name backref, caselessly */
1469 OP_RECURSE, /* 117 Match a numbered subpattern (possibly recursive) */
1470 OP_CALLOUT, /* 118 Call out to external function if provided */
1471 OP_CALLOUT_STR, /* 119 Call out with string argument */
1473 OP_ALT, /* 120 Start of alternation */
1474 OP_KET, /* 121 End of group that doesn't have an unbounded repeat */
1475 OP_KETRMAX, /* 122 These two must remain together and in this */
1476 OP_KETRMIN, /* 123 order. They are for groups the repeat for ever. */
1477 OP_KETRPOS, /* 124 Possessive unlimited repeat. */
1479 /* The assertions must come before BRA, CBRA, ONCE, and COND, and the four
1480 asserts must remain in order. */
1482 OP_REVERSE, /* 125 Move pointer back - used in lookbehind assertions */
1483 OP_ASSERT, /* 126 Positive lookahead */
1484 OP_ASSERT_NOT, /* 127 Negative lookahead */
1485 OP_ASSERTBACK, /* 128 Positive lookbehind */
1486 OP_ASSERTBACK_NOT, /* 129 Negative lookbehind */
1488 /* ONCE, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come immediately after the
1489 assertions, with ONCE first, as there's a test for >= ONCE for a subpattern
1490 that isn't an assertion. The POS versions must immediately follow the non-POS
1491 versions in each case. */
1493 OP_ONCE, /* 130 Atomic group, contains captures */
1494 OP_BRA, /* 131 Start of non-capturing bracket */
1495 OP_BRAPOS, /* 132 Ditto, with unlimited, possessive repeat */
1496 OP_CBRA, /* 133 Start of capturing bracket */
1497 OP_CBRAPOS, /* 134 Ditto, with unlimited, possessive repeat */
1498 OP_COND, /* 135 Conditional group */
1500 /* These five must follow the previous five, in the same order. There's a
1501 check for >= SBRA to distinguish the two sets. */
1503 OP_SBRA, /* 136 Start of non-capturing bracket, check empty */
1504 OP_SBRAPOS, /* 137 Ditto, with unlimited, possessive repeat */
1505 OP_SCBRA, /* 138 Start of capturing bracket, check empty */
1506 OP_SCBRAPOS, /* 139 Ditto, with unlimited, possessive repeat */
1507 OP_SCOND, /* 140 Conditional group, check empty */
1509 /* The next two pairs must (respectively) be kept together. */
1511 OP_CREF, /* 141 Used to hold a capture number as condition */
1512 OP_DNCREF, /* 142 Used to point to duplicate names as a condition */
1513 OP_RREF, /* 143 Used to hold a recursion number as condition */
1514 OP_DNRREF, /* 144 Used to point to duplicate names as a condition */
1515 OP_FALSE, /* 145 Always false (used by DEFINE and VERSION) */
1516 OP_TRUE, /* 146 Always true (used by VERSION) */
1518 OP_BRAZERO, /* 147 These two must remain together and in this */
1519 OP_BRAMINZERO, /* 148 order. */
1520 OP_BRAPOSZERO, /* 149 */
1522 /* These are backtracking control verbs */
1524 OP_MARK, /* 150 always has an argument */
1526 OP_PRUNE_ARG, /* 152 same, but with argument */
1528 OP_SKIP_ARG, /* 154 same, but with argument */
1530 OP_THEN_ARG, /* 156 same, but with argument */
1531 OP_COMMIT, /* 157 */
1532 OP_COMMIT_ARG, /* 158 same, but with argument */
1534 /* These are forced failure and success verbs. FAIL and ACCEPT do accept an
1535 argument, but these cases can be compiled as, for example, (*MARK:X)(*FAIL)
1536 without the need for a special opcode. */
1539 OP_ACCEPT, /* 160 */
1540 OP_ASSERT_ACCEPT, /* 161 Used inside assertions */
1541 OP_CLOSE, /* 162 Used before OP_ACCEPT to close open captures */
1543 /* This is used to skip a subpattern with a {0} quantifier */
1545 OP_SKIPZERO, /* 163 */
1547 /* This is used to identify a DEFINE group during compilation so that it can
1548 be checked for having only one branch. It is changed to OP_FALSE before
1549 compilation finishes. */
1551 OP_DEFINE, /* 164 */
1553 /* This is not an opcode, but is used to check that tables indexed by opcode
1554 are the correct length, in order to catch updating errors - there have been
1555 some in the past. */
1561 /* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro
1562 definitions that follow must also be updated to match. There are also tables
1563 called "opcode_possessify" in pcre2_compile.c and "coptable" and "poptable" in
1564 pcre2_dfa_exec.c that must be updated. */
1567 /* This macro defines textual names for all the opcodes. These are used only
1568 for debugging, and some of them are only partial names. The macro is referenced
1569 only in pcre2_printint.c, which fills out the full names in many cases (and in
1570 some cases doesn't actually use these names at all). */
1572 #define OP_NAME_LIST \
1573 "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \
1574 "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \
1575 "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \
1576 "extuni", "\\Z", "\\z", \
1577 "$", "$", "^", "^", "char", "chari", "not", "noti", \
1578 "*", "*?", "+", "+?", "?", "??", \
1580 "*+","++", "?+", "{", \
1581 "*", "*?", "+", "+?", "?", "??", \
1583 "*+","++", "?+", "{", \
1584 "*", "*?", "+", "+?", "?", "??", \
1586 "*+","++", "?+", "{", \
1587 "*", "*?", "+", "+?", "?", "??", \
1589 "*+","++", "?+", "{", \
1590 "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \
1591 "*+","++", "?+", "{", \
1592 "*", "*?", "+", "+?", "?", "??", "{", "{", \
1593 "*+","++", "?+", "{", \
1594 "class", "nclass", "xclass", "Ref", "Refi", "DnRef", "DnRefi", \
1595 "Recurse", "Callout", "CalloutStr", \
1596 "Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \
1597 "Reverse", "Assert", "Assert not", "AssertB", "AssertB not", \
1599 "Bra", "BraPos", "CBra", "CBraPos", \
1601 "SBra", "SBraPos", "SCBra", "SCBraPos", \
1603 "Cond ref", "Cond dnref", "Cond rec", "Cond dnrec", \
1604 "Cond false", "Cond true", \
1605 "Brazero", "Braminzero", "Braposzero", \
1606 "*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \
1607 "*THEN", "*THEN", "*COMMIT", "*COMMIT", "*FAIL", \
1608 "*ACCEPT", "*ASSERT_ACCEPT", \
1609 "Close", "Skip zero", "Define"
1612 /* This macro defines the length of fixed length operations in the compiled
1613 regex. The lengths are used when searching for specific things, and also in the
1614 debugging printing of a compiled regex. We use a macro so that it can be
1615 defined close to the definitions of the opcodes themselves.
1617 As things have been extended, some of these are no longer fixed lenths, but are
1618 minima instead. For example, the length of a single-character repeat may vary
1619 in UTF-8 mode. The code that uses this table must know about such things. */
1621 #define OP_LENGTHS \
1623 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \
1624 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \
1625 1, 1, 1, /* Any, AllAny, Anybyte */ \
1626 3, 3, /* \P, \p */ \
1627 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \
1629 1, 1, 1, 1, 1, 1, /* \Z, \z, $, $M ^, ^M */ \
1630 2, /* Char - the minimum length */ \
1631 2, /* Chari - the minimum length */ \
1634 /* Positive single-char repeats ** These are */ \
1635 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \
1636 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto, minupto ** mode */ \
1637 2+IMM2_SIZE, /* exact */ \
1638 2, 2, 2, 2+IMM2_SIZE, /* *+, ++, ?+, upto+ */ \
1639 2, 2, 2, 2, 2, 2, /* *I, *?I, +I, +?I, ?I, ??I ** UTF-8 */ \
1640 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto I, minupto I */ \
1641 2+IMM2_SIZE, /* exact I */ \
1642 2, 2, 2, 2+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ \
1643 /* Negative single-char repeats - only for chars < 256 */ \
1644 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \
1645 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto, minupto */ \
1646 2+IMM2_SIZE, /* NOT exact */ \
1647 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *, +, ?, upto */ \
1648 2, 2, 2, 2, 2, 2, /* NOT *I, *?I, +I, +?I, ?I, ??I */ \
1649 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto I, minupto I */ \
1650 2+IMM2_SIZE, /* NOT exact I */ \
1651 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *I, +I, ?I, upto I */ \
1652 /* Positive type repeats */ \
1653 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \
1654 2+IMM2_SIZE, 2+IMM2_SIZE, /* Type upto, minupto */ \
1655 2+IMM2_SIZE, /* Type exact */ \
1656 2, 2, 2, 2+IMM2_SIZE, /* Possessive *+, ++, ?+, upto+ */ \
1657 /* Character class & ref repeats */ \
1658 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \
1659 1+2*IMM2_SIZE, 1+2*IMM2_SIZE, /* CRRANGE, CRMINRANGE */ \
1660 1, 1, 1, 1+2*IMM2_SIZE, /* Possessive *+, ++, ?+, CRPOSRANGE */ \
1661 1+(32/sizeof(PCRE2_UCHAR)), /* CLASS */ \
1662 1+(32/sizeof(PCRE2_UCHAR)), /* NCLASS */ \
1663 0, /* XCLASS - variable length */ \
1664 1+IMM2_SIZE, /* REF */ \
1665 1+IMM2_SIZE, /* REFI */ \
1666 1+2*IMM2_SIZE, /* DNREF */ \
1667 1+2*IMM2_SIZE, /* DNREFI */ \
1668 1+LINK_SIZE, /* RECURSE */ \
1669 1+2*LINK_SIZE+1, /* CALLOUT */ \
1670 0, /* CALLOUT_STR - variable length */ \
1671 1+LINK_SIZE, /* Alt */ \
1672 1+LINK_SIZE, /* Ket */ \
1673 1+LINK_SIZE, /* KetRmax */ \
1674 1+LINK_SIZE, /* KetRmin */ \
1675 1+LINK_SIZE, /* KetRpos */ \
1676 1+LINK_SIZE, /* Reverse */ \
1677 1+LINK_SIZE, /* Assert */ \
1678 1+LINK_SIZE, /* Assert not */ \
1679 1+LINK_SIZE, /* Assert behind */ \
1680 1+LINK_SIZE, /* Assert behind not */ \
1681 1+LINK_SIZE, /* ONCE */ \
1682 1+LINK_SIZE, /* BRA */ \
1683 1+LINK_SIZE, /* BRAPOS */ \
1684 1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \
1685 1+LINK_SIZE+IMM2_SIZE, /* CBRAPOS */ \
1686 1+LINK_SIZE, /* COND */ \
1687 1+LINK_SIZE, /* SBRA */ \
1688 1+LINK_SIZE, /* SBRAPOS */ \
1689 1+LINK_SIZE+IMM2_SIZE, /* SCBRA */ \
1690 1+LINK_SIZE+IMM2_SIZE, /* SCBRAPOS */ \
1691 1+LINK_SIZE, /* SCOND */ \
1692 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* CREF, DNCREF */ \
1693 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* RREF, DNRREF */ \
1694 1, 1, /* FALSE, TRUE */ \
1695 1, 1, 1, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ \
1696 3, 1, 3, /* MARK, PRUNE, PRUNE_ARG */ \
1697 1, 3, /* SKIP, SKIP_ARG */ \
1698 1, 3, /* THEN, THEN_ARG */ \
1699 1, 3, /* COMMIT, COMMIT_ARG */ \
1700 1, 1, 1, /* FAIL, ACCEPT, ASSERT_ACCEPT */ \
1701 1+IMM2_SIZE, 1, /* CLOSE, SKIPZERO */ \
1704 /* A magic value for OP_RREF to indicate the "any recursion" condition. */
1706 #define RREF_ANY 0xffff
1709 /* ---------- Private structures that are mode-independent. ---------- */
1711 /* Structure to hold data for custom memory management. */
1713 typedef struct pcre2_memctl {
1714 void * (*malloc)(size_t, void *);
1715 void (*free)(void *, void *);
1719 /* Structure for building a chain of open capturing subpatterns during
1720 compiling, so that instructions to close them can be compiled when (*ACCEPT) is
1721 encountered. This is also used to identify subpatterns that contain recursive
1722 back references to themselves, so that they can be made atomic. */
1724 typedef struct open_capitem {
1725 struct open_capitem *next; /* Chain link */
1726 uint16_t number; /* Capture number */
1727 uint16_t flag; /* Set TRUE if recursive back ref */
1728 uint16_t assert_depth; /* Assertion depth when opened */
1731 /* Layout of the UCP type table that translates property names into types and
1732 codes. Each entry used to point directly to a name, but to reduce the number of
1733 relocations in shared libraries, it now has an offset into a single string
1737 uint16_t name_offset;
1742 /* Unicode character database (UCD) record format */
1745 uint8_t script; /* ucp_Arabic, etc. */
1746 uint8_t chartype; /* ucp_Cc, etc. (general categories) */
1747 uint8_t gbprop; /* ucp_gbControl, etc. (grapheme break property) */
1748 uint8_t caseset; /* offset to multichar other cases or zero */
1749 int32_t other_case; /* offset to other case, or zero if none */
1752 /* UCD access macros */
1754 #define UCD_BLOCK_SIZE 128
1755 #define REAL_GET_UCD(ch) (PRIV(ucd_records) + \
1756 PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \
1757 UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE])
1759 #if PCRE2_CODE_UNIT_WIDTH == 32
1760 #define GET_UCD(ch) ((ch > MAX_UTF_CODE_POINT)? \
1761 PRIV(dummy_ucd_record) : REAL_GET_UCD(ch))
1763 #define GET_UCD(ch) REAL_GET_UCD(ch)
1766 #define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype
1767 #define UCD_SCRIPT(ch) GET_UCD(ch)->script
1768 #define UCD_CATEGORY(ch) PRIV(ucp_gentype)[UCD_CHARTYPE(ch)]
1769 #define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop
1770 #define UCD_CASESET(ch) GET_UCD(ch)->caseset
1771 #define UCD_OTHERCASE(ch) ((uint32_t)((int)ch + (int)(GET_UCD(ch)->other_case)))
1773 /* Header for serialized pcre2 codes. */
1775 typedef struct pcre2_serialized_data {
1779 int32_t number_of_codes;
1780 } pcre2_serialized_data;
1784 /* ----------------- Items that need PCRE2_CODE_UNIT_WIDTH ----------------- */
1786 /* When this file is included by pcre2test, PCRE2_CODE_UNIT_WIDTH is defined as
1787 0, so the following items are omitted. */
1789 #if defined PCRE2_CODE_UNIT_WIDTH && PCRE2_CODE_UNIT_WIDTH != 0
1791 /* EBCDIC is supported only for the 8-bit library. */
1793 #if defined EBCDIC && PCRE2_CODE_UNIT_WIDTH != 8
1794 #error EBCDIC is not supported for the 16-bit or 32-bit libraries
1797 /* This is the largest non-UTF code point. */
1799 #define MAX_NON_UTF_CHAR (0xffffffffU >> (32 - PCRE2_CODE_UNIT_WIDTH))
1801 /* Internal shared data tables and variables. These are used by more than one
1802 of the exported public functions. They have to be "external" in the C sense,
1803 but are not part of the PCRE2 public API. Although the data for some of them is
1804 identical in all libraries, they must have different names so that multiple
1805 libraries can be simultaneously linked to a single application. However, UTF-8
1806 tables are needed only when compiling the 8-bit library. */
1808 #if PCRE2_CODE_UNIT_WIDTH == 8
1809 extern const int PRIV(utf8_table1)[];
1810 extern const int PRIV(utf8_table1_size);
1811 extern const int PRIV(utf8_table2)[];
1812 extern const int PRIV(utf8_table3)[];
1813 extern const uint8_t PRIV(utf8_table4)[];
1816 #define _pcre2_OP_lengths PCRE2_SUFFIX(_pcre2_OP_lengths_)
1817 #define _pcre2_callout_end_delims PCRE2_SUFFIX(_pcre2_callout_end_delims_)
1818 #define _pcre2_callout_start_delims PCRE2_SUFFIX(_pcre2_callout_start_delims_)
1819 #define _pcre2_default_compile_context PCRE2_SUFFIX(_pcre2_default_compile_context_)
1820 #define _pcre2_default_convert_context PCRE2_SUFFIX(_pcre2_default_convert_context_)
1821 #define _pcre2_default_match_context PCRE2_SUFFIX(_pcre2_default_match_context_)
1822 #define _pcre2_default_tables PCRE2_SUFFIX(_pcre2_default_tables_)
1823 #if PCRE2_CODE_UNIT_WIDTH == 32
1824 #define _pcre2_dummy_ucd_record PCRE2_SUFFIX(_pcre2_dummy_ucd_record_)
1826 #define _pcre2_hspace_list PCRE2_SUFFIX(_pcre2_hspace_list_)
1827 #define _pcre2_vspace_list PCRE2_SUFFIX(_pcre2_vspace_list_)
1828 #define _pcre2_ucd_caseless_sets PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
1829 #define _pcre2_ucd_records PCRE2_SUFFIX(_pcre2_ucd_records_)
1830 #define _pcre2_ucd_stage1 PCRE2_SUFFIX(_pcre2_ucd_stage1_)
1831 #define _pcre2_ucd_stage2 PCRE2_SUFFIX(_pcre2_ucd_stage2_)
1832 #define _pcre2_ucp_gbtable PCRE2_SUFFIX(_pcre2_ucp_gbtable_)
1833 #define _pcre2_ucp_gentype PCRE2_SUFFIX(_pcre2_ucp_gentype_)
1834 #define _pcre2_ucp_typerange PCRE2_SUFFIX(_pcre2_ucp_typerange_)
1835 #define _pcre2_unicode_version PCRE2_SUFFIX(_pcre2_unicode_version_)
1836 #define _pcre2_utt PCRE2_SUFFIX(_pcre2_utt_)
1837 #define _pcre2_utt_names PCRE2_SUFFIX(_pcre2_utt_names_)
1838 #define _pcre2_utt_size PCRE2_SUFFIX(_pcre2_utt_size_)
1840 extern const uint8_t PRIV(OP_lengths)[];
1841 extern const uint32_t PRIV(callout_end_delims)[];
1842 extern const uint32_t PRIV(callout_start_delims)[];
1843 extern const pcre2_compile_context PRIV(default_compile_context);
1844 extern const pcre2_convert_context PRIV(default_convert_context);
1845 extern const pcre2_match_context PRIV(default_match_context);
1846 extern const uint8_t PRIV(default_tables)[];
1847 extern const uint32_t PRIV(hspace_list)[];
1848 extern const uint32_t PRIV(vspace_list)[];
1849 extern const uint32_t PRIV(ucd_caseless_sets)[];
1850 extern const ucd_record PRIV(ucd_records)[];
1851 #if PCRE2_CODE_UNIT_WIDTH == 32
1852 extern const ucd_record PRIV(dummy_ucd_record)[];
1854 extern const uint16_t PRIV(ucd_stage1)[];
1855 extern const uint16_t PRIV(ucd_stage2)[];
1856 extern const uint32_t PRIV(ucp_gbtable)[];
1857 extern const uint32_t PRIV(ucp_gentype)[];
1859 extern const int PRIV(ucp_typerange)[];
1861 extern const char *PRIV(unicode_version);
1862 extern const ucp_type_table PRIV(utt)[];
1863 extern const char PRIV(utt_names)[];
1864 extern const size_t PRIV(utt_size);
1866 /* Mode-dependent macros and hidden and private structures are defined in a
1867 separate file so that pcre2test can include them at all supported widths. When
1868 compiling the library, PCRE2_CODE_UNIT_WIDTH will be defined, and we can
1869 include them at the appropriate width, after setting up suffix macros for the
1870 private structures. */
1872 #define branch_chain PCRE2_SUFFIX(branch_chain_)
1873 #define compile_block PCRE2_SUFFIX(compile_block_)
1874 #define dfa_match_block PCRE2_SUFFIX(dfa_match_block_)
1875 #define match_block PCRE2_SUFFIX(match_block_)
1876 #define named_group PCRE2_SUFFIX(named_group_)
1878 #include "pcre2_intmodedep.h"
1880 /* Private "external" functions. These are internal functions that are called
1881 from modules other than the one in which they are defined. They have to be
1882 "external" in the C sense, but are not part of the PCRE2 public API. They are
1883 not referenced from pcre2test, and must not be defined when no code unit width
1886 #define _pcre2_auto_possessify PCRE2_SUFFIX(_pcre2_auto_possessify_)
1887 #define _pcre2_check_escape PCRE2_SUFFIX(_pcre2_check_escape_)
1888 #define _pcre2_extuni PCRE2_SUFFIX(_pcre2_extuni_)
1889 #define _pcre2_find_bracket PCRE2_SUFFIX(_pcre2_find_bracket_)
1890 #define _pcre2_is_newline PCRE2_SUFFIX(_pcre2_is_newline_)
1891 #define _pcre2_jit_free_rodata PCRE2_SUFFIX(_pcre2_jit_free_rodata_)
1892 #define _pcre2_jit_free PCRE2_SUFFIX(_pcre2_jit_free_)
1893 #define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_)
1894 #define _pcre2_jit_get_target PCRE2_SUFFIX(_pcre2_jit_get_target_)
1895 #define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
1896 #define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_)
1897 #define _pcre2_strcmp PCRE2_SUFFIX(_pcre2_strcmp_)
1898 #define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre2_strcmp_c8_)
1899 #define _pcre2_strcpy_c8 PCRE2_SUFFIX(_pcre2_strcpy_c8_)
1900 #define _pcre2_strlen PCRE2_SUFFIX(_pcre2_strlen_)
1901 #define _pcre2_strncmp PCRE2_SUFFIX(_pcre2_strncmp_)
1902 #define _pcre2_strncmp_c8 PCRE2_SUFFIX(_pcre2_strncmp_c8_)
1903 #define _pcre2_study PCRE2_SUFFIX(_pcre2_study_)
1904 #define _pcre2_valid_utf PCRE2_SUFFIX(_pcre2_valid_utf_)
1905 #define _pcre2_was_newline PCRE2_SUFFIX(_pcre2_was_newline_)
1906 #define _pcre2_xclass PCRE2_SUFFIX(_pcre2_xclass_)
1908 extern int _pcre2_auto_possessify(PCRE2_UCHAR *, BOOL,
1909 const compile_block *);
1910 extern int _pcre2_check_escape(PCRE2_SPTR *, PCRE2_SPTR, uint32_t *,
1911 int *, uint32_t, BOOL, compile_block *);
1912 extern PCRE2_SPTR _pcre2_extuni(uint32_t, PCRE2_SPTR, PCRE2_SPTR, PCRE2_SPTR,
1914 extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int);
1915 extern BOOL _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR,
1917 extern void _pcre2_jit_free_rodata(void *, void *);
1918 extern void _pcre2_jit_free(void *, pcre2_memctl *);
1919 extern size_t _pcre2_jit_get_size(void *);
1920 const char * _pcre2_jit_get_target(void);
1921 extern void * _pcre2_memctl_malloc(size_t, pcre2_memctl *);
1922 extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
1923 extern int _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR);
1924 extern int _pcre2_strcmp_c8(PCRE2_SPTR, const char *);
1925 extern PCRE2_SIZE _pcre2_strcpy_c8(PCRE2_UCHAR *, const char *);
1926 extern PCRE2_SIZE _pcre2_strlen(PCRE2_SPTR);
1927 extern int _pcre2_strncmp(PCRE2_SPTR, PCRE2_SPTR, size_t);
1928 extern int _pcre2_strncmp_c8(PCRE2_SPTR, const char *, size_t);
1929 extern int _pcre2_study(pcre2_real_code *);
1930 extern int _pcre2_valid_utf(PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE *);
1931 extern BOOL _pcre2_was_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR,
1933 extern BOOL _pcre2_xclass(uint32_t, PCRE2_SPTR, BOOL);
1935 /* This function is needed only when memmove() is not available. */
1937 #if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE)
1938 #define _pcre2_memmove PCRE2_SUFFIX(_pcre2_memmove)
1939 extern void * _pcre2_memmove(void *, const void *, size_t);
1942 #endif /* PCRE2_CODE_UNIT_WIDTH */
1943 #endif /* PCRE2_INTERNAL_H_IDEMPOTENT_GUARD */
1945 /* End of pcre2_internal.h */