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