1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker //
4*0e209d39SAndroid Build Coastguard Worker // Copyright (C) 2002-2015 International Business Machines Corporation
5*0e209d39SAndroid Build Coastguard Worker // and others. All rights reserved.
6*0e209d39SAndroid Build Coastguard Worker //
7*0e209d39SAndroid Build Coastguard Worker // file: regeximp.h
8*0e209d39SAndroid Build Coastguard Worker //
9*0e209d39SAndroid Build Coastguard Worker // ICU Regular Expressions,
10*0e209d39SAndroid Build Coastguard Worker // Definitions of constant values used in the compiled form of
11*0e209d39SAndroid Build Coastguard Worker // a regular expression pattern.
12*0e209d39SAndroid Build Coastguard Worker //
13*0e209d39SAndroid Build Coastguard Worker
14*0e209d39SAndroid Build Coastguard Worker #ifndef _REGEXIMP_H
15*0e209d39SAndroid Build Coastguard Worker #define _REGEXIMP_H
16*0e209d39SAndroid Build Coastguard Worker
17*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
18*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
19*0e209d39SAndroid Build Coastguard Worker #include "unicode/uniset.h"
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/utext.h"
21*0e209d39SAndroid Build Coastguard Worker
22*0e209d39SAndroid Build Coastguard Worker #include "cmemory.h"
23*0e209d39SAndroid Build Coastguard Worker #include "ucase.h"
24*0e209d39SAndroid Build Coastguard Worker
25*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
26*0e209d39SAndroid Build Coastguard Worker
27*0e209d39SAndroid Build Coastguard Worker // For debugging, define REGEX_DEBUG
28*0e209d39SAndroid Build Coastguard Worker // To define with configure,
29*0e209d39SAndroid Build Coastguard Worker // CPPFLAGS="-DREGEX_DEBUG" ./runConfigureICU --enable-debug --disable-release Linux
30*0e209d39SAndroid Build Coastguard Worker
31*0e209d39SAndroid Build Coastguard Worker #ifdef REGEX_DEBUG
32*0e209d39SAndroid Build Coastguard Worker //
33*0e209d39SAndroid Build Coastguard Worker // debugging options. Enable one or more of the three #defines immediately following
34*0e209d39SAndroid Build Coastguard Worker //
35*0e209d39SAndroid Build Coastguard Worker
36*0e209d39SAndroid Build Coastguard Worker //#define REGEX_SCAN_DEBUG
37*0e209d39SAndroid Build Coastguard Worker #define REGEX_DUMP_DEBUG
38*0e209d39SAndroid Build Coastguard Worker #define REGEX_RUN_DEBUG
39*0e209d39SAndroid Build Coastguard Worker
40*0e209d39SAndroid Build Coastguard Worker // End of #defines intended to be directly set.
41*0e209d39SAndroid Build Coastguard Worker
42*0e209d39SAndroid Build Coastguard Worker #include <stdio.h>
43*0e209d39SAndroid Build Coastguard Worker #endif
44*0e209d39SAndroid Build Coastguard Worker
45*0e209d39SAndroid Build Coastguard Worker #ifdef REGEX_SCAN_DEBUG
46*0e209d39SAndroid Build Coastguard Worker #define REGEX_SCAN_DEBUG_PRINTF(a) printf a
47*0e209d39SAndroid Build Coastguard Worker #else
48*0e209d39SAndroid Build Coastguard Worker #define REGEX_SCAN_DEBUG_PRINTF(a)
49*0e209d39SAndroid Build Coastguard Worker #endif
50*0e209d39SAndroid Build Coastguard Worker
51*0e209d39SAndroid Build Coastguard Worker
52*0e209d39SAndroid Build Coastguard Worker //
53*0e209d39SAndroid Build Coastguard Worker // Opcode types In the compiled form of the regexp, these are the type, or opcodes,
54*0e209d39SAndroid Build Coastguard Worker // of the entries.
55*0e209d39SAndroid Build Coastguard Worker //
56*0e209d39SAndroid Build Coastguard Worker enum {
57*0e209d39SAndroid Build Coastguard Worker URX_RESERVED_OP = 0, // For multi-operand ops, most non-first words.
58*0e209d39SAndroid Build Coastguard Worker URX_RESERVED_OP_N = 255, // For multi-operand ops, negative operand values.
59*0e209d39SAndroid Build Coastguard Worker URX_BACKTRACK = 1, // Force a backtrack, as if a match test had failed.
60*0e209d39SAndroid Build Coastguard Worker URX_END = 2,
61*0e209d39SAndroid Build Coastguard Worker URX_ONECHAR = 3, // Value field is the 21 bit unicode char to match
62*0e209d39SAndroid Build Coastguard Worker URX_STRING = 4, // Value field is index of string start
63*0e209d39SAndroid Build Coastguard Worker URX_STRING_LEN = 5, // Value field is string length (code units)
64*0e209d39SAndroid Build Coastguard Worker URX_STATE_SAVE = 6, // Value field is pattern position to push
65*0e209d39SAndroid Build Coastguard Worker URX_NOP = 7,
66*0e209d39SAndroid Build Coastguard Worker URX_START_CAPTURE = 8, // Value field is capture group number.
67*0e209d39SAndroid Build Coastguard Worker URX_END_CAPTURE = 9, // Value field is capture group number
68*0e209d39SAndroid Build Coastguard Worker URX_STATIC_SETREF = 10, // Value field is index of set in array of sets.
69*0e209d39SAndroid Build Coastguard Worker URX_SETREF = 11, // Value field is index of set in array of sets.
70*0e209d39SAndroid Build Coastguard Worker URX_DOTANY = 12,
71*0e209d39SAndroid Build Coastguard Worker URX_JMP = 13, // Value field is destination position in
72*0e209d39SAndroid Build Coastguard Worker // the pattern.
73*0e209d39SAndroid Build Coastguard Worker URX_FAIL = 14, // Stop match operation, No match.
74*0e209d39SAndroid Build Coastguard Worker
75*0e209d39SAndroid Build Coastguard Worker URX_JMP_SAV = 15, // Operand: JMP destination location
76*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_B = 16, // Value field: 0: \b 1: \B
77*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_G = 17,
78*0e209d39SAndroid Build Coastguard Worker URX_JMP_SAV_X = 18, // Conditional JMP_SAV,
79*0e209d39SAndroid Build Coastguard Worker // Used in (x)+, breaks loop on zero length match.
80*0e209d39SAndroid Build Coastguard Worker // Operand: Jmp destination.
81*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_X = 19,
82*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_Z = 20, // \z Unconditional end of line.
83*0e209d39SAndroid Build Coastguard Worker
84*0e209d39SAndroid Build Coastguard Worker URX_DOTANY_ALL = 21, // ., in the . matches any mode.
85*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_D = 22, // Value field: 0: \d 1: \D
86*0e209d39SAndroid Build Coastguard Worker URX_CARET = 23, // Value field: 1: multi-line mode.
87*0e209d39SAndroid Build Coastguard Worker URX_DOLLAR = 24, // Also for \Z
88*0e209d39SAndroid Build Coastguard Worker
89*0e209d39SAndroid Build Coastguard Worker URX_CTR_INIT = 25, // Counter Inits for {Interval} loops.
90*0e209d39SAndroid Build Coastguard Worker URX_CTR_INIT_NG = 26, // 2 kinds, normal and non-greedy.
91*0e209d39SAndroid Build Coastguard Worker // These are 4 word opcodes. See description.
92*0e209d39SAndroid Build Coastguard Worker // First Operand: Data loc of counter variable
93*0e209d39SAndroid Build Coastguard Worker // 2nd Operand: Pat loc of the URX_CTR_LOOPx
94*0e209d39SAndroid Build Coastguard Worker // at the end of the loop.
95*0e209d39SAndroid Build Coastguard Worker // 3rd Operand: Minimum count.
96*0e209d39SAndroid Build Coastguard Worker // 4th Operand: Max count, -1 for unbounded.
97*0e209d39SAndroid Build Coastguard Worker
98*0e209d39SAndroid Build Coastguard Worker URX_DOTANY_UNIX = 27, // '.' operator in UNIX_LINES mode, only \n marks end of line.
99*0e209d39SAndroid Build Coastguard Worker
100*0e209d39SAndroid Build Coastguard Worker URX_CTR_LOOP = 28, // Loop Ops for {interval} loops.
101*0e209d39SAndroid Build Coastguard Worker URX_CTR_LOOP_NG = 29, // Also in three flavors.
102*0e209d39SAndroid Build Coastguard Worker // Operand is loc of corresponding CTR_INIT.
103*0e209d39SAndroid Build Coastguard Worker
104*0e209d39SAndroid Build Coastguard Worker URX_CARET_M_UNIX = 30, // '^' operator, test for start of line in multi-line
105*0e209d39SAndroid Build Coastguard Worker // plus UNIX_LINES mode.
106*0e209d39SAndroid Build Coastguard Worker
107*0e209d39SAndroid Build Coastguard Worker URX_RELOC_OPRND = 31, // Operand value in multi-operand ops that refers
108*0e209d39SAndroid Build Coastguard Worker // back into compiled pattern code, and thus must
109*0e209d39SAndroid Build Coastguard Worker // be relocated when inserting/deleting ops in code.
110*0e209d39SAndroid Build Coastguard Worker
111*0e209d39SAndroid Build Coastguard Worker URX_STO_SP = 32, // Store the stack ptr. Operand is location within
112*0e209d39SAndroid Build Coastguard Worker // matcher data (not stack data) to store it.
113*0e209d39SAndroid Build Coastguard Worker URX_LD_SP = 33, // Load the stack pointer. Operand is location
114*0e209d39SAndroid Build Coastguard Worker // to load from.
115*0e209d39SAndroid Build Coastguard Worker URX_BACKREF = 34, // Back Reference. Parameter is the index of the
116*0e209d39SAndroid Build Coastguard Worker // capture group variables in the state stack frame.
117*0e209d39SAndroid Build Coastguard Worker URX_STO_INP_LOC = 35, // Store the input location. Operand is location
118*0e209d39SAndroid Build Coastguard Worker // within the matcher stack frame.
119*0e209d39SAndroid Build Coastguard Worker URX_JMPX = 36, // Conditional JMP.
120*0e209d39SAndroid Build Coastguard Worker // First Operand: JMP target location.
121*0e209d39SAndroid Build Coastguard Worker // Second Operand: Data location containing an
122*0e209d39SAndroid Build Coastguard Worker // input position. If current input position ==
123*0e209d39SAndroid Build Coastguard Worker // saved input position, FAIL rather than taking
124*0e209d39SAndroid Build Coastguard Worker // the JMP
125*0e209d39SAndroid Build Coastguard Worker URX_LA_START = 37, // Starting a LookAround expression.
126*0e209d39SAndroid Build Coastguard Worker // Save InputPos, SP and active region in static data.
127*0e209d39SAndroid Build Coastguard Worker // Operand: Static data offset for the save
128*0e209d39SAndroid Build Coastguard Worker URX_LA_END = 38, // Ending a Lookaround expression.
129*0e209d39SAndroid Build Coastguard Worker // Restore InputPos and Stack to saved values.
130*0e209d39SAndroid Build Coastguard Worker // Operand: Static data offset for saved data.
131*0e209d39SAndroid Build Coastguard Worker URX_ONECHAR_I = 39, // Test for case-insensitive match of a literal character.
132*0e209d39SAndroid Build Coastguard Worker // Operand: the literal char.
133*0e209d39SAndroid Build Coastguard Worker URX_STRING_I = 40, // Case insensitive string compare.
134*0e209d39SAndroid Build Coastguard Worker // First Operand: Index of start of string in string literals
135*0e209d39SAndroid Build Coastguard Worker // Second Operand (next word in compiled code):
136*0e209d39SAndroid Build Coastguard Worker // the length of the string.
137*0e209d39SAndroid Build Coastguard Worker URX_BACKREF_I = 41, // Case insensitive back reference.
138*0e209d39SAndroid Build Coastguard Worker // Parameter is the index of the
139*0e209d39SAndroid Build Coastguard Worker // capture group variables in the state stack frame.
140*0e209d39SAndroid Build Coastguard Worker URX_DOLLAR_M = 42, // $ in multi-line mode.
141*0e209d39SAndroid Build Coastguard Worker URX_CARET_M = 43, // ^ in multi-line mode.
142*0e209d39SAndroid Build Coastguard Worker URX_LB_START = 44, // LookBehind Start.
143*0e209d39SAndroid Build Coastguard Worker // Parameter is data location
144*0e209d39SAndroid Build Coastguard Worker URX_LB_CONT = 45, // LookBehind Continue.
145*0e209d39SAndroid Build Coastguard Worker // Param 0: the data location
146*0e209d39SAndroid Build Coastguard Worker // Param 1: The minimum length of the look-behind match
147*0e209d39SAndroid Build Coastguard Worker // Param 2: The max length of the look-behind match
148*0e209d39SAndroid Build Coastguard Worker URX_LB_END = 46, // LookBehind End.
149*0e209d39SAndroid Build Coastguard Worker // Parameter is the data location.
150*0e209d39SAndroid Build Coastguard Worker // Check that match ended at the right spot,
151*0e209d39SAndroid Build Coastguard Worker // Restore original input string len.
152*0e209d39SAndroid Build Coastguard Worker URX_LBN_CONT = 47, // Negative LookBehind Continue
153*0e209d39SAndroid Build Coastguard Worker // Param 0: the data location
154*0e209d39SAndroid Build Coastguard Worker // Param 1: The minimum length of the look-behind match
155*0e209d39SAndroid Build Coastguard Worker // Param 2: The max length of the look-behind match
156*0e209d39SAndroid Build Coastguard Worker // Param 3: The pattern loc following the look-behind block.
157*0e209d39SAndroid Build Coastguard Worker URX_LBN_END = 48, // Negative LookBehind end
158*0e209d39SAndroid Build Coastguard Worker // Parameter is the data location.
159*0e209d39SAndroid Build Coastguard Worker // Check that the match ended at the right spot.
160*0e209d39SAndroid Build Coastguard Worker URX_STAT_SETREF_N = 49, // Reference to a prebuilt set (e.g. \w), negated
161*0e209d39SAndroid Build Coastguard Worker // Operand is index of set in array of sets.
162*0e209d39SAndroid Build Coastguard Worker URX_LOOP_SR_I = 50, // Init a [set]* loop.
163*0e209d39SAndroid Build Coastguard Worker // Operand is the sets index in array of user sets.
164*0e209d39SAndroid Build Coastguard Worker URX_LOOP_C = 51, // Continue a [set]* or OneChar* loop.
165*0e209d39SAndroid Build Coastguard Worker // Operand is a matcher static data location.
166*0e209d39SAndroid Build Coastguard Worker // Must always immediately follow LOOP_x_I instruction.
167*0e209d39SAndroid Build Coastguard Worker URX_LOOP_DOT_I = 52, // .*, initialization of the optimized loop.
168*0e209d39SAndroid Build Coastguard Worker // Operand value:
169*0e209d39SAndroid Build Coastguard Worker // bit 0:
170*0e209d39SAndroid Build Coastguard Worker // 0: Normal (. doesn't match new-line) mode.
171*0e209d39SAndroid Build Coastguard Worker // 1: . matches new-line mode.
172*0e209d39SAndroid Build Coastguard Worker // bit 1: controls what new-lines are recognized by this operation.
173*0e209d39SAndroid Build Coastguard Worker // 0: All Unicode New-lines
174*0e209d39SAndroid Build Coastguard Worker // 1: UNIX_LINES, \u000a only.
175*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_BU = 53, // \b or \B in UREGEX_UWORD mode, using Unicode style
176*0e209d39SAndroid Build Coastguard Worker // word boundaries.
177*0e209d39SAndroid Build Coastguard Worker URX_DOLLAR_D = 54, // $ end of input test, in UNIX_LINES mode.
178*0e209d39SAndroid Build Coastguard Worker URX_DOLLAR_MD = 55, // $ end of input test, in MULTI_LINE and UNIX_LINES mode.
179*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_H = 56, // Value field: 0: \h 1: \H
180*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_R = 57, // Any line break sequence.
181*0e209d39SAndroid Build Coastguard Worker URX_BACKSLASH_V = 58 // Value field: 0: \v 1: \V
182*0e209d39SAndroid Build Coastguard Worker
183*0e209d39SAndroid Build Coastguard Worker };
184*0e209d39SAndroid Build Coastguard Worker
185*0e209d39SAndroid Build Coastguard Worker // Keep this list of opcode names in sync with the above enum
186*0e209d39SAndroid Build Coastguard Worker // Used for debug printing only.
187*0e209d39SAndroid Build Coastguard Worker #define URX_OPCODE_NAMES \
188*0e209d39SAndroid Build Coastguard Worker " ", \
189*0e209d39SAndroid Build Coastguard Worker "BACKTRACK", \
190*0e209d39SAndroid Build Coastguard Worker "END", \
191*0e209d39SAndroid Build Coastguard Worker "ONECHAR", \
192*0e209d39SAndroid Build Coastguard Worker "STRING", \
193*0e209d39SAndroid Build Coastguard Worker "STRING_LEN", \
194*0e209d39SAndroid Build Coastguard Worker "STATE_SAVE", \
195*0e209d39SAndroid Build Coastguard Worker "NOP", \
196*0e209d39SAndroid Build Coastguard Worker "START_CAPTURE", \
197*0e209d39SAndroid Build Coastguard Worker "END_CAPTURE", \
198*0e209d39SAndroid Build Coastguard Worker "URX_STATIC_SETREF", \
199*0e209d39SAndroid Build Coastguard Worker "SETREF", \
200*0e209d39SAndroid Build Coastguard Worker "DOTANY", \
201*0e209d39SAndroid Build Coastguard Worker "JMP", \
202*0e209d39SAndroid Build Coastguard Worker "FAIL", \
203*0e209d39SAndroid Build Coastguard Worker "JMP_SAV", \
204*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_B", \
205*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_G", \
206*0e209d39SAndroid Build Coastguard Worker "JMP_SAV_X", \
207*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_X", \
208*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_Z", \
209*0e209d39SAndroid Build Coastguard Worker "DOTANY_ALL", \
210*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_D", \
211*0e209d39SAndroid Build Coastguard Worker "CARET", \
212*0e209d39SAndroid Build Coastguard Worker "DOLLAR", \
213*0e209d39SAndroid Build Coastguard Worker "CTR_INIT", \
214*0e209d39SAndroid Build Coastguard Worker "CTR_INIT_NG", \
215*0e209d39SAndroid Build Coastguard Worker "DOTANY_UNIX", \
216*0e209d39SAndroid Build Coastguard Worker "CTR_LOOP", \
217*0e209d39SAndroid Build Coastguard Worker "CTR_LOOP_NG", \
218*0e209d39SAndroid Build Coastguard Worker "URX_CARET_M_UNIX", \
219*0e209d39SAndroid Build Coastguard Worker "RELOC_OPRND", \
220*0e209d39SAndroid Build Coastguard Worker "STO_SP", \
221*0e209d39SAndroid Build Coastguard Worker "LD_SP", \
222*0e209d39SAndroid Build Coastguard Worker "BACKREF", \
223*0e209d39SAndroid Build Coastguard Worker "STO_INP_LOC", \
224*0e209d39SAndroid Build Coastguard Worker "JMPX", \
225*0e209d39SAndroid Build Coastguard Worker "LA_START", \
226*0e209d39SAndroid Build Coastguard Worker "LA_END", \
227*0e209d39SAndroid Build Coastguard Worker "ONECHAR_I", \
228*0e209d39SAndroid Build Coastguard Worker "STRING_I", \
229*0e209d39SAndroid Build Coastguard Worker "BACKREF_I", \
230*0e209d39SAndroid Build Coastguard Worker "DOLLAR_M", \
231*0e209d39SAndroid Build Coastguard Worker "CARET_M", \
232*0e209d39SAndroid Build Coastguard Worker "LB_START", \
233*0e209d39SAndroid Build Coastguard Worker "LB_CONT", \
234*0e209d39SAndroid Build Coastguard Worker "LB_END", \
235*0e209d39SAndroid Build Coastguard Worker "LBN_CONT", \
236*0e209d39SAndroid Build Coastguard Worker "LBN_END", \
237*0e209d39SAndroid Build Coastguard Worker "STAT_SETREF_N", \
238*0e209d39SAndroid Build Coastguard Worker "LOOP_SR_I", \
239*0e209d39SAndroid Build Coastguard Worker "LOOP_C", \
240*0e209d39SAndroid Build Coastguard Worker "LOOP_DOT_I", \
241*0e209d39SAndroid Build Coastguard Worker "BACKSLASH_BU", \
242*0e209d39SAndroid Build Coastguard Worker "DOLLAR_D", \
243*0e209d39SAndroid Build Coastguard Worker "DOLLAR_MD", \
244*0e209d39SAndroid Build Coastguard Worker "URX_BACKSLASH_H", \
245*0e209d39SAndroid Build Coastguard Worker "URX_BACKSLASH_R", \
246*0e209d39SAndroid Build Coastguard Worker "URX_BACKSLASH_V"
247*0e209d39SAndroid Build Coastguard Worker
248*0e209d39SAndroid Build Coastguard Worker
249*0e209d39SAndroid Build Coastguard Worker //
250*0e209d39SAndroid Build Coastguard Worker // Convenience macros for assembling and disassembling a compiled operation.
251*0e209d39SAndroid Build Coastguard Worker //
252*0e209d39SAndroid Build Coastguard Worker #define URX_TYPE(x) ((uint32_t)(x) >> 24)
253*0e209d39SAndroid Build Coastguard Worker #define URX_VAL(x) ((x) & 0xffffff)
254*0e209d39SAndroid Build Coastguard Worker
255*0e209d39SAndroid Build Coastguard Worker
256*0e209d39SAndroid Build Coastguard Worker //
257*0e209d39SAndroid Build Coastguard Worker // Access to Unicode Sets composite character properties
258*0e209d39SAndroid Build Coastguard Worker // The sets are accessed by the match engine for things like \w (word boundary)
259*0e209d39SAndroid Build Coastguard Worker //
260*0e209d39SAndroid Build Coastguard Worker enum {
261*0e209d39SAndroid Build Coastguard Worker URX_ISWORD_SET = 1,
262*0e209d39SAndroid Build Coastguard Worker URX_ISALNUM_SET = 2,
263*0e209d39SAndroid Build Coastguard Worker URX_ISALPHA_SET = 3,
264*0e209d39SAndroid Build Coastguard Worker URX_ISSPACE_SET = 4,
265*0e209d39SAndroid Build Coastguard Worker
266*0e209d39SAndroid Build Coastguard Worker URX_GC_NORMAL, // Sets for finding grapheme cluster boundaries.
267*0e209d39SAndroid Build Coastguard Worker URX_GC_EXTEND,
268*0e209d39SAndroid Build Coastguard Worker URX_GC_CONTROL,
269*0e209d39SAndroid Build Coastguard Worker URX_GC_L,
270*0e209d39SAndroid Build Coastguard Worker URX_GC_LV,
271*0e209d39SAndroid Build Coastguard Worker URX_GC_LVT,
272*0e209d39SAndroid Build Coastguard Worker URX_GC_V,
273*0e209d39SAndroid Build Coastguard Worker URX_GC_T,
274*0e209d39SAndroid Build Coastguard Worker
275*0e209d39SAndroid Build Coastguard Worker URX_LAST_SET,
276*0e209d39SAndroid Build Coastguard Worker
277*0e209d39SAndroid Build Coastguard Worker URX_NEG_SET = 0x800000 // Flag bit to reverse sense of set
278*0e209d39SAndroid Build Coastguard Worker // membership test.
279*0e209d39SAndroid Build Coastguard Worker };
280*0e209d39SAndroid Build Coastguard Worker
281*0e209d39SAndroid Build Coastguard Worker
282*0e209d39SAndroid Build Coastguard Worker //
283*0e209d39SAndroid Build Coastguard Worker // Match Engine State Stack Frame Layout.
284*0e209d39SAndroid Build Coastguard Worker //
285*0e209d39SAndroid Build Coastguard Worker struct REStackFrame {
286*0e209d39SAndroid Build Coastguard Worker // Header
287*0e209d39SAndroid Build Coastguard Worker int64_t fInputIdx; // Position of next character in the input string
288*0e209d39SAndroid Build Coastguard Worker int64_t fPatIdx; // Position of next Op in the compiled pattern
289*0e209d39SAndroid Build Coastguard Worker // (int64_t for UVector64, values fit in an int32_t)
290*0e209d39SAndroid Build Coastguard Worker // Remainder
291*0e209d39SAndroid Build Coastguard Worker int64_t fExtra[1]; // Extra state, for capture group start/ends
292*0e209d39SAndroid Build Coastguard Worker // atomic parentheses, repeat counts, etc.
293*0e209d39SAndroid Build Coastguard Worker // Locations assigned at pattern compile time.
294*0e209d39SAndroid Build Coastguard Worker // Variable-length array.
295*0e209d39SAndroid Build Coastguard Worker };
296*0e209d39SAndroid Build Coastguard Worker // number of UVector elements in the header
297*0e209d39SAndroid Build Coastguard Worker #define RESTACKFRAME_HDRCOUNT 2
298*0e209d39SAndroid Build Coastguard Worker
299*0e209d39SAndroid Build Coastguard Worker //
300*0e209d39SAndroid Build Coastguard Worker // Start-Of-Match type. Used by find() to quickly scan to positions where a
301*0e209d39SAndroid Build Coastguard Worker // match might start before firing up the full match engine.
302*0e209d39SAndroid Build Coastguard Worker //
303*0e209d39SAndroid Build Coastguard Worker enum StartOfMatch {
304*0e209d39SAndroid Build Coastguard Worker START_NO_INFO, // No hint available.
305*0e209d39SAndroid Build Coastguard Worker START_CHAR, // Match starts with a literal code point.
306*0e209d39SAndroid Build Coastguard Worker START_SET, // Match starts with something matching a set.
307*0e209d39SAndroid Build Coastguard Worker START_START, // Match starts at start of buffer only (^ or \A)
308*0e209d39SAndroid Build Coastguard Worker START_LINE, // Match starts with ^ in multi-line mode.
309*0e209d39SAndroid Build Coastguard Worker START_STRING // Match starts with a literal string.
310*0e209d39SAndroid Build Coastguard Worker };
311*0e209d39SAndroid Build Coastguard Worker
312*0e209d39SAndroid Build Coastguard Worker #define START_OF_MATCH_STR(v) ((v)==START_NO_INFO? "START_NO_INFO" : \
313*0e209d39SAndroid Build Coastguard Worker (v)==START_CHAR? "START_CHAR" : \
314*0e209d39SAndroid Build Coastguard Worker (v)==START_SET? "START_SET" : \
315*0e209d39SAndroid Build Coastguard Worker (v)==START_START? "START_START" : \
316*0e209d39SAndroid Build Coastguard Worker (v)==START_LINE? "START_LINE" : \
317*0e209d39SAndroid Build Coastguard Worker (v)==START_STRING? "START_STRING" : \
318*0e209d39SAndroid Build Coastguard Worker "ILLEGAL")
319*0e209d39SAndroid Build Coastguard Worker
320*0e209d39SAndroid Build Coastguard Worker //
321*0e209d39SAndroid Build Coastguard Worker // 8 bit set, to fast-path latin-1 set membership tests.
322*0e209d39SAndroid Build Coastguard Worker //
323*0e209d39SAndroid Build Coastguard Worker struct Regex8BitSet : public UMemory {
324*0e209d39SAndroid Build Coastguard Worker inline Regex8BitSet();
325*0e209d39SAndroid Build Coastguard Worker inline void operator = (const Regex8BitSet &s);
326*0e209d39SAndroid Build Coastguard Worker inline void init(const UnicodeSet *src);
327*0e209d39SAndroid Build Coastguard Worker inline UBool contains(UChar32 c);
328*0e209d39SAndroid Build Coastguard Worker inline void add(UChar32 c);
329*0e209d39SAndroid Build Coastguard Worker int8_t d[32];
330*0e209d39SAndroid Build Coastguard Worker };
331*0e209d39SAndroid Build Coastguard Worker
Regex8BitSet()332*0e209d39SAndroid Build Coastguard Worker inline Regex8BitSet::Regex8BitSet() {
333*0e209d39SAndroid Build Coastguard Worker uprv_memset(d, 0, sizeof(d));
334*0e209d39SAndroid Build Coastguard Worker }
335*0e209d39SAndroid Build Coastguard Worker
contains(UChar32 c)336*0e209d39SAndroid Build Coastguard Worker inline UBool Regex8BitSet::contains(UChar32 c) {
337*0e209d39SAndroid Build Coastguard Worker // No bounds checking! This is deliberate.
338*0e209d39SAndroid Build Coastguard Worker return ((d[c>>3] & 1 <<(c&7)) != 0);
339*0e209d39SAndroid Build Coastguard Worker }
340*0e209d39SAndroid Build Coastguard Worker
add(UChar32 c)341*0e209d39SAndroid Build Coastguard Worker inline void Regex8BitSet::add(UChar32 c) {
342*0e209d39SAndroid Build Coastguard Worker d[c>>3] |= 1 << (c&7);
343*0e209d39SAndroid Build Coastguard Worker }
344*0e209d39SAndroid Build Coastguard Worker
init(const UnicodeSet * s)345*0e209d39SAndroid Build Coastguard Worker inline void Regex8BitSet::init(const UnicodeSet *s) {
346*0e209d39SAndroid Build Coastguard Worker if (s != nullptr) {
347*0e209d39SAndroid Build Coastguard Worker for (int32_t i=0; i<=255; i++) {
348*0e209d39SAndroid Build Coastguard Worker if (s->contains(i)) {
349*0e209d39SAndroid Build Coastguard Worker this->add(i);
350*0e209d39SAndroid Build Coastguard Worker }
351*0e209d39SAndroid Build Coastguard Worker }
352*0e209d39SAndroid Build Coastguard Worker }
353*0e209d39SAndroid Build Coastguard Worker }
354*0e209d39SAndroid Build Coastguard Worker
355*0e209d39SAndroid Build Coastguard Worker inline void Regex8BitSet::operator = (const Regex8BitSet &s) {
356*0e209d39SAndroid Build Coastguard Worker uprv_memcpy(d, s.d, sizeof(d));
357*0e209d39SAndroid Build Coastguard Worker }
358*0e209d39SAndroid Build Coastguard Worker
359*0e209d39SAndroid Build Coastguard Worker
360*0e209d39SAndroid Build Coastguard Worker // Case folded UText Iterator helper class.
361*0e209d39SAndroid Build Coastguard Worker // Wraps a UText, provides a case-folded enumeration over its contents.
362*0e209d39SAndroid Build Coastguard Worker // Used in implementing case insensitive matching constructs.
363*0e209d39SAndroid Build Coastguard Worker // Implementation in rematch.cpp
364*0e209d39SAndroid Build Coastguard Worker
365*0e209d39SAndroid Build Coastguard Worker class CaseFoldingUTextIterator: public UMemory {
366*0e209d39SAndroid Build Coastguard Worker public:
367*0e209d39SAndroid Build Coastguard Worker CaseFoldingUTextIterator(UText &text);
368*0e209d39SAndroid Build Coastguard Worker ~CaseFoldingUTextIterator();
369*0e209d39SAndroid Build Coastguard Worker
370*0e209d39SAndroid Build Coastguard Worker UChar32 next(); // Next case folded character
371*0e209d39SAndroid Build Coastguard Worker
372*0e209d39SAndroid Build Coastguard Worker UBool inExpansion(); // True if last char returned from next() and the
373*0e209d39SAndroid Build Coastguard Worker // next to be returned both originated from a string
374*0e209d39SAndroid Build Coastguard Worker // folding of the same code point from the original UText.
375*0e209d39SAndroid Build Coastguard Worker private:
376*0e209d39SAndroid Build Coastguard Worker UText &fUText;
377*0e209d39SAndroid Build Coastguard Worker const char16_t *fFoldChars;
378*0e209d39SAndroid Build Coastguard Worker int32_t fFoldLength;
379*0e209d39SAndroid Build Coastguard Worker int32_t fFoldIndex;
380*0e209d39SAndroid Build Coastguard Worker
381*0e209d39SAndroid Build Coastguard Worker };
382*0e209d39SAndroid Build Coastguard Worker
383*0e209d39SAndroid Build Coastguard Worker
384*0e209d39SAndroid Build Coastguard Worker // Case folded char16_t * string iterator.
385*0e209d39SAndroid Build Coastguard Worker // Wraps a char16_t *, provides a case-folded enumeration over its contents.
386*0e209d39SAndroid Build Coastguard Worker // Used in implementing case insensitive matching constructs.
387*0e209d39SAndroid Build Coastguard Worker // Implementation in rematch.cpp
388*0e209d39SAndroid Build Coastguard Worker
389*0e209d39SAndroid Build Coastguard Worker class CaseFoldingUCharIterator: public UMemory {
390*0e209d39SAndroid Build Coastguard Worker public:
391*0e209d39SAndroid Build Coastguard Worker CaseFoldingUCharIterator(const char16_t *chars, int64_t start, int64_t limit);
392*0e209d39SAndroid Build Coastguard Worker ~CaseFoldingUCharIterator();
393*0e209d39SAndroid Build Coastguard Worker
394*0e209d39SAndroid Build Coastguard Worker UChar32 next(); // Next case folded character
395*0e209d39SAndroid Build Coastguard Worker
396*0e209d39SAndroid Build Coastguard Worker UBool inExpansion(); // True if last char returned from next() and the
397*0e209d39SAndroid Build Coastguard Worker // next to be returned both originated from a string
398*0e209d39SAndroid Build Coastguard Worker // folding of the same code point from the original UText.
399*0e209d39SAndroid Build Coastguard Worker
400*0e209d39SAndroid Build Coastguard Worker int64_t getIndex(); // Return the current input buffer index.
401*0e209d39SAndroid Build Coastguard Worker
402*0e209d39SAndroid Build Coastguard Worker private:
403*0e209d39SAndroid Build Coastguard Worker const char16_t *fChars;
404*0e209d39SAndroid Build Coastguard Worker int64_t fIndex;
405*0e209d39SAndroid Build Coastguard Worker int64_t fLimit;
406*0e209d39SAndroid Build Coastguard Worker const char16_t *fFoldChars;
407*0e209d39SAndroid Build Coastguard Worker int32_t fFoldLength;
408*0e209d39SAndroid Build Coastguard Worker int32_t fFoldIndex;
409*0e209d39SAndroid Build Coastguard Worker
410*0e209d39SAndroid Build Coastguard Worker };
411*0e209d39SAndroid Build Coastguard Worker
412*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
413*0e209d39SAndroid Build Coastguard Worker #endif
414*0e209d39SAndroid Build Coastguard Worker
415