forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcre2_internal.h
2235 lines (1919 loc) · 101 KB
/
pcre2_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
/* PCRE2 is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
New API code Copyright (c) 2016-2024 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of Cambridge nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/
#ifndef PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
#define PCRE2_INTERNAL_H_IDEMPOTENT_GUARD
/* We do not support both EBCDIC and Unicode at the same time. The "configure"
script prevents both being selected, but not everybody uses "configure". EBCDIC
is only supported for the 8-bit library, but the check for this has to be later
in this file, because the first part is not width-dependent, and is included by
pcre2test.c with CODE_UNIT_WIDTH == 0. */
#if defined EBCDIC && defined SUPPORT_UNICODE
#error The use of both EBCDIC and SUPPORT_UNICODE is not supported.
#endif
/* When compiling one of the libraries, the value of PCRE2_CODE_UNIT_WIDTH must
be 8, 16, or 32. AutoTools and CMake ensure that this is always the case, but
other other building methods may not, so here is a check. It is cut out when
building pcre2test, bcause that sets the value to zero. No other source should
be including this file. There is no explicit way of forcing a compile to be
abandoned, but trying to include a non-existent file seems cleanest. Otherwise
there will be many irrelevant consequential errors. */
#if (!defined PCRE2_BUILDING_PCRE2TEST && !defined PCRE2_DFTABLES) && \
(!defined PCRE2_CODE_UNIT_WIDTH || \
(PCRE2_CODE_UNIT_WIDTH != 8 && \
PCRE2_CODE_UNIT_WIDTH != 16 && \
PCRE2_CODE_UNIT_WIDTH != 32))
#error PCRE2_CODE_UNIT_WIDTH must be defined as 8, 16, or 32.
#include <AbandonCompile>
#endif
/* Standard C headers */
#include <ctype.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Macros to make boolean values more obvious. The #ifndef is to pacify
compiler warnings in environments where these macros are defined elsewhere.
Unfortunately, there is no way to do the same for the typedef. */
typedef int BOOL;
#ifndef FALSE
#define FALSE 0
#define TRUE 1
#endif
/* Helper macro for static (compile-time) assertions. Can be used inside
functions, or at the top-level of a file. */
#define STATIC_ASSERT_JOIN(a,b) a ## b
#define STATIC_ASSERT(cond, msg) \
typedef int STATIC_ASSERT_JOIN(static_assertion_,msg)[(cond)?1:-1]
/* Valgrind (memcheck) support */
#ifdef SUPPORT_VALGRIND
#include <valgrind/memcheck.h>
#endif
/* -ftrivial-auto-var-init support supports initializing all local variables
to avoid some classes of bug, but this can cause an unacceptable slowdown
for large on-stack arrays in hot functions. This macro lets us annotate
such arrays. */
#ifdef HAVE_ATTRIBUTE_UNINITIALIZED
#define PCRE2_KEEP_UNINITIALIZED __attribute__((uninitialized))
#else
#define PCRE2_KEEP_UNINITIALIZED
#endif
/* Older versions of MSVC lack snprintf(). This define allows for
warning/error-free compilation and testing with MSVC compilers back to at least
MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
/* When compiling a DLL for Windows, the exported symbols have to be declared
using some MS magic. I found some useful information on this web page:
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
information there, using __declspec(dllexport) without "extern" we have a
definition; with "extern" we have a declaration. The settings here override the
setting in pcre2.h (which is included below); it defines only PCRE2_EXP_DECL,
which is all that is needed for applications (they just import the symbols). We
use:
PCRE2_EXP_DECL for declarations
PCRE2_EXP_DEFN for definitions
The reason for wrapping this in #ifndef PCRE2_EXP_DECL is so that pcre2test,
which is an application, but needs to import this file in order to "peek" at
internals, can #include pcre2.h first to get an application's-eye view.
In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
special-purpose environments) might want to stick other stuff in front of
exported symbols. That's why, in the non-Windows case, we set PCRE2_EXP_DEFN
only if it is not already set. */
#ifndef PCRE2_EXP_DECL
# ifdef _WIN32
# ifndef PCRE2_STATIC
# define PCRE2_EXP_DECL extern __declspec(dllexport)
# define PCRE2_EXP_DEFN __declspec(dllexport)
# else
# define PCRE2_EXP_DECL extern PCRE2_EXPORT
# define PCRE2_EXP_DEFN
# endif
# else
# ifdef __cplusplus
# define PCRE2_EXP_DECL extern "C" PCRE2_EXPORT
# else
# define PCRE2_EXP_DECL extern PCRE2_EXPORT
# endif
# ifndef PCRE2_EXP_DEFN
# define PCRE2_EXP_DEFN PCRE2_EXP_DECL
# endif
# endif
#endif
/* Include the public PCRE2 header and the definitions of UCP character
property values. This must follow the setting of PCRE2_EXP_DECL above. */
#include "pcre2.h"
#include "pcre2_ucp.h"
/* When PCRE2 is compiled as a C++ library, the subject pointer can be replaced
with a custom type. This makes it possible, for example, to allow pcre2_match()
to process subject strings that are discontinuous by using a smart pointer
class. It must always be possible to inspect all of the subject string in
pcre2_match() because of the way it backtracks. */
/* WARNING: This is as yet untested for PCRE2. */
#ifdef CUSTOM_SUBJECT_PTR
#undef PCRE2_SPTR
#define PCRE2_SPTR CUSTOM_SUBJECT_PTR
#endif
/* When checking for integer overflow, we need to handle large integers.
If a 64-bit integer type is available, we can use that.
Otherwise we have to cast to double, which of course requires floating point
arithmetic. Handle this by defining a macro for the appropriate type. */
#if defined INT64_MAX || defined int64_t
#define INT64_OR_DOUBLE int64_t
#else
#define INT64_OR_DOUBLE double
#endif
/* External (in the C sense) functions and tables that are private to the
libraries are always referenced using the PRIV macro. This makes it possible
for pcre2test.c to include some of the source files from the libraries using a
different PRIV definition to avoid name clashes. It also makes it clear in the
code that a non-static object is being referenced. */
#ifndef PRIV
#define PRIV(name) _pcre2_##name
#endif
/* When compiling for use with the Virtual Pascal compiler, these functions
need to have their names changed. PCRE2 must be compiled with the -DVPCOMPAT
option on the command line. */
#ifdef VPCOMPAT
#define strlen(s) _strlen(s)
#define strncmp(s1,s2,m) _strncmp(s1,s2,m)
#define memcmp(s,c,n) _memcmp(s,c,n)
#define memcpy(d,s,n) _memcpy(d,s,n)
#define memmove(d,s,n) _memmove(d,s,n)
#define memset(s,c,n) _memset(s,c,n)
#else /* VPCOMPAT */
/* Otherwise, to cope with SunOS4 and other systems that lack memmove(), define
a macro that calls an emulating function. */
#ifndef HAVE_MEMMOVE
#undef memmove /* Some systems may have a macro */
#define memmove(a, b, c) PRIV(memmove)(a, b, c)
#endif /* not HAVE_MEMMOVE */
#endif /* not VPCOMPAT */
/* This is an unsigned int value that no UTF character can ever have, as
Unicode doesn't go beyond 0x0010ffff. */
#define NOTACHAR 0xffffffff
/* This is the largest valid UTF/Unicode code point. */
#define MAX_UTF_CODE_POINT 0x10ffff
/* Compile-time positive error numbers (all except UTF errors, which are
negative) start at this value. It should probably never be changed, in case
some application is checking for specific numbers. There is a copy of this
#define in pcre2posix.c (which now no longer includes this file). Ideally, a
way of having a single definition should be found, but as the number is
unlikely to change, this is not a pressing issue. The original reason for
having a base other than 0 was to keep the absolute values of compile-time and
run-time error numbers numerically different, but in the event the code does
not rely on this. */
#define COMPILE_ERROR_BASE 100
/* The initial frames vector for remembering pcre2_match() backtracking points
is allocated on the heap, of this size (bytes) or ten times the frame size if
larger, unless the heap limit is smaller. Typical frame sizes are a few hundred
bytes (it depends on the number of capturing parentheses) so 20KiB handles
quite a few frames. A larger vector on the heap is obtained for matches that
need more frames, subject to the heap limit. */
#define START_FRAMES_SIZE 20480
/* For DFA matching, an initial internal workspace vector is allocated on the
stack. The heap is used only if this turns out to be too small. */
#define DFA_START_RWS_SIZE 30720
/* Define the default BSR convention. */
#ifdef BSR_ANYCRLF
#define BSR_DEFAULT PCRE2_BSR_ANYCRLF
#else
#define BSR_DEFAULT PCRE2_BSR_UNICODE
#endif
/* ---------------- Basic UTF-8 macros ---------------- */
/* These UTF-8 macros are always defined because they are used in pcre2test for
handling wide characters in 16-bit and 32-bit modes, even if an 8-bit library
is not supported. */
/* Tests whether a UTF-8 code point needs extra bytes to decode. */
#define HASUTF8EXTRALEN(c) ((c) >= 0xc0)
/* The following macros were originally written in the form of loops that used
data from the tables whose names start with PRIV(utf8_table). They were
rewritten by a user so as not to use loops, because in some environments this
gives a significant performance advantage, and it seems never to do any harm.
*/
/* Base macro to pick up the remaining bytes of a UTF-8 character, not
advancing the pointer. */
#define GETUTF8(c, eptr) \
{ \
if ((c & 0x20u) == 0) \
c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
else if ((c & 0x10u) == 0) \
c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
else if ((c & 0x08u) == 0) \
c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
else if ((c & 0x04u) == 0) \
c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
(eptr[4] & 0x3fu); \
else \
c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
}
/* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
the pointer. */
#define GETUTF8INC(c, eptr) \
{ \
if ((c & 0x20u) == 0) \
c = ((c & 0x1fu) << 6) | (*eptr++ & 0x3fu); \
else if ((c & 0x10u) == 0) \
{ \
c = ((c & 0x0fu) << 12) | ((*eptr & 0x3fu) << 6) | (eptr[1] & 0x3fu); \
eptr += 2; \
} \
else if ((c & 0x08u) == 0) \
{ \
c = ((c & 0x07u) << 18) | ((*eptr & 0x3fu) << 12) | \
((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
eptr += 3; \
} \
else if ((c & 0x04u) == 0) \
{ \
c = ((c & 0x03u) << 24) | ((*eptr & 0x3fu) << 18) | \
((eptr[1] & 0x3fu) << 12) | ((eptr[2] & 0x3fu) << 6) | \
(eptr[3] & 0x3fu); \
eptr += 4; \
} \
else \
{ \
c = ((c & 0x01u) << 30) | ((*eptr & 0x3fu) << 24) | \
((eptr[1] & 0x3fu) << 18) | ((eptr[2] & 0x3fu) << 12) | \
((eptr[3] & 0x3fu) << 6) | (eptr[4] & 0x3fu); \
eptr += 5; \
} \
}
/* Base macro to pick up the remaining bytes of a UTF-8 character, not
advancing the pointer, incrementing the length. */
#define GETUTF8LEN(c, eptr, len) \
{ \
if ((c & 0x20u) == 0) \
{ \
c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
len++; \
} \
else if ((c & 0x10u) == 0) \
{ \
c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
len += 2; \
} \
else if ((c & 0x08u) == 0) \
{\
c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
len += 3; \
} \
else if ((c & 0x04u) == 0) \
{ \
c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
(eptr[4] & 0x3fu); \
len += 4; \
} \
else \
{\
c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
len += 5; \
} \
}
/* --------------- Whitespace macros ---------------- */
/* Tests for Unicode horizontal and vertical whitespace characters must check a
number of different values. Using a switch statement for this generates the
fastest code (no loop, no memory access), and there are several places in the
interpreter code where this happens. In order to ensure that all the case lists
remain in step, we use macros so that there is only one place where the lists
are defined.
These values are also required as lists in pcre2_compile.c when processing \h,
\H, \v and \V in a character class. The lists are defined in pcre2_tables.c,
but macros that define the values are here so that all the definitions are
together. The lists must be in ascending character order, terminated by
NOTACHAR (which is 0xffffffff).
Any changes should ensure that the various macros are kept in step with each
other. NOTE: The values also appear in pcre2_jit_compile.c. */
/* -------------- ASCII/Unicode environments -------------- */
#ifndef EBCDIC
/* Character U+180E (Mongolian Vowel Separator) is not included in the list of
spaces in the Unicode file PropList.txt, and Perl does not recognize it as a
space. However, in many other sources it is listed as a space and has been in
PCRE (both APIs) for a long time. */
#define HSPACE_LIST \
CHAR_HT, CHAR_SPACE, CHAR_NBSP, \
0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \
0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \
NOTACHAR
#define HSPACE_MULTIBYTE_CASES \
case 0x1680: /* OGHAM SPACE MARK */ \
case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \
case 0x2000: /* EN QUAD */ \
case 0x2001: /* EM QUAD */ \
case 0x2002: /* EN SPACE */ \
case 0x2003: /* EM SPACE */ \
case 0x2004: /* THREE-PER-EM SPACE */ \
case 0x2005: /* FOUR-PER-EM SPACE */ \
case 0x2006: /* SIX-PER-EM SPACE */ \
case 0x2007: /* FIGURE SPACE */ \
case 0x2008: /* PUNCTUATION SPACE */ \
case 0x2009: /* THIN SPACE */ \
case 0x200A: /* HAIR SPACE */ \
case 0x202f: /* NARROW NO-BREAK SPACE */ \
case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \
case 0x3000 /* IDEOGRAPHIC SPACE */
#define HSPACE_BYTE_CASES \
case CHAR_HT: \
case CHAR_SPACE: \
case CHAR_NBSP
#define HSPACE_CASES \
HSPACE_BYTE_CASES: \
HSPACE_MULTIBYTE_CASES
#define VSPACE_LIST \
CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR
#define VSPACE_MULTIBYTE_CASES \
case 0x2028: /* LINE SEPARATOR */ \
case 0x2029 /* PARAGRAPH SEPARATOR */
#define VSPACE_BYTE_CASES \
case CHAR_LF: \
case CHAR_VT: \
case CHAR_FF: \
case CHAR_CR: \
case CHAR_NEL
#define VSPACE_CASES \
VSPACE_BYTE_CASES: \
VSPACE_MULTIBYTE_CASES
/* -------------- EBCDIC environments -------------- */
#else
#define HSPACE_LIST CHAR_HT, CHAR_SPACE, CHAR_NBSP, NOTACHAR
#define HSPACE_BYTE_CASES \
case CHAR_HT: \
case CHAR_SPACE: \
case CHAR_NBSP
#define HSPACE_CASES HSPACE_BYTE_CASES
#ifdef EBCDIC_NL25
#define VSPACE_LIST \
CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR
#else
#define VSPACE_LIST \
CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR
#endif
#define VSPACE_BYTE_CASES \
case CHAR_LF: \
case CHAR_VT: \
case CHAR_FF: \
case CHAR_CR: \
case CHAR_NEL
#define VSPACE_CASES VSPACE_BYTE_CASES
#endif /* EBCDIC */
/* -------------- End of whitespace macros -------------- */
/* PCRE2 is able to support several different kinds of newline (CR, LF, CRLF,
"any" and "anycrlf" at present). The following macros are used to package up
testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
modules to indicate in which datablock the parameters exist, and what the
start/end of string field names are. */
#define NLTYPE_FIXED 0 /* Newline is a fixed length string */
#define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
#define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
/* This macro checks for a newline at the given position */
#define IS_NEWLINE(p) \
((NLBLOCK->nltype != NLTYPE_FIXED)? \
((p) < NLBLOCK->PSEND && \
PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \
&(NLBLOCK->nllen), utf)) \
: \
((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
UCHAR21TEST(p) == NLBLOCK->nl[0] && \
(NLBLOCK->nllen == 1 || UCHAR21TEST(p+1) == NLBLOCK->nl[1]) \
) \
)
/* This macro checks for a newline immediately preceding the given position */
#define WAS_NEWLINE(p) \
((NLBLOCK->nltype != NLTYPE_FIXED)? \
((p) > NLBLOCK->PSSTART && \
PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
&(NLBLOCK->nllen), utf)) \
: \
((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
UCHAR21TEST(p - NLBLOCK->nllen) == NLBLOCK->nl[0] && \
(NLBLOCK->nllen == 1 || UCHAR21TEST(p - NLBLOCK->nllen + 1) == NLBLOCK->nl[1]) \
) \
)
/* Private flags containing information about the compiled pattern. The first
three must not be changed, because whichever is set is actually the number of
bytes in a code unit in that mode. */
#define PCRE2_MODE8 0x00000001u /* compiled in 8 bit mode */
#define PCRE2_MODE16 0x00000002u /* compiled in 16 bit mode */
#define PCRE2_MODE32 0x00000004u /* compiled in 32 bit mode */
#define PCRE2_FIRSTSET 0x00000010u /* first_code unit is set */
#define PCRE2_FIRSTCASELESS 0x00000020u /* caseless first code unit */
#define PCRE2_FIRSTMAPSET 0x00000040u /* bitmap of first code units is set */
#define PCRE2_LASTSET 0x00000080u /* last code unit is set */
#define PCRE2_LASTCASELESS 0x00000100u /* caseless last code unit */
#define PCRE2_STARTLINE 0x00000200u /* start after \n for multiline */
#define PCRE2_JCHANGED 0x00000400u /* j option used in pattern */
#define PCRE2_HASCRORLF 0x00000800u /* explicit \r or \n in pattern */
#define PCRE2_HASTHEN 0x00001000u /* pattern contains (*THEN) */
#define PCRE2_MATCH_EMPTY 0x00002000u /* pattern can match empty string */
#define PCRE2_BSR_SET 0x00004000u /* BSR was set in the pattern */
#define PCRE2_NL_SET 0x00008000u /* newline was set in the pattern */
#define PCRE2_NOTEMPTY_SET 0x00010000u /* (*NOTEMPTY) used ) keep */
#define PCRE2_NE_ATST_SET 0x00020000u /* (*NOTEMPTY_ATSTART) used) together */
#define PCRE2_DEREF_TABLES 0x00040000u /* release character tables */
#define PCRE2_NOJIT 0x00080000u /* (*NOJIT) used */
#define PCRE2_HASBKPORX 0x00100000u /* contains \P, \p, or \X */
#define PCRE2_DUPCAPUSED 0x00200000u /* contains (?| */
#define PCRE2_HASBKC 0x00400000u /* contains \C */
#define PCRE2_HASACCEPT 0x00800000u /* contains (*ACCEPT) */
#define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32)
/* Values for the matchedby field in a match data block. */
enum { PCRE2_MATCHEDBY_INTERPRETER, /* pcre2_match() */
PCRE2_MATCHEDBY_DFA_INTERPRETER, /* pcre2_dfa_match() */
PCRE2_MATCHEDBY_JIT }; /* pcre2_jit_match() */
/* Values for the flags field in a match data block. */
#define PCRE2_MD_COPIED_SUBJECT 0x01u
/* Magic number to provide a small check against being handed junk. */
#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
/* The maximum remaining length of subject we are prepared to search for a
req_unit match from an anchored pattern. In 8-bit mode, memchr() is used and is
much faster than the search loop that has to be used in 16-bit and 32-bit
modes. */
#if PCRE2_CODE_UNIT_WIDTH == 8
#define REQ_CU_MAX 5000
#else
#define REQ_CU_MAX 2000
#endif
/* The maximum nesting depth for Unicode character class sets.
Currently fixed. Warning: the interpreter relies on this so it can encode
the operand stack in a uint32_t. A nesting limit of 15 implies (15*2+1)=31
stack operands required, due to the fact that we have two (and only two)
levels of operator precedence. In the UTS#18 syntax, you can write 'x&&y[z]'
and in Perl syntax you can write '(?[ x - y & (z) ])', both of which imply
pushing the match results for x & y to the stack. */
#define ECLASS_NEST_LIMIT 15
/* Offsets for the bitmap tables in the cbits set of tables. Each table
contains a set of bits for a class map. Some classes are built by combining
these tables. */
#define cbit_space 0 /* [:space:] or \s */
#define cbit_xdigit 32 /* [:xdigit:] */
#define cbit_digit 64 /* [:digit:] or \d */
#define cbit_upper 96 /* [:upper:] */
#define cbit_lower 128 /* [:lower:] */
#define cbit_word 160 /* [:word:] or \w */
#define cbit_graph 192 /* [:graph:] */
#define cbit_print 224 /* [:print:] */
#define cbit_punct 256 /* [:punct:] */
#define cbit_cntrl 288 /* [:cntrl:] */
#define cbit_length 320 /* Length of the cbits table */
/* Bit definitions for entries in the ctypes table. Do not change these values
without checking pcre2_jit_compile.c, which has an assertion to ensure that
ctype_word has the value 16. */
#define ctype_space 0x01
#define ctype_letter 0x02
#define ctype_lcletter 0x04
#define ctype_digit 0x08
#define ctype_word 0x10 /* alphanumeric or '_' */
/* Offsets of the various tables from the base tables pointer, and
total length of the tables. */
#define lcc_offset 0 /* Lower case */
#define fcc_offset 256 /* Flip case */
#define cbits_offset 512 /* Character classes */
#define ctypes_offset (cbits_offset + cbit_length) /* Character types */
#define TABLES_LENGTH (ctypes_offset + 256)
/* Private flags used in compile_context.optimization_flags */
#define PCRE2_OPTIM_AUTO_POSSESS 0x00000001u
#define PCRE2_OPTIM_DOTSTAR_ANCHOR 0x00000002u
#define PCRE2_OPTIM_START_OPTIMIZE 0x00000004u
#define PCRE2_OPTIMIZATION_ALL 0x00000007u
/* -------------------- Character and string names ------------------------ */
/* If PCRE2 is to support UTF-8 on EBCDIC platforms, we cannot use normal
character constants like '*' because the compiler would emit their EBCDIC code,
which is different from their ASCII/UTF-8 code. Instead we define macros for
the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
is enabled. When UTF-8 support is not enabled, the definitions use character
literals. Both character and string versions of each character are needed, and
there are some longer strings as well.
This means that, on EBCDIC platforms, the PCRE2 library can handle either
EBCDIC, or UTF-8, but not both. To support both in the same compiled library
would need different lookups depending on whether PCRE2_UTF was set or not.
This would make it impossible to use characters in switch/case statements,
which would reduce performance. For a theoretical use (which nobody has asked
for) in a minority area (EBCDIC platforms), this is not sensible. Any
application that did need both could compile two versions of the library, using
macros to give the functions distinct names. */
#ifndef SUPPORT_UNICODE
/* UTF-8 support is not enabled; use the platform-dependent character literals
so that PCRE2 works in both ASCII and EBCDIC environments, but only in non-UTF
mode. Newline characters are problematic in EBCDIC. Though it has CR and LF
characters, a common practice has been to use its NL (0x15) character as the
line terminator in C-like processing environments. However, sometimes the LF
(0x25) character is used instead, according to this Unicode document:
http://unicode.org/standard/reports/tr13/tr13-5.html
PCRE2 defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25
instead. Whichever is *not* chosen is defined as NEL.
In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the
same code point. */
#ifdef EBCDIC
#ifndef EBCDIC_NL25
#define CHAR_NL '\x15'
#define CHAR_NEL '\x25'
#define STR_NL "\x15"
#define STR_NEL "\x25"
#else
#define CHAR_NL '\x25'
#define CHAR_NEL '\x15'
#define STR_NL "\x25"
#define STR_NEL "\x15"
#endif
#define CHAR_LF CHAR_NL
#define STR_LF STR_NL
#define CHAR_ESC '\047'
#define CHAR_DEL '\007'
#define CHAR_NBSP ((unsigned char)'\x41')
#define STR_ESC "\047"
#define STR_DEL "\007"
#else /* Not EBCDIC */
/* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for
compatibility. NEL is the Unicode newline character; make sure it is
a positive value. */
#define CHAR_LF '\n'
#define CHAR_NL CHAR_LF
#define CHAR_NEL ((unsigned char)'\x85')
#define CHAR_ESC '\033'
#define CHAR_DEL '\177'
#define CHAR_NBSP ((unsigned char)'\xa0')
#define STR_LF "\n"
#define STR_NL STR_LF
#define STR_NEL "\x85"
#define STR_ESC "\033"
#define STR_DEL "\177"
#endif /* EBCDIC */
/* The remaining definitions work in both environments. */
#define CHAR_NUL '\0'
#define CHAR_HT '\t'
#define CHAR_VT '\v'
#define CHAR_FF '\f'
#define CHAR_CR '\r'
#define CHAR_BS '\b'
#define CHAR_BEL '\a'
#define CHAR_SPACE ' '
#define CHAR_EXCLAMATION_MARK '!'
#define CHAR_QUOTATION_MARK '"'
#define CHAR_NUMBER_SIGN '#'
#define CHAR_DOLLAR_SIGN '$'
#define CHAR_PERCENT_SIGN '%'
#define CHAR_AMPERSAND '&'
#define CHAR_APOSTROPHE '\''
#define CHAR_LEFT_PARENTHESIS '('
#define CHAR_RIGHT_PARENTHESIS ')'
#define CHAR_ASTERISK '*'
#define CHAR_PLUS '+'
#define CHAR_COMMA ','
#define CHAR_MINUS '-'
#define CHAR_DOT '.'
#define CHAR_SLASH '/'
#define CHAR_0 '0'
#define CHAR_1 '1'
#define CHAR_2 '2'
#define CHAR_3 '3'
#define CHAR_4 '4'
#define CHAR_5 '5'
#define CHAR_6 '6'
#define CHAR_7 '7'
#define CHAR_8 '8'
#define CHAR_9 '9'
#define CHAR_COLON ':'
#define CHAR_SEMICOLON ';'
#define CHAR_LESS_THAN_SIGN '<'
#define CHAR_EQUALS_SIGN '='
#define CHAR_GREATER_THAN_SIGN '>'
#define CHAR_QUESTION_MARK '?'
#define CHAR_COMMERCIAL_AT '@'
#define CHAR_A 'A'
#define CHAR_B 'B'
#define CHAR_C 'C'
#define CHAR_D 'D'
#define CHAR_E 'E'
#define CHAR_F 'F'
#define CHAR_G 'G'
#define CHAR_H 'H'
#define CHAR_I 'I'
#define CHAR_J 'J'
#define CHAR_K 'K'
#define CHAR_L 'L'
#define CHAR_M 'M'
#define CHAR_N 'N'
#define CHAR_O 'O'
#define CHAR_P 'P'
#define CHAR_Q 'Q'
#define CHAR_R 'R'
#define CHAR_S 'S'
#define CHAR_T 'T'
#define CHAR_U 'U'
#define CHAR_V 'V'
#define CHAR_W 'W'
#define CHAR_X 'X'
#define CHAR_Y 'Y'
#define CHAR_Z 'Z'
#define CHAR_LEFT_SQUARE_BRACKET '['
#define CHAR_BACKSLASH '\\'
#define CHAR_RIGHT_SQUARE_BRACKET ']'
#define CHAR_CIRCUMFLEX_ACCENT '^'
#define CHAR_UNDERSCORE '_'
#define CHAR_GRAVE_ACCENT '`'
#define CHAR_a 'a'
#define CHAR_b 'b'
#define CHAR_c 'c'
#define CHAR_d 'd'
#define CHAR_e 'e'
#define CHAR_f 'f'
#define CHAR_g 'g'
#define CHAR_h 'h'
#define CHAR_i 'i'
#define CHAR_j 'j'
#define CHAR_k 'k'
#define CHAR_l 'l'
#define CHAR_m 'm'
#define CHAR_n 'n'
#define CHAR_o 'o'
#define CHAR_p 'p'
#define CHAR_q 'q'
#define CHAR_r 'r'
#define CHAR_s 's'
#define CHAR_t 't'
#define CHAR_u 'u'
#define CHAR_v 'v'
#define CHAR_w 'w'
#define CHAR_x 'x'
#define CHAR_y 'y'
#define CHAR_z 'z'
#define CHAR_LEFT_CURLY_BRACKET '{'
#define CHAR_VERTICAL_LINE '|'
#define CHAR_RIGHT_CURLY_BRACKET '}'
#define CHAR_TILDE '~'
#define STR_HT "\t"
#define STR_VT "\v"
#define STR_FF "\f"
#define STR_CR "\r"
#define STR_BS "\b"
#define STR_BEL "\a"
#define STR_SPACE " "
#define STR_EXCLAMATION_MARK "!"
#define STR_QUOTATION_MARK "\""
#define STR_NUMBER_SIGN "#"
#define STR_DOLLAR_SIGN "$"
#define STR_PERCENT_SIGN "%"
#define STR_AMPERSAND "&"
#define STR_APOSTROPHE "'"
#define STR_LEFT_PARENTHESIS "("
#define STR_RIGHT_PARENTHESIS ")"
#define STR_ASTERISK "*"
#define STR_PLUS "+"
#define STR_COMMA ","
#define STR_MINUS "-"
#define STR_DOT "."
#define STR_SLASH "/"
#define STR_0 "0"
#define STR_1 "1"
#define STR_2 "2"
#define STR_3 "3"
#define STR_4 "4"
#define STR_5 "5"
#define STR_6 "6"
#define STR_7 "7"
#define STR_8 "8"
#define STR_9 "9"
#define STR_COLON ":"
#define STR_SEMICOLON ";"
#define STR_LESS_THAN_SIGN "<"
#define STR_EQUALS_SIGN "="
#define STR_GREATER_THAN_SIGN ">"
#define STR_QUESTION_MARK "?"
#define STR_COMMERCIAL_AT "@"
#define STR_A "A"
#define STR_B "B"
#define STR_C "C"
#define STR_D "D"
#define STR_E "E"
#define STR_F "F"
#define STR_G "G"
#define STR_H "H"
#define STR_I "I"
#define STR_J "J"
#define STR_K "K"
#define STR_L "L"
#define STR_M "M"
#define STR_N "N"
#define STR_O "O"
#define STR_P "P"
#define STR_Q "Q"
#define STR_R "R"
#define STR_S "S"
#define STR_T "T"
#define STR_U "U"
#define STR_V "V"
#define STR_W "W"
#define STR_X "X"
#define STR_Y "Y"
#define STR_Z "Z"
#define STR_LEFT_SQUARE_BRACKET "["
#define STR_BACKSLASH "\\"
#define STR_RIGHT_SQUARE_BRACKET "]"
#define STR_CIRCUMFLEX_ACCENT "^"
#define STR_UNDERSCORE "_"
#define STR_GRAVE_ACCENT "`"
#define STR_a "a"
#define STR_b "b"
#define STR_c "c"
#define STR_d "d"
#define STR_e "e"
#define STR_f "f"
#define STR_g "g"
#define STR_h "h"
#define STR_i "i"
#define STR_j "j"
#define STR_k "k"
#define STR_l "l"
#define STR_m "m"
#define STR_n "n"
#define STR_o "o"
#define STR_p "p"
#define STR_q "q"
#define STR_r "r"
#define STR_s "s"
#define STR_t "t"
#define STR_u "u"
#define STR_v "v"
#define STR_w "w"
#define STR_x "x"
#define STR_y "y"
#define STR_z "z"
#define STR_LEFT_CURLY_BRACKET "{"
#define STR_VERTICAL_LINE "|"
#define STR_RIGHT_CURLY_BRACKET "}"
#define STR_TILDE "~"
#define STRING_ACCEPT0 "ACCEPT\0"
#define STRING_COMMIT0 "COMMIT\0"
#define STRING_F0 "F\0"
#define STRING_FAIL0 "FAIL\0"
#define STRING_MARK0 "MARK\0"
#define STRING_PRUNE0 "PRUNE\0"
#define STRING_SKIP0 "SKIP\0"
#define STRING_THEN "THEN"
#define STRING_atomic0 "atomic\0"
#define STRING_pla0 "pla\0"
#define STRING_plb0 "plb\0"
#define STRING_napla0 "napla\0"
#define STRING_naplb0 "naplb\0"
#define STRING_nla0 "nla\0"
#define STRING_nlb0 "nlb\0"
#define STRING_scs0 "scs\0"
#define STRING_sr0 "sr\0"
#define STRING_asr0 "asr\0"
#define STRING_positive_lookahead0 "positive_lookahead\0"
#define STRING_positive_lookbehind0 "positive_lookbehind\0"
#define STRING_non_atomic_positive_lookahead0 "non_atomic_positive_lookahead\0"
#define STRING_non_atomic_positive_lookbehind0 "non_atomic_positive_lookbehind\0"
#define STRING_negative_lookahead0 "negative_lookahead\0"
#define STRING_negative_lookbehind0 "negative_lookbehind\0"
#define STRING_script_run0 "script_run\0"
#define STRING_atomic_script_run "atomic_script_run"
#define STRING_scan_substring0 "scan_substring\0"
#define STRING_alpha0 "alpha\0"
#define STRING_lower0 "lower\0"
#define STRING_upper0 "upper\0"
#define STRING_alnum0 "alnum\0"
#define STRING_ascii0 "ascii\0"
#define STRING_blank0 "blank\0"
#define STRING_cntrl0 "cntrl\0"
#define STRING_digit0 "digit\0"
#define STRING_graph0 "graph\0"
#define STRING_print0 "print\0"
#define STRING_punct0 "punct\0"
#define STRING_space0 "space\0"
#define STRING_word0 "word\0"
#define STRING_xdigit "xdigit"
#define STRING_DEFINE "DEFINE"
#define STRING_VERSION "VERSION"
#define STRING_WEIRD_STARTWORD "[:<:]]"
#define STRING_WEIRD_ENDWORD "[:>:]]"
#define STRING_CR_RIGHTPAR "CR)"
#define STRING_LF_RIGHTPAR "LF)"
#define STRING_CRLF_RIGHTPAR "CRLF)"
#define STRING_ANY_RIGHTPAR "ANY)"
#define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)"
#define STRING_NUL_RIGHTPAR "NUL)"
#define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
#define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
#define STRING_UTF8_RIGHTPAR "UTF8)"
#define STRING_UTF16_RIGHTPAR "UTF16)"
#define STRING_UTF32_RIGHTPAR "UTF32)"
#define STRING_UTF_RIGHTPAR "UTF)"
#define STRING_UCP_RIGHTPAR "UCP)"
#define STRING_NO_AUTO_POSSESS_RIGHTPAR "NO_AUTO_POSSESS)"
#define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR "NO_DOTSTAR_ANCHOR)"
#define STRING_NO_JIT_RIGHTPAR "NO_JIT)"
#define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)"
#define STRING_NOTEMPTY_RIGHTPAR "NOTEMPTY)"
#define STRING_NOTEMPTY_ATSTART_RIGHTPAR "NOTEMPTY_ATSTART)"
#define STRING_CASELESS_RESTRICT_RIGHTPAR "CASELESS_RESTRICT)"
#define STRING_TURKISH_CASING_RIGHTPAR "TURKISH_CASING)"
#define STRING_LIMIT_HEAP_EQ "LIMIT_HEAP="
#define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH="
#define STRING_LIMIT_DEPTH_EQ "LIMIT_DEPTH="
#define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION="
#define STRING_MARK "MARK"