2016-06-15 18:58:17 +00:00
|
|
|
// Copyright (C) 2016 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2007-12-11 21:30:10 +00:00
|
|
|
//
|
2016-05-31 21:45:07 +00:00
|
|
|
// Copyright (C) 2002-2015 International Business Machines Corporation
|
|
|
|
// and others. All rights reserved.
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
// file: regeximp.h
|
|
|
|
//
|
2002-11-07 02:34:46 +00:00
|
|
|
// ICU Regular Expressions,
|
|
|
|
// Definitions of constant values used in the compiled form of
|
|
|
|
// a regular expression pattern.
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _REGEXIMP_H
|
|
|
|
#define _REGEXIMP_H
|
|
|
|
|
2012-01-20 00:50:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "unicode/utext.h"
|
|
|
|
|
2003-03-27 01:25:20 +00:00
|
|
|
#include "cmemory.h"
|
2012-01-20 00:50:02 +00:00
|
|
|
#include "ucase.h"
|
2003-03-27 01:25:20 +00:00
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
// For debugging, define REGEX_DEBUG
|
2012-01-20 00:50:02 +00:00
|
|
|
// To define with configure,
|
2013-10-14 22:11:21 +00:00
|
|
|
// CPPFLAGS="-DREGEX_DEBUG" ./runConfigureICU --enable-debug --disable-release Linux
|
2012-01-20 00:50:02 +00:00
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
#ifdef REGEX_DEBUG
|
2002-11-19 19:31:03 +00:00
|
|
|
//
|
2003-12-06 01:49:56 +00:00
|
|
|
// debugging options. Enable one or more of the three #defines immediately following
|
2002-11-19 19:31:03 +00:00
|
|
|
//
|
2003-12-06 01:49:56 +00:00
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
//#define REGEX_SCAN_DEBUG
|
2003-12-06 01:49:56 +00:00
|
|
|
#define REGEX_DUMP_DEBUG
|
|
|
|
#define REGEX_RUN_DEBUG
|
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
// End of #defines inteded to be directly set.
|
|
|
|
|
2003-03-15 01:42:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
#ifdef REGEX_SCAN_DEBUG
|
2003-12-06 01:49:56 +00:00
|
|
|
#define REGEX_SCAN_DEBUG_PRINTF(a) printf a
|
2002-11-19 19:31:03 +00:00
|
|
|
#else
|
2003-12-06 01:49:56 +00:00
|
|
|
#define REGEX_SCAN_DEBUG_PRINTF(a)
|
2002-11-19 19:31:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
2002-11-11 18:49:49 +00:00
|
|
|
// Opcode types In the compiled form of the regexp, these are the type, or opcodes,
|
2002-10-22 00:09:32 +00:00
|
|
|
// of the entries.
|
|
|
|
//
|
2002-11-11 18:49:49 +00:00
|
|
|
enum {
|
2003-01-16 01:12:04 +00:00
|
|
|
URX_RESERVED_OP = 0, // For multi-operand ops, most non-first words.
|
2003-03-24 05:23:07 +00:00
|
|
|
URX_RESERVED_OP_N = 255, // For multi-operand ops, negative operand values.
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_BACKTRACK = 1, // Force a backtrack, as if a match test had failed.
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_END = 2,
|
|
|
|
URX_ONECHAR = 3, // Value field is the 21 bit unicode char to match
|
|
|
|
URX_STRING = 4, // Value field is index of string start
|
|
|
|
URX_STRING_LEN = 5, // Value field is string length (code units)
|
|
|
|
URX_STATE_SAVE = 6, // Value field is pattern position to push
|
|
|
|
URX_NOP = 7,
|
|
|
|
URX_START_CAPTURE = 8, // Value field is capture group number.
|
|
|
|
URX_END_CAPTURE = 9, // Value field is capture group number
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_STATIC_SETREF = 10, // Value field is index of set in array of sets.
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_SETREF = 11, // Value field is index of set in array of sets.
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_DOTANY = 12,
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_JMP = 13, // Value field is destination position in
|
2002-10-22 00:09:32 +00:00
|
|
|
// the pattern.
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_FAIL = 14, // Stop match operation, No match.
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2003-03-18 01:51:36 +00:00
|
|
|
URX_JMP_SAV = 15, // Operand: JMP destination location
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_BACKSLASH_B = 16, // Value field: 0: \b 1: \B
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_BACKSLASH_G = 17,
|
2003-04-02 23:10:16 +00:00
|
|
|
URX_JMP_SAV_X = 18, // Conditional JMP_SAV,
|
|
|
|
// Used in (x)+, breaks loop on zero length match.
|
|
|
|
// Operand: Jmp destination.
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_BACKSLASH_X = 19,
|
|
|
|
URX_BACKSLASH_Z = 20, // \z Unconditional end of line.
|
2002-10-28 17:18:44 +00:00
|
|
|
|
2002-11-11 18:49:49 +00:00
|
|
|
URX_DOTANY_ALL = 21, // ., in the . matches any mode.
|
|
|
|
URX_BACKSLASH_D = 22, // Value field: 0: \d 1: \D
|
|
|
|
URX_CARET = 23, // Value field: 1: multi-line mode.
|
2003-01-16 01:12:04 +00:00
|
|
|
URX_DOLLAR = 24, // Also for \Z
|
|
|
|
|
|
|
|
URX_CTR_INIT = 25, // Counter Inits for {Interval} loops.
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_CTR_INIT_NG = 26, // 2 kinds, normal and non-greedy.
|
2003-03-26 01:17:16 +00:00
|
|
|
// These are 4 word opcodes. See description.
|
2003-02-26 05:16:49 +00:00
|
|
|
// First Operand: Data loc of counter variable
|
2007-12-11 21:30:10 +00:00
|
|
|
// 2nd Operand: Pat loc of the URX_CTR_LOOPx
|
2003-02-26 05:16:49 +00:00
|
|
|
// at the end of the loop.
|
|
|
|
// 3rd Operand: Minimum count.
|
|
|
|
// 4th Operand: Max count, -1 for unbounded.
|
2003-03-26 01:17:16 +00:00
|
|
|
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_DOTANY_UNIX = 27, // '.' operator in UNIX_LINES mode, only \n marks end of line.
|
2003-03-26 01:17:16 +00:00
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
URX_CTR_LOOP = 28, // Loop Ops for {interval} loops.
|
|
|
|
URX_CTR_LOOP_NG = 29, // Also in three flavors.
|
2003-03-26 01:17:16 +00:00
|
|
|
// Operand is loc of corresponding CTR_INIT.
|
|
|
|
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_CARET_M_UNIX = 30, // '^' operator, test for start of line in multi-line
|
|
|
|
// plus UNIX_LINES mode.
|
2003-01-16 01:12:04 +00:00
|
|
|
|
2003-01-17 01:43:54 +00:00
|
|
|
URX_RELOC_OPRND = 31, // Operand value in multi-operand ops that refers
|
2003-01-16 01:12:04 +00:00
|
|
|
// back into compiled pattern code, and thus must
|
|
|
|
// be relocated when inserting/deleting ops in code.
|
2003-01-17 01:43:54 +00:00
|
|
|
|
|
|
|
URX_STO_SP = 32, // Store the stack ptr. Operand is location within
|
|
|
|
// matcher data (not stack data) to store it.
|
2003-01-21 04:56:14 +00:00
|
|
|
URX_LD_SP = 33, // Load the stack pointer. Operand is location
|
2003-01-17 01:43:54 +00:00
|
|
|
// to load from.
|
2003-01-25 18:57:42 +00:00
|
|
|
URX_BACKREF = 34, // Back Reference. Parameter is the index of the
|
2003-01-21 04:56:14 +00:00
|
|
|
// capture group variables in the state stack frame.
|
2003-01-25 18:57:42 +00:00
|
|
|
URX_STO_INP_LOC = 35, // Store the input location. Operand is location
|
2003-04-02 23:10:16 +00:00
|
|
|
// within the matcher stack frame.
|
2003-01-31 02:00:52 +00:00
|
|
|
URX_JMPX = 36, // Conditional JMP.
|
2003-01-25 18:57:42 +00:00
|
|
|
// First Operand: JMP target location.
|
2007-12-11 21:30:10 +00:00
|
|
|
// Second Operand: Data location containing an
|
2003-01-25 18:57:42 +00:00
|
|
|
// input position. If current input position ==
|
|
|
|
// saved input position, FAIL rather than taking
|
2003-01-31 02:00:52 +00:00
|
|
|
// the JMP
|
|
|
|
URX_LA_START = 37, // Starting a LookAround expression.
|
|
|
|
// Save InputPos and SP in static data.
|
|
|
|
// Operand: Static data offset for the save
|
2003-02-07 02:04:14 +00:00
|
|
|
URX_LA_END = 38, // Ending a Lookaround expression.
|
2003-01-31 02:00:52 +00:00
|
|
|
// Restore InputPos and Stack to saved values.
|
|
|
|
// Operand: Static data offset for saved data.
|
2003-02-07 02:04:14 +00:00
|
|
|
URX_ONECHAR_I = 39, // Test for case-insensitive match of a literal character.
|
|
|
|
// Operand: the literal char.
|
2003-02-11 01:17:51 +00:00
|
|
|
URX_STRING_I = 40, // Case insensitive string compare.
|
2003-02-07 02:04:14 +00:00
|
|
|
// First Operand: Index of start of string in string literals
|
|
|
|
// Second Operand (next word in compiled code):
|
|
|
|
// the length of the string.
|
2003-02-12 01:28:01 +00:00
|
|
|
URX_BACKREF_I = 41, // Case insensitive back reference.
|
2003-02-11 01:17:51 +00:00
|
|
|
// Parameter is the index of the
|
|
|
|
// capture group variables in the state stack frame.
|
2003-02-12 01:28:01 +00:00
|
|
|
URX_DOLLAR_M = 42, // $ in multi-line mode.
|
2003-03-02 19:11:09 +00:00
|
|
|
URX_CARET_M = 43, // ^ in multi-line mode.
|
|
|
|
URX_LB_START = 44, // LookBehind Start.
|
|
|
|
// Paramater is data location
|
|
|
|
URX_LB_CONT = 45, // LookBehind Continue.
|
|
|
|
// Param 0: the data location
|
|
|
|
// Param 1: The minimum length of the look-behind match
|
|
|
|
// Param 2: The max length of the look-behind match
|
|
|
|
URX_LB_END = 46, // LookBehind End.
|
|
|
|
// Parameter is the data location.
|
|
|
|
// Check that match ended at the right spot,
|
|
|
|
// Restore original input string len.
|
|
|
|
URX_LBN_CONT = 47, // Negative LookBehind Continue
|
|
|
|
// Param 0: the data location
|
|
|
|
// Param 1: The minimum length of the look-behind match
|
|
|
|
// Param 2: The max length of the look-behind match
|
|
|
|
// Param 3: The pattern loc following the look-behind block.
|
2003-03-27 01:25:20 +00:00
|
|
|
URX_LBN_END = 48, // Negative LookBehind end
|
2003-03-02 19:11:09 +00:00
|
|
|
// Parameter is the data location.
|
|
|
|
// Check that the match ended at the right spot.
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_STAT_SETREF_N = 49, // Reference to a prebuilt set (e.g. \w), negated
|
2003-03-28 02:31:17 +00:00
|
|
|
// Operand is index of set in array of sets.
|
|
|
|
URX_LOOP_SR_I = 50, // Init a [set]* loop.
|
|
|
|
// Operand is the sets index in array of user sets.
|
2003-04-02 23:10:16 +00:00
|
|
|
URX_LOOP_C = 51, // Continue a [set]* or OneChar* loop.
|
2003-03-28 02:31:17 +00:00
|
|
|
// Operand is a matcher static data location.
|
|
|
|
// Must always immediately follow LOOP_x_I instruction.
|
2003-11-08 02:01:42 +00:00
|
|
|
URX_LOOP_DOT_I = 52, // .*, initialization of the optimized loop.
|
2003-04-02 23:10:16 +00:00
|
|
|
// Operand value:
|
2007-12-11 21:30:10 +00:00
|
|
|
// bit 0:
|
|
|
|
// 0: Normal (. doesn't match new-line) mode.
|
|
|
|
// 1: . matches new-line mode.
|
|
|
|
// bit 1: controls what new-lines are recognized by this operation.
|
|
|
|
// 0: All Unicode New-lines
|
|
|
|
// 1: UNIX_LINES, \u000a only.
|
|
|
|
URX_BACKSLASH_BU = 53, // \b or \B in UREGEX_UWORD mode, using Unicode style
|
2003-11-08 02:01:42 +00:00
|
|
|
// word boundaries.
|
2007-12-11 21:30:10 +00:00
|
|
|
URX_DOLLAR_D = 54, // $ end of input test, in UNIX_LINES mode.
|
2015-02-24 00:24:59 +00:00
|
|
|
URX_DOLLAR_MD = 55, // $ end of input test, in MULTI_LINE and UNIX_LINES mode.
|
|
|
|
URX_BACKSLASH_H = 56, // Value field: 0: \h 1: \H
|
|
|
|
URX_BACKSLASH_R = 57, // Any line break sequence.
|
|
|
|
URX_BACKSLASH_V = 58 // Value field: 0: \v 1: \V
|
2003-03-02 19:11:09 +00:00
|
|
|
|
2007-12-11 21:30:10 +00:00
|
|
|
};
|
2002-10-31 01:58:01 +00:00
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
// Keep this list of opcode names in sync with the above enum
|
|
|
|
// Used for debug printing only.
|
|
|
|
#define URX_OPCODE_NAMES \
|
2003-01-16 01:12:04 +00:00
|
|
|
" ", \
|
2003-03-26 06:25:55 +00:00
|
|
|
"BACKTRACK", \
|
2002-11-14 18:27:00 +00:00
|
|
|
"END", \
|
|
|
|
"ONECHAR", \
|
|
|
|
"STRING", \
|
|
|
|
"STRING_LEN", \
|
|
|
|
"STATE_SAVE", \
|
|
|
|
"NOP", \
|
|
|
|
"START_CAPTURE", \
|
|
|
|
"END_CAPTURE", \
|
|
|
|
"URX_STATIC_SETREF", \
|
|
|
|
"SETREF", \
|
|
|
|
"DOTANY", \
|
|
|
|
"JMP", \
|
|
|
|
"FAIL", \
|
2003-03-26 06:25:55 +00:00
|
|
|
"JMP_SAV", \
|
|
|
|
"BACKSLASH_B", \
|
|
|
|
"BACKSLASH_G", \
|
|
|
|
"JMP_SAV_X", \
|
|
|
|
"BACKSLASH_X", \
|
|
|
|
"BACKSLASH_Z", \
|
|
|
|
"DOTANY_ALL", \
|
|
|
|
"BACKSLASH_D", \
|
|
|
|
"CARET", \
|
|
|
|
"DOLLAR", \
|
2003-01-16 01:12:04 +00:00
|
|
|
"CTR_INIT", \
|
|
|
|
"CTR_INIT_NG", \
|
2007-12-11 21:30:10 +00:00
|
|
|
"DOTANY_UNIX", \
|
2003-01-16 01:12:04 +00:00
|
|
|
"CTR_LOOP", \
|
|
|
|
"CTR_LOOP_NG", \
|
2007-12-11 21:30:10 +00:00
|
|
|
"URX_CARET_M_UNIX", \
|
2003-01-17 01:43:54 +00:00
|
|
|
"RELOC_OPRND", \
|
|
|
|
"STO_SP", \
|
2003-01-21 04:56:14 +00:00
|
|
|
"LD_SP", \
|
2003-01-25 18:57:42 +00:00
|
|
|
"BACKREF", \
|
|
|
|
"STO_INP_LOC", \
|
2003-01-31 02:00:52 +00:00
|
|
|
"JMPX", \
|
|
|
|
"LA_START", \
|
2003-02-07 02:04:14 +00:00
|
|
|
"LA_END", \
|
|
|
|
"ONECHAR_I", \
|
2003-02-11 01:17:51 +00:00
|
|
|
"STRING_I", \
|
2003-02-12 01:28:01 +00:00
|
|
|
"BACKREF_I", \
|
|
|
|
"DOLLAR_M", \
|
2003-03-02 19:11:09 +00:00
|
|
|
"CARET_M", \
|
|
|
|
"LB_START", \
|
|
|
|
"LB_CONT", \
|
|
|
|
"LB_END", \
|
|
|
|
"LBN_CONT", \
|
2003-03-27 01:25:20 +00:00
|
|
|
"LBN_END", \
|
2003-03-28 02:31:17 +00:00
|
|
|
"STAT_SETREF_N", \
|
|
|
|
"LOOP_SR_I", \
|
2003-04-02 23:10:16 +00:00
|
|
|
"LOOP_C", \
|
2003-11-08 02:01:42 +00:00
|
|
|
"LOOP_DOT_I", \
|
2007-12-11 21:30:10 +00:00
|
|
|
"BACKSLASH_BU", \
|
|
|
|
"DOLLAR_D", \
|
2015-02-24 00:24:59 +00:00
|
|
|
"DOLLAR_MD", \
|
|
|
|
"URX_BACKSLASH_H", \
|
|
|
|
"URX_BACKSLASH_R", \
|
|
|
|
"URX_BACKSLASH_V"
|
2003-03-27 01:25:20 +00:00
|
|
|
|
2002-10-28 17:18:44 +00:00
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
// Convenience macros for assembling and disassembling a compiled operation.
|
|
|
|
//
|
2007-12-11 21:30:10 +00:00
|
|
|
#define URX_TYPE(x) ((uint32_t)(x) >> 24)
|
2002-10-22 00:09:32 +00:00
|
|
|
#define URX_VAL(x) ((x) & 0xffffff)
|
|
|
|
|
2007-12-11 21:30:10 +00:00
|
|
|
|
2002-10-31 01:58:01 +00:00
|
|
|
//
|
2003-02-16 07:24:55 +00:00
|
|
|
// Access to Unicode Sets composite character properties
|
2002-10-31 01:58:01 +00:00
|
|
|
// The sets are accessed by the match engine for things like \w (word boundary)
|
2007-12-11 21:30:10 +00:00
|
|
|
//
|
2002-11-11 18:49:49 +00:00
|
|
|
enum {
|
|
|
|
URX_ISWORD_SET = 1,
|
|
|
|
URX_ISALNUM_SET = 2,
|
|
|
|
URX_ISALPHA_SET = 3,
|
|
|
|
URX_ISSPACE_SET = 4,
|
2003-02-16 07:24:55 +00:00
|
|
|
|
|
|
|
URX_GC_NORMAL, // Sets for finding grapheme cluster boundaries.
|
|
|
|
URX_GC_EXTEND,
|
|
|
|
URX_GC_CONTROL,
|
|
|
|
URX_GC_L,
|
|
|
|
URX_GC_LV,
|
|
|
|
URX_GC_LVT,
|
|
|
|
URX_GC_V,
|
|
|
|
URX_GC_T,
|
|
|
|
|
|
|
|
URX_LAST_SET,
|
2002-11-11 18:49:49 +00:00
|
|
|
|
|
|
|
URX_NEG_SET = 0x800000 // Flag bit to reverse sense of set
|
|
|
|
// membership test.
|
|
|
|
};
|
2002-10-31 01:58:01 +00:00
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Match Engine State Stack Frame Layout.
|
|
|
|
//
|
|
|
|
struct REStackFrame {
|
2010-02-25 06:33:29 +00:00
|
|
|
// Header
|
2010-02-03 02:59:35 +00:00
|
|
|
int64_t fInputIdx; // Position of next character in the input string
|
2010-02-25 06:33:29 +00:00
|
|
|
int64_t fPatIdx; // Position of next Op in the compiled pattern
|
|
|
|
// (int64_t for UVector64, values fit in an int32_t)
|
|
|
|
// Remainder
|
|
|
|
int64_t fExtra[1]; // Extra state, for capture group start/ends
|
2003-01-16 01:12:04 +00:00
|
|
|
// atomic parentheses, repeat counts, etc.
|
|
|
|
// Locations assigned at pattern compile time.
|
2010-02-25 06:33:29 +00:00
|
|
|
// Variable-length array.
|
2003-01-16 01:12:04 +00:00
|
|
|
};
|
2010-02-25 06:33:29 +00:00
|
|
|
// number of UVector elements in the header
|
|
|
|
#define RESTACKFRAME_HDRCOUNT 2
|
2003-01-16 01:12:04 +00:00
|
|
|
|
2003-03-06 01:57:52 +00:00
|
|
|
//
|
|
|
|
// Start-Of-Match type. Used by find() to quickly scan to positions where a
|
|
|
|
// match might start before firing up the full match engine.
|
|
|
|
//
|
|
|
|
enum StartOfMatch {
|
|
|
|
START_NO_INFO, // No hint available.
|
|
|
|
START_CHAR, // Match starts with a literal code point.
|
|
|
|
START_SET, // Match starts with something matching a set.
|
|
|
|
START_START, // Match starts at start of buffer only (^ or \A)
|
|
|
|
START_LINE, // Match starts with ^ in multi-line mode.
|
|
|
|
START_STRING // Match starts with a literal string.
|
|
|
|
};
|
2003-03-13 01:56:01 +00:00
|
|
|
|
|
|
|
#define START_OF_MATCH_STR(v) ((v)==START_NO_INFO? "START_NO_INFO" : \
|
|
|
|
(v)==START_CHAR? "START_CHAR" : \
|
|
|
|
(v)==START_SET? "START_SET" : \
|
|
|
|
(v)==START_START? "START_START" : \
|
|
|
|
(v)==START_LINE? "START_LINE" : \
|
|
|
|
(v)==START_STRING? "START_STRING" : \
|
|
|
|
"ILLEGAL")
|
2007-12-11 21:30:10 +00:00
|
|
|
|
2003-03-27 01:25:20 +00:00
|
|
|
//
|
|
|
|
// 8 bit set, to fast-path latin-1 set membership tests.
|
|
|
|
//
|
2003-05-28 03:04:04 +00:00
|
|
|
struct Regex8BitSet : public UMemory {
|
2003-03-28 02:31:17 +00:00
|
|
|
inline Regex8BitSet();
|
|
|
|
inline void operator = (const Regex8BitSet &s);
|
2003-03-27 01:25:20 +00:00
|
|
|
inline void init(const UnicodeSet *src);
|
|
|
|
inline UBool contains(UChar32 c);
|
|
|
|
inline void add(UChar32 c);
|
|
|
|
int8_t d[32];
|
|
|
|
};
|
|
|
|
|
2003-03-28 02:31:17 +00:00
|
|
|
inline Regex8BitSet::Regex8BitSet() {
|
|
|
|
uprv_memset(d, 0, sizeof(d));
|
|
|
|
}
|
|
|
|
|
2003-03-27 01:25:20 +00:00
|
|
|
inline UBool Regex8BitSet::contains(UChar32 c) {
|
|
|
|
// No bounds checking! This is deliberate.
|
|
|
|
return ((d[c>>3] & 1 <<(c&7)) != 0);
|
2004-12-30 07:25:51 +00:00
|
|
|
}
|
2003-03-27 01:25:20 +00:00
|
|
|
|
|
|
|
inline void Regex8BitSet::add(UChar32 c) {
|
|
|
|
d[c>>3] |= 1 << (c&7);
|
2004-12-30 07:25:51 +00:00
|
|
|
}
|
2003-03-27 01:25:20 +00:00
|
|
|
|
|
|
|
inline void Regex8BitSet::init(const UnicodeSet *s) {
|
|
|
|
if (s != NULL) {
|
2005-08-23 18:44:52 +00:00
|
|
|
for (int32_t i=0; i<=255; i++) {
|
2003-03-27 01:25:20 +00:00
|
|
|
if (s->contains(i)) {
|
|
|
|
this->add(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-28 02:31:17 +00:00
|
|
|
inline void Regex8BitSet::operator = (const Regex8BitSet &s) {
|
|
|
|
uprv_memcpy(d, s.d, sizeof(d));
|
|
|
|
}
|
|
|
|
|
2012-01-20 00:50:02 +00:00
|
|
|
|
|
|
|
// Case folded UText Iterator helper class.
|
|
|
|
// Wraps a UText, provides a case-folded enumeration over its contents.
|
|
|
|
// Used in implementing case insensitive matching constructs.
|
|
|
|
// Implementation in rematch.cpp
|
|
|
|
|
|
|
|
class CaseFoldingUTextIterator: public UMemory {
|
|
|
|
public:
|
|
|
|
CaseFoldingUTextIterator(UText &text);
|
|
|
|
~CaseFoldingUTextIterator();
|
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
UChar32 next(); // Next case folded character
|
2012-01-20 00:50:02 +00:00
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
UBool inExpansion(); // True if last char returned from next() and the
|
2012-01-20 00:50:02 +00:00
|
|
|
// next to be returned both originated from a string
|
|
|
|
// folding of the same code point from the orignal UText.
|
|
|
|
private:
|
|
|
|
UText &fUText;
|
|
|
|
const UCaseProps *fcsp;
|
|
|
|
const UChar *fFoldChars;
|
|
|
|
int32_t fFoldLength;
|
|
|
|
int32_t fFoldIndex;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Case folded UChar * string iterator.
|
|
|
|
// Wraps a UChar *, provides a case-folded enumeration over its contents.
|
|
|
|
// Used in implementing case insensitive matching constructs.
|
|
|
|
// Implementation in rematch.cpp
|
|
|
|
|
|
|
|
class CaseFoldingUCharIterator: public UMemory {
|
|
|
|
public:
|
|
|
|
CaseFoldingUCharIterator(const UChar *chars, int64_t start, int64_t limit);
|
|
|
|
~CaseFoldingUCharIterator();
|
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
UChar32 next(); // Next case folded character
|
2012-01-20 00:50:02 +00:00
|
|
|
|
2013-10-14 22:11:21 +00:00
|
|
|
UBool inExpansion(); // True if last char returned from next() and the
|
2012-01-20 00:50:02 +00:00
|
|
|
// next to be returned both originated from a string
|
|
|
|
// folding of the same code point from the orignal UText.
|
|
|
|
|
|
|
|
int64_t getIndex(); // Return the current input buffer index.
|
|
|
|
|
|
|
|
private:
|
|
|
|
const UChar *fChars;
|
|
|
|
int64_t fIndex;
|
|
|
|
int64_t fLimit;
|
|
|
|
const UCaseProps *fcsp;
|
|
|
|
const UChar *fFoldChars;
|
|
|
|
int32_t fFoldLength;
|
|
|
|
int32_t fFoldIndex;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
U_NAMESPACE_END
|
2002-10-22 00:09:32 +00:00
|
|
|
#endif
|
|
|
|
|