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