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