X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/i18n/regexst.cpp diff --git a/icuSources/i18n/regexst.cpp b/icuSources/i18n/regexst.cpp index ca5456e7..4f12e87b 100644 --- a/icuSources/i18n/regexst.cpp +++ b/icuSources/i18n/regexst.cpp @@ -1,7 +1,9 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html // // regexst.h // -// Copyright (C) 2003, International Business Machines Corporation and others. +// Copyright (C) 2004-2015, International Business Machines Corporation and others. // All Rights Reserved. // // This file contains class RegexStaticSets @@ -38,13 +40,13 @@ U_NAMESPACE_BEGIN -//---------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // // Unicode Set pattern strings for all of the required constant sets. // Initialized with hex values for portability to EBCDIC based machines. // Really ugly, but there's no good way to avoid it. // -//---------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // "Rule Char" Characters are those with no special meaning, and therefore do not // need to be escaped to appear as literals in a regexp. Expressed @@ -55,14 +57,6 @@ static const UChar gRuleSet_rule_char_pattern[] = { // \ { \ } \ ^ \ $ \ | \ \ \ . ] 0x5c, 0x7b,0x5c, 0x7d, 0x5c, 0x5e, 0x5c, 0x24, 0x5c, 0x7c, 0x5c, 0x5c, 0x5c, 0x2e, 0x5d, 0}; - -static const UChar gRuleSet_digit_char_pattern[] = { -// [ 0 - 9 ] - 0x5b, 0x30, 0x2d, 0x39, 0x5d, 0}; -//static const UnicodeSet *gRuleDigits = NULL; - - - // // Here are the backslash escape characters that ICU's unescape() function // will handle. @@ -72,192 +66,226 @@ static const UChar gUnescapeCharPattern[] = { 0x5b, 0x61, 0x63, 0x65, 0x66, 0x6e, 0x72, 0x74, 0x75, 0x55, 0x78, 0x5d, 0}; -// -// White space characters that may appear within a pattern in free-form mode -// -static const UChar gRuleWhiteSpacePattern[] = { - /* "[[:Cf:][:WSpace:]]" */ - 91, 91, 58, 67, 102, 58, 93, 91, 58, 87, - 83, 112, 97, 99, 101, 58, 93, 93, 0 }; - - - // // Unicode Set Definitions for Regular Expression \w // static const UChar gIsWordPattern[] = { -// [ \ p { L l } \ p { L u } - 0x5b, 0x5c, 0x70, 0x7b, 0x4c, 0x6c, 0x7d, 0x5c, 0x70, 0x7b, 0x4c, 0x75, 0x7d, -// \ p { L t } \ p { L o } - 0x5c, 0x70, 0x7b, 0x4c, 0x74, 0x7d, 0x5c, 0x70, 0x7b, 0x4c, 0x6f, 0x7d, -// \ p { N d } _ ] - 0x5c, 0x70, 0x7b, 0x4e, 0x64, 0x7d, 0x5f, 0x5d, 0}; +// [ \ p { A l p h a b e t i c } + 0x5b, 0x5c, 0x70, 0x7b, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x62, 0x65, 0x74, 0x69, 0x63, 0x7d, +// \ p { M } Mark + 0x5c, 0x70, 0x7b, 0x4d, 0x7d, +// \ p { N d } Digit_Numeric + 0x5c, 0x70, 0x7b, 0x4e, 0x64, 0x7d, +// \ p { P c } Connector_Punctuation + 0x5c, 0x70, 0x7b, 0x50, 0x63, 0x7d, +// \ u 2 0 0 c \ u 2 0 0 d ] + 0x5c, 0x75, 0x32, 0x30, 0x30, 0x63, 0x5c, 0x75, 0x32, 0x30, 0x30, 0x64, 0x5d, 0}; // // Unicode Set Definitions for Regular Expression \s // - static const UChar gIsSpacePattern[] = { -// [ \ t \ n \ f \ r \ p { Z } ] - 0x5b, 0x5c, 0x74, 0x5c, 0x6e, 0x5c, 0x66, 0x5c, 0x72, 0x5c, 0x70, 0x7b, 0x5a, 0x7d, 0x5d, 0}; +static const UChar gIsSpacePattern[] = { +// [ \ p { W h i t e S p a c e } ] + 0x5b, 0x5c, 0x70, 0x7b, 0x57, 0x68, 0x69, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x7d, 0x5d, 0}; // // UnicodeSets used in implementation of Grapheme Cluster detection, \X // - static const UChar gGC_ControlPattern[] = { -// [ [ : Z l : ] [ : Z p : ] - 0x5b, 0x5b, 0x3a, 0x5A, 0x6c, 0x3a, 0x5d, 0x5b, 0x3a, 0x5A, 0x70, 0x3a, 0x5d, -// [ : C c : ] [ : C f : ] ] - 0x5b, 0x3a, 0x43, 0x63, 0x3a, 0x5d, 0x5b, 0x3a, 0x43, 0x66, 0x3a, 0x5d, 0x5d, 0}; - - static const UChar gGC_ExtendPattern[] = { +static const UChar gGC_ControlPattern[] = { +// [ [ : Z l : ] [ : Z p : ] + 0x5b, 0x5b, 0x3a, 0x5A, 0x6c, 0x3a, 0x5d, 0x5b, 0x3a, 0x5A, 0x70, 0x3a, 0x5d, +// [ : C c : ] [ : C f : ] - + 0x5b, 0x3a, 0x43, 0x63, 0x3a, 0x5d, 0x5b, 0x3a, 0x43, 0x66, 0x3a, 0x5d, 0x2d, +// [ : G r a p h e m e _ + 0x5b, 0x3a, 0x47, 0x72, 0x61, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x5f, +// E x t e n d : ] ] + 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x3a, 0x5d, 0x5d, 0}; + +static const UChar gGC_ExtendPattern[] = { // [ \ p { G r a p h e m e _ 0x5b, 0x5c, 0x70, 0x7b, 0x47, 0x72, 0x61, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x5f, // E x t e n d } ] 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x7d, 0x5d, 0}; - static const UChar gGC_LPattern[] = { -// [ \ p { H a n g u l _ S y l +static const UChar gGC_LPattern[] = { +// [ \ p { H a n g u l _ S y l 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c, // l a b l e _ T y p e = L } ] - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x7d, 0x5d, 0}; + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x7d, 0x5d, 0}; - static const UChar gGC_VPattern[] = { -// [ \ p { H a n g u l _ S y l +static const UChar gGC_VPattern[] = { +// [ \ p { H a n g u l _ S y l 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c, // l a b l e _ T y p e = V } ] - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x56, 0x7d, 0x5d, 0}; + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x56, 0x7d, 0x5d, 0}; - static const UChar gGC_TPattern[] = { -// [ \ p { H a n g u l _ S y l +static const UChar gGC_TPattern[] = { +// [ \ p { H a n g u l _ S y l 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c, // l a b l e _ T y p e = T } ] - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x54, 0x7d, 0x5d, 0}; + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x54, 0x7d, 0x5d, 0}; - static const UChar gGC_LVPattern[] = { -// [ \ p { H a n g u l _ S y l +static const UChar gGC_LVPattern[] = { +// [ \ p { H a n g u l _ S y l 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c, // l a b l e _ T y p e = L V } ] - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x7d, 0x5d, 0}; + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x7d, 0x5d, 0}; - static const UChar gGC_LVTPattern[] = { -// [ \ p { H a n g u l _ S y l +static const UChar gGC_LVTPattern[] = { +// [ \ p { H a n g u l _ S y l 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c, // l a b l e _ T y p e = L V T } ] - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x54, 0x7d, 0x5d, 0}; + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x54, 0x7d, 0x5d, 0}; -RegexStaticSets *RegexStaticSets::gStaticSets = NULL; -RegexStaticSets::RegexStaticSets(UErrorCode *status) { - // First zero out everything +RegexStaticSets *RegexStaticSets::gStaticSets = NULL; +UInitOnce gStaticSetsInitOnce = U_INITONCE_INITIALIZER; + +RegexStaticSets::RegexStaticSets(UErrorCode *status) +: +fUnescapeCharSet(UnicodeString(TRUE, gUnescapeCharPattern, -1), *status), +fRuleDigitsAlias(NULL), +fEmptyText(NULL) +{ + // First zero out everything int i; for (i=0; icomplement(); + fPropSets[URX_GC_NORMAL] = new UnicodeSet(0, UnicodeSet::MAX_VALUE); + // Null pointer check + if (fPropSets[URX_GC_NORMAL] == NULL) { + goto ExitConstrDeleteAll; + } fPropSets[URX_GC_NORMAL]->remove(0xac00, 0xd7a4); fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_CONTROL]); fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_L]); fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_V]); fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_T]); - + // Initialize the 8-bit fast bit sets from the parallel full // UnicodeSets. for (i=0; icompact(); + fPropSets8[i].init(fPropSets[i]); + } } // Sets used while parsing rules, but not referenced from the parse state table - fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(gRuleSet_rule_char_pattern, *status); - fRuleSets[kRuleSet_white_space-128] = new UnicodeSet(gRuleWhiteSpacePattern, *status); - fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(gRuleSet_digit_char_pattern, *status); - fRuleDigits = new UnicodeSet(gRuleSet_digit_char_pattern, *status); - fUnescapeCharSet = new UnicodeSet(gUnescapeCharPattern, *status); + fRuleSets[kRuleSet_rule_char-128] = UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status); + fRuleSets[kRuleSet_digit_char-128].add((UChar)0x30, (UChar)0x39); // [0-9] + fRuleSets[kRuleSet_ascii_letter-128].add((UChar)0x41, (UChar)0x5A); // [A-Z] + fRuleSets[kRuleSet_ascii_letter-128].add((UChar)0x61, (UChar)0x7A); // [a-z] + fRuleDigitsAlias = &fRuleSets[kRuleSet_digit_char-128]; + for (i=0; i