Index: source/i18n/regexcmp.cpp |
diff --git a/source/i18n/regexcmp.cpp b/source/i18n/regexcmp.cpp |
index afad2bdbfb80574d2ef7f34c70e1af4fd56616eb..0816eecfff5c885ccd30ccec8ad1ead4284998e1 100644 |
--- a/source/i18n/regexcmp.cpp |
+++ b/source/i18n/regexcmp.cpp |
@@ -1,7 +1,7 @@ |
// |
// file: regexcmp.cpp |
// |
-// Copyright (C) 2002-2013 International Business Machines Corporation and others. |
+// Copyright (C) 2002-2014 International Business Machines Corporation and others. |
// All Rights Reserved. |
// |
// This file contains the ICU regular expression compiler, which is responsible |
@@ -30,7 +30,6 @@ |
#include "uvectr32.h" |
#include "uvectr64.h" |
#include "uassert.h" |
-#include "ucln_in.h" |
#include "uinvchar.h" |
#include "regeximp.h" |
@@ -109,7 +108,7 @@ void RegexCompile::compile( |
fRXPat->fPatternString = new UnicodeString(pat); |
UText patternText = UTEXT_INITIALIZER; |
utext_openConstUnicodeString(&patternText, fRXPat->fPatternString, &e); |
- |
+ |
if (U_SUCCESS(e)) { |
compile(&patternText, pp, e); |
utext_close(&patternText); |
@@ -302,7 +301,7 @@ void RegexCompile::compile( |
// present in the saved state: the input string position (int64_t) and |
// the position in the compiled pattern. |
// |
- allocateStackData(RESTACKFRAME_HDRCOUNT); |
+ fRXPat->fFrameSize+=RESTACKFRAME_HDRCOUNT; |
// |
// Optimization pass 1: NOPs, back-references, and case-folding |
@@ -368,9 +367,9 @@ UBool RegexCompile::doParseActions(int32_t action) |
// the start of an ( grouping. |
//4 NOP Resreved, will be replaced by a save if there are |
// OR | operators at the top level |
- appendOp(URX_BUILD(URX_STATE_SAVE, 2)); |
- appendOp(URX_BUILD(URX_JMP, 3)); |
- appendOp(URX_BUILD(URX_FAIL, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_STATE_SAVE, 2), *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_JMP, 3), *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_FAIL, 0), *fStatus); |
// Standard open nonCapture paren action emits the two NOPs and |
// sets up the paren stack frame. |
@@ -393,7 +392,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
} |
// add the END operation to the compiled pattern. |
- appendOp(URX_BUILD(URX_END, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_END, 0), *fStatus); |
// Terminate the pattern compilation state machine. |
returnVal = FALSE; |
@@ -422,7 +421,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// the JMP will eventually be the location following the ')' for the |
// group. This will be patched in later, when the ')' is encountered. |
op = URX_BUILD(URX_JMP, 0); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Push the position of the newly added JMP op onto the parentheses stack. |
// This registers if for fixup when this block's close paren is encountered. |
@@ -431,7 +430,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Append a NOP to the compiled pattern. This is the slot reserved |
// for a SAVE in the event that there is yet another '|' following |
// this one. |
- appendOp(URX_BUILD(URX_NOP, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); |
} |
break; |
@@ -457,11 +456,12 @@ UBool RegexCompile::doParseActions(int32_t action) |
// END_CAPTURE is encountered. |
{ |
fixLiterals(); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
- int32_t varsLoc = allocateStackData(3); // Reserve three slots in match stack frame. |
- int32_t cop = URX_BUILD(URX_START_CAPTURE, varsLoc); |
- appendOp(cop); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
+ int32_t varsLoc = fRXPat->fFrameSize; // Reserve three slots in match stack frame. |
+ fRXPat->fFrameSize += 3; |
+ int32_t cop = URX_BUILD(URX_START_CAPTURE, varsLoc); |
+ fRXPat->fCompiledPat->addElement(cop, *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the two NOPs. Depending on what follows in the pattern, the |
@@ -486,8 +486,8 @@ UBool RegexCompile::doParseActions(int32_t action) |
// is an '|' alternation within the parens. |
{ |
fixLiterals(); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the two NOPs. |
@@ -509,11 +509,12 @@ UBool RegexCompile::doParseActions(int32_t action) |
// is an '|' alternation within the parens. |
{ |
fixLiterals(); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
- int32_t varLoc = allocateData(1); // Reserve a data location for saving the state stack ptr. |
- int32_t stoOp = URX_BUILD(URX_STO_SP, varLoc); |
- appendOp(stoOp); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
+ int32_t varLoc = fRXPat->fDataSize; // Reserve a data location for saving the |
+ fRXPat->fDataSize += 1; // state stack ptr. |
+ int32_t stoOp = URX_BUILD(URX_STO_SP, varLoc); |
+ fRXPat->fCompiledPat->addElement(stoOp, *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the two NOPs. Depending on what follows in the pattern, the |
@@ -556,25 +557,26 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Two data slots are reserved, for saving the stack ptr and the input position. |
{ |
fixLiterals(); |
- int32_t dataLoc = allocateData(2); |
+ int32_t dataLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize += 2; |
int32_t op = URX_BUILD(URX_LA_START, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_STATE_SAVE, fRXPat->fCompiledPat->size()+ 2); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_JMP, fRXPat->fCompiledPat->size()+ 3); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_LA_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_BACKTRACK, 0); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_NOP, 0); |
- appendOp(op); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the NOPs. |
@@ -599,15 +601,16 @@ UBool RegexCompile::doParseActions(int32_t action) |
// an alternate (transparent) region. |
{ |
fixLiterals(); |
- int32_t dataLoc = allocateData(2); |
+ int32_t dataLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize += 2; |
int32_t op = URX_BUILD(URX_LA_START, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_STATE_SAVE, 0); // dest address will be patched later. |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_NOP, 0); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the StateSave and NOP. |
@@ -645,22 +648,23 @@ UBool RegexCompile::doParseActions(int32_t action) |
fixLiterals(); |
// Allocate data space |
- int32_t dataLoc = allocateData(4); |
+ int32_t dataLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize += 4; |
// Emit URX_LB_START |
int32_t op = URX_BUILD(URX_LB_START, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Emit URX_LB_CONT |
op = URX_BUILD(URX_LB_CONT, dataLoc); |
- appendOp(op); |
- appendOp(0); // MinMatchLength. To be filled later. |
- appendOp(0); // MaxMatchLength. To be filled later. |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ fRXPat->fCompiledPat->addElement(0, *fStatus); // MinMatchLength. To be filled later. |
+ fRXPat->fCompiledPat->addElement(0, *fStatus); // MaxMatchLength. To be filled later. |
// Emit the NOP |
op = URX_BUILD(URX_NOP, 0); |
- appendOp(op); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the URX_LB_CONT and the NOP. |
@@ -700,23 +704,24 @@ UBool RegexCompile::doParseActions(int32_t action) |
fixLiterals(); |
// Allocate data space |
- int32_t dataLoc = allocateData(4); |
+ int32_t dataLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize += 4; |
// Emit URX_LB_START |
int32_t op = URX_BUILD(URX_LB_START, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Emit URX_LBN_CONT |
op = URX_BUILD(URX_LBN_CONT, dataLoc); |
- appendOp(op); |
- appendOp(0); // MinMatchLength. To be filled later. |
- appendOp(0); // MaxMatchLength. To be filled later. |
- appendOp(0); // Continue Loc. To be filled later. |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ fRXPat->fCompiledPat->addElement(0, *fStatus); // MinMatchLength. To be filled later. |
+ fRXPat->fCompiledPat->addElement(0, *fStatus); // MaxMatchLength. To be filled later. |
+ fRXPat->fCompiledPat->addElement(0, *fStatus); // Continue Loc. To be filled later. |
// Emit the NOP |
op = URX_BUILD(URX_NOP, 0); |
- appendOp(op); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the URX_LB_CONT and the NOP. |
@@ -787,10 +792,11 @@ UBool RegexCompile::doParseActions(int32_t action) |
if (URX_TYPE(repeatedOp) == URX_SETREF) { |
// Emit optimized code for [char set]+ |
int32_t loopOpI = URX_BUILD(URX_LOOP_SR_I, URX_VAL(repeatedOp)); |
- appendOp(loopOpI); |
- frameLoc = allocateStackData(1); |
+ fRXPat->fCompiledPat->addElement(loopOpI, *fStatus); |
+ frameLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t loopOpC = URX_BUILD(URX_LOOP_C, frameLoc); |
- appendOp(loopOpC); |
+ fRXPat->fCompiledPat->addElement(loopOpC, *fStatus); |
break; |
} |
@@ -806,10 +812,11 @@ UBool RegexCompile::doParseActions(int32_t action) |
if (fModeFlags & UREGEX_UNIX_LINES) { |
loopOpI |= 2; |
} |
- appendOp(loopOpI); |
- frameLoc = allocateStackData(1); |
+ fRXPat->fCompiledPat->addElement(loopOpI, *fStatus); |
+ frameLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t loopOpC = URX_BUILD(URX_LOOP_C, frameLoc); |
- appendOp(loopOpC); |
+ fRXPat->fCompiledPat->addElement(loopOpC, *fStatus); |
break; |
} |
@@ -823,17 +830,18 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Zero length match is possible. |
// Emit the code sequence that can handle it. |
insertOp(topLoc); |
- frameLoc = allocateStackData(1); |
+ frameLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t op = URX_BUILD(URX_STO_INP_LOC, frameLoc); |
fRXPat->fCompiledPat->setElementAt(op, topLoc); |
op = URX_BUILD(URX_JMP_SAV_X, topLoc+1); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} else { |
// Simpler code when the repeated body must match something non-empty |
int32_t jmpOp = URX_BUILD(URX_JMP_SAV, topLoc); |
- appendOp(jmpOp); |
+ fRXPat->fCompiledPat->addElement(jmpOp, *fStatus); |
} |
} |
break; |
@@ -846,7 +854,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
{ |
int32_t topLoc = blockTopLoc(FALSE); |
int32_t saveStateOp = URX_BUILD(URX_STATE_SAVE, topLoc); |
- appendOp(saveStateOp); |
+ fRXPat->fCompiledPat->addElement(saveStateOp, *fStatus); |
} |
break; |
@@ -883,10 +891,10 @@ UBool RegexCompile::doParseActions(int32_t action) |
fRXPat->fCompiledPat->setElementAt(jmp1_op, jmp1_loc); |
int32_t jmp2_op = URX_BUILD(URX_JMP, jmp2_loc+2); |
- appendOp(jmp2_op); |
+ fRXPat->fCompiledPat->addElement(jmp2_op, *fStatus); |
int32_t save_op = URX_BUILD(URX_STATE_SAVE, jmp1_loc+1); |
- appendOp(save_op); |
+ fRXPat->fCompiledPat->addElement(save_op, *fStatus); |
} |
break; |
@@ -928,9 +936,10 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Emit optimized code for a [char set]* |
int32_t loopOpI = URX_BUILD(URX_LOOP_SR_I, URX_VAL(repeatedOp)); |
fRXPat->fCompiledPat->setElementAt(loopOpI, topLoc); |
- dataLoc = allocateStackData(1); |
+ dataLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t loopOpC = URX_BUILD(URX_LOOP_C, dataLoc); |
- appendOp(loopOpC); |
+ fRXPat->fCompiledPat->addElement(loopOpC, *fStatus); |
break; |
} |
@@ -947,9 +956,10 @@ UBool RegexCompile::doParseActions(int32_t action) |
loopOpI |= 2; |
} |
fRXPat->fCompiledPat->setElementAt(loopOpI, topLoc); |
- dataLoc = allocateStackData(1); |
+ dataLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t loopOpC = URX_BUILD(URX_LOOP_C, dataLoc); |
- appendOp(loopOpC); |
+ fRXPat->fCompiledPat->addElement(loopOpC, *fStatus); |
break; |
} |
} |
@@ -964,7 +974,8 @@ UBool RegexCompile::doParseActions(int32_t action) |
// extra loop-breaking code. |
if (minMatchLength(saveStateLoc, fRXPat->fCompiledPat->size()-1) == 0) { |
insertOp(saveStateLoc); |
- dataLoc = allocateStackData(1); |
+ dataLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
int32_t op = URX_BUILD(URX_STO_INP_LOC, dataLoc); |
fRXPat->fCompiledPat->setElementAt(op, saveStateLoc+1); |
@@ -980,7 +991,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
fRXPat->fCompiledPat->setElementAt(saveStateOp, saveStateLoc); |
// Append the URX_JMP_SAV or URX_JMPX operation to the compiled pattern. |
- appendOp(jmpOp); |
+ fRXPat->fCompiledPat->addElement(jmpOp, *fStatus); |
} |
break; |
@@ -997,7 +1008,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
int32_t jmpOp = URX_BUILD(URX_JMP, saveLoc); |
int32_t stateSaveOp = URX_BUILD(URX_STATE_SAVE, jmpLoc+1); |
fRXPat->fCompiledPat->setElementAt(jmpOp, jmpLoc); |
- appendOp(stateSaveOp); |
+ fRXPat->fCompiledPat->addElement(stateSaveOp, *fStatus); |
} |
break; |
@@ -1066,9 +1077,9 @@ UBool RegexCompile::doParseActions(int32_t action) |
// First the STO_SP before the start of the loop |
insertOp(topLoc); |
- |
- int32_t varLoc = allocateData(1); // Reserve a data location for saving the |
- int32_t op = URX_BUILD(URX_STO_SP, varLoc); |
+ int32_t varLoc = fRXPat->fDataSize; // Reserve a data location for saving the |
+ fRXPat->fDataSize += 1; // state stack ptr. |
+ int32_t op = URX_BUILD(URX_STO_SP, varLoc); |
fRXPat->fCompiledPat->setElementAt(op, topLoc); |
int32_t loopOp = (int32_t)fRXPat->fCompiledPat->popi(); |
@@ -1078,7 +1089,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Then the LD_SP after the end of the loop |
op = URX_BUILD(URX_LD_SP, varLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1122,7 +1133,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
} else { |
op = URX_BUILD(URX_DOTANY, 0); |
} |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1135,11 +1146,11 @@ UBool RegexCompile::doParseActions(int32_t action) |
} else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) == 0) { |
op = URX_CARET_M; |
} else if ((fModeFlags & UREGEX_MULTILINE) == 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) { |
- op = URX_CARET; // Only testing true start of input. |
+ op = URX_CARET; // Only testing true start of input. |
} else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) { |
op = URX_CARET_M_UNIX; |
} |
- appendOp(URX_BUILD(op, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(op, 0), *fStatus); |
} |
break; |
@@ -1156,13 +1167,13 @@ UBool RegexCompile::doParseActions(int32_t action) |
} else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) { |
op = URX_DOLLAR_MD; |
} |
- appendOp(URX_BUILD(op, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(op, 0), *fStatus); |
} |
break; |
case doBackslashA: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_CARET, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_CARET, 0), *fStatus); |
break; |
case doBackslashB: |
@@ -1174,7 +1185,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
#endif |
fixLiterals(FALSE); |
int32_t op = (fModeFlags & UREGEX_UWORD)? URX_BACKSLASH_BU : URX_BACKSLASH_B; |
- appendOp(URX_BUILD(op, 1)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(op, 1), *fStatus); |
} |
break; |
@@ -1187,59 +1198,63 @@ UBool RegexCompile::doParseActions(int32_t action) |
#endif |
fixLiterals(FALSE); |
int32_t op = (fModeFlags & UREGEX_UWORD)? URX_BACKSLASH_BU : URX_BACKSLASH_B; |
- appendOp(URX_BUILD(op, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(op, 0), *fStatus); |
} |
break; |
case doBackslashD: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_BACKSLASH_D, 1)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKSLASH_D, 1), *fStatus); |
break; |
case doBackslashd: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_BACKSLASH_D, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKSLASH_D, 0), *fStatus); |
break; |
case doBackslashG: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_BACKSLASH_G, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKSLASH_G, 0), *fStatus); |
break; |
case doBackslashS: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_STAT_SETREF_N, URX_ISSPACE_SET)); |
+ fRXPat->fCompiledPat->addElement( |
+ URX_BUILD(URX_STAT_SETREF_N, URX_ISSPACE_SET), *fStatus); |
break; |
case doBackslashs: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_STATIC_SETREF, URX_ISSPACE_SET)); |
+ fRXPat->fCompiledPat->addElement( |
+ URX_BUILD(URX_STATIC_SETREF, URX_ISSPACE_SET), *fStatus); |
break; |
case doBackslashW: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_STAT_SETREF_N, URX_ISWORD_SET)); |
+ fRXPat->fCompiledPat->addElement( |
+ URX_BUILD(URX_STAT_SETREF_N, URX_ISWORD_SET), *fStatus); |
break; |
case doBackslashw: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_STATIC_SETREF, URX_ISWORD_SET)); |
+ fRXPat->fCompiledPat->addElement( |
+ URX_BUILD(URX_STATIC_SETREF, URX_ISWORD_SET), *fStatus); |
break; |
case doBackslashX: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_BACKSLASH_X, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKSLASH_X, 0), *fStatus); |
break; |
case doBackslashZ: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_DOLLAR, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_DOLLAR, 0), *fStatus); |
break; |
case doBackslashz: |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_BACKSLASH_Z, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKSLASH_Z, 0), *fStatus); |
break; |
case doEscapeError: |
@@ -1265,7 +1280,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
literalChar(c); |
} |
break; |
- |
+ |
case doBackRef: |
// BackReference. Somewhat unusual in that the front-end can not completely parse |
@@ -1305,7 +1320,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
} else { |
op = URX_BUILD(URX_BACKREF, groupNum); |
} |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1326,21 +1341,22 @@ UBool RegexCompile::doParseActions(int32_t action) |
{ |
// Emit the STO_SP |
int32_t topLoc = blockTopLoc(TRUE); |
- int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr. |
+ int32_t stoLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize++; // Reserve the data location for storing save stack ptr. |
int32_t op = URX_BUILD(URX_STO_SP, stoLoc); |
fRXPat->fCompiledPat->setElementAt(op, topLoc); |
// Emit the STATE_SAVE |
op = URX_BUILD(URX_STATE_SAVE, fRXPat->fCompiledPat->size()+2); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Emit the JMP |
op = URX_BUILD(URX_JMP, topLoc+1); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Emit the LD_SP |
op = URX_BUILD(URX_LD_SP, stoLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1360,7 +1376,8 @@ UBool RegexCompile::doParseActions(int32_t action) |
insertOp(topLoc); |
// emit STO_SP loc |
- int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr. |
+ int32_t stoLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize++; // Reserve the data location for storing save stack ptr. |
int32_t op = URX_BUILD(URX_STO_SP, stoLoc); |
fRXPat->fCompiledPat->setElementAt(op, topLoc); |
@@ -1371,11 +1388,11 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Append the JMP operation. |
op = URX_BUILD(URX_JMP, topLoc+1); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Emit the LD_SP loc |
op = URX_BUILD(URX_LD_SP, stoLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1394,7 +1411,8 @@ UBool RegexCompile::doParseActions(int32_t action) |
insertOp(topLoc); |
// Emit the STO_SP |
- int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr. |
+ int32_t stoLoc = fRXPat->fDataSize; |
+ fRXPat->fDataSize++; // Reserve the data location for storing save stack ptr. |
int32_t op = URX_BUILD(URX_STO_SP, stoLoc); |
fRXPat->fCompiledPat->setElementAt(op, topLoc); |
@@ -1405,7 +1423,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// Emit the LD_SP |
op = URX_BUILD(URX_LD_SP, stoLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -1462,8 +1480,8 @@ UBool RegexCompile::doParseActions(int32_t action) |
// is an '|' alternation within the parens. |
{ |
fixLiterals(FALSE); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
- appendOp(URX_BUILD(URX_NOP, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_NOP, 0), *fStatus); |
// On the Parentheses stack, start a new frame and add the postions |
// of the two NOPs (a normal non-capturing () frame, except for the |
@@ -1624,7 +1642,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
compileSet(theSet); |
break; |
} |
- |
+ |
case doSetIntersection2: |
// Have scanned something like [abc&& |
setPushOp(setIntersection2); |
@@ -1635,7 +1653,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// This operation is the highest precedence set operation, so we can always do |
// it immediately, without waiting to see what follows. It is necessary to perform |
// any pending '-' or '&' operation first, because these have the same precedence |
- // as union-ing in a literal' |
+ // as union-ing in a literal' |
{ |
setEval(setUnion); |
UnicodeSet *s = (UnicodeSet *)fSetStack.peek(); |
@@ -1730,7 +1748,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
} // else error. scanProp() reported the error status already. |
} |
break; |
- |
+ |
case doSetProp: |
// Scanned a \p \P within [brackets]. |
{ |
@@ -1752,7 +1770,7 @@ UBool RegexCompile::doParseActions(int32_t action) |
// and ICU UnicodeSet behavior. |
{ |
if (fLastSetLiteral > fC.fChar) { |
- error(U_REGEX_INVALID_RANGE); |
+ error(U_REGEX_INVALID_RANGE); |
} |
UnicodeSet *s = (UnicodeSet *)fSetStack.peek(); |
s->add(fLastSetLiteral, fC.fChar); |
@@ -1811,7 +1829,7 @@ void RegexCompile::fixLiterals(UBool split) { |
int32_t indexOfLastCodePoint = fLiteralChars.moveIndex32(fLiteralChars.length(), -1); |
UChar32 lastCodePoint = fLiteralChars.char32At(indexOfLastCodePoint); |
- // Split: We need to ensure that the last item in the compiled pattern |
+ // Split: We need to ensure that the last item in the compiled pattern |
// refers only to the last literal scanned in the pattern, so that |
// quantifiers (*, +, etc.) affect only it, and not a longer string. |
// Split before case folding for case insensitive matches. |
@@ -1837,13 +1855,13 @@ void RegexCompile::fixLiterals(UBool split) { |
if (indexOfLastCodePoint == 0) { |
// Single character, emit a URX_ONECHAR op to match it. |
- if ((fModeFlags & UREGEX_CASE_INSENSITIVE) && |
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) && |
u_hasBinaryProperty(lastCodePoint, UCHAR_CASE_SENSITIVE)) { |
op = URX_BUILD(URX_ONECHAR_I, lastCodePoint); |
} else { |
op = URX_BUILD(URX_ONECHAR, lastCodePoint); |
} |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} else { |
// Two or more chars, emit a URX_STRING to match them. |
if (fModeFlags & UREGEX_CASE_INSENSITIVE) { |
@@ -1853,39 +1871,20 @@ void RegexCompile::fixLiterals(UBool split) { |
// into two single char ops, for efficiency. |
op = URX_BUILD(URX_STRING, fRXPat->fLiteralText.length()); |
} |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_STRING_LEN, fLiteralChars.length()); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Add this string into the accumulated strings of the compiled pattern. |
- // The total size of the accumulated strings must be restricted to 24 bits because |
- // string indexes appear as compiled pattern operand values. |
- // This is the only place that the pattern.fLiteralText string is modified. |
- |
fRXPat->fLiteralText.append(fLiteralChars); |
- if (U_SUCCESS(*fStatus) && fRXPat->fLiteralText.length() > 0x00ffffff) { |
- *fStatus = U_REGEX_PATTERN_TOO_BIG; |
- } |
} |
fLiteralChars.remove(); |
} |
-//------------------------------------------------------------------------------ |
-// |
-// appendOp() Append a new instruction onto the compiled pattern |
-// Includes error checking, limiting the size of the |
-// pattern to lengths that can be represented in the |
-// 24 bit operand field of an instruction. |
-// |
-//------------------------------------------------------------------------------ |
-void RegexCompile::appendOp(int32_t op) { |
- fRXPat->fCompiledPat->addElement(op, *fStatus); |
- if ((fRXPat->fCompiledPat->size() > 0x00fffff0) && U_SUCCESS(*fStatus)) { |
- *fStatus = U_REGEX_PATTERN_TOO_BIG; |
- } |
-} |
+ |
+ |
//------------------------------------------------------------------------------ |
@@ -1947,58 +1946,6 @@ void RegexCompile::insertOp(int32_t where) { |
} |
-//------------------------------------------------------------------------------ |
-// |
-// allocateData() Allocate storage in the matcher's static data area. |
-// Return the index for the newly allocated data. |
-// The storage won't actually exist until we are running a match |
-// operation, but the storage indexes are inserted into various |
-// opcodes while compiling the pattern. |
-// |
-//------------------------------------------------------------------------------ |
-int32_t RegexCompile::allocateData(int32_t size) { |
- if (U_FAILURE(*fStatus)) { |
- return 0; |
- } |
- if (size <= 0 || size > 0x100 || fRXPat->fDataSize < 0) { |
- *fStatus = U_REGEX_INTERNAL_ERROR; |
- return 0; |
- } |
- int32_t dataIndex = fRXPat->fDataSize; |
- fRXPat->fDataSize += size; |
- if (fRXPat->fDataSize >= 0x00fffff0) { |
- *fStatus = U_REGEX_PATTERN_TOO_BIG; |
- } |
- return dataIndex; |
-} |
- |
- |
-//------------------------------------------------------------------------------ |
-// |
-// allocateStackData() Allocate space in the back-tracking stack frame. |
-// Return the index for the newly allocated data. |
-// The frame indexes are inserted into various |
-// opcodes while compiling the pattern, meaning that frame |
-// size must be restricted to the size that will fit |
-// as an operand (24 bits). |
-// |
-//------------------------------------------------------------------------------ |
-int32_t RegexCompile::allocateStackData(int32_t size) { |
- if (U_FAILURE(*fStatus)) { |
- return 0; |
- } |
- if (size <= 0 || size > 0x100 || fRXPat->fFrameSize < 0) { |
- *fStatus = U_REGEX_INTERNAL_ERROR; |
- return 0; |
- } |
- int32_t dataIndex = fRXPat->fFrameSize; |
- fRXPat->fFrameSize += size; |
- if (fRXPat->fFrameSize >= 0x00fffff0) { |
- *fStatus = U_REGEX_PATTERN_TOO_BIG; |
- } |
- return dataIndex; |
-} |
- |
//------------------------------------------------------------------------------ |
// |
@@ -2117,7 +2064,7 @@ void RegexCompile::handleCloseParen() { |
int32_t frameVarLocation = URX_VAL(captureOp); |
int32_t endCaptureOp = URX_BUILD(URX_END_CAPTURE, frameVarLocation); |
- appendOp(endCaptureOp); |
+ fRXPat->fCompiledPat->addElement(endCaptureOp, *fStatus); |
} |
break; |
case atomic: |
@@ -2129,7 +2076,7 @@ void RegexCompile::handleCloseParen() { |
U_ASSERT(URX_TYPE(stoOp) == URX_STO_SP); |
int32_t stoLoc = URX_VAL(stoOp); |
int32_t ldOp = URX_BUILD(URX_LD_SP, stoLoc); |
- appendOp(ldOp); |
+ fRXPat->fCompiledPat->addElement(ldOp, *fStatus); |
} |
break; |
@@ -2139,7 +2086,7 @@ void RegexCompile::handleCloseParen() { |
U_ASSERT(URX_TYPE(startOp) == URX_LA_START); |
int32_t dataLoc = URX_VAL(startOp); |
int32_t op = URX_BUILD(URX_LA_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
break; |
@@ -2150,11 +2097,11 @@ void RegexCompile::handleCloseParen() { |
U_ASSERT(URX_TYPE(startOp) == URX_LA_START); |
int32_t dataLoc = URX_VAL(startOp); |
int32_t op = URX_BUILD(URX_LA_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_BACKTRACK, 0); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
op = URX_BUILD(URX_LA_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Patch the URX_SAVE near the top of the block. |
// The destination of the SAVE is the final LA_END that was just added. |
@@ -2175,9 +2122,9 @@ void RegexCompile::handleCloseParen() { |
U_ASSERT(URX_TYPE(startOp) == URX_LB_START); |
int32_t dataLoc = URX_VAL(startOp); |
int32_t op = URX_BUILD(URX_LB_END, dataLoc); |
- appendOp(op); |
- op = URX_BUILD(URX_LA_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
+ op = URX_BUILD(URX_LA_END, dataLoc); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Determine the min and max bounds for the length of the |
// string that the pattern can match. |
@@ -2185,10 +2132,6 @@ void RegexCompile::handleCloseParen() { |
int32_t patEnd = fRXPat->fCompiledPat->size() - 1; |
int32_t minML = minMatchLength(fMatchOpenParen, patEnd); |
int32_t maxML = maxMatchLength(fMatchOpenParen, patEnd); |
- if (URX_TYPE(maxML) != 0) { |
- error(U_REGEX_LOOK_BEHIND_LIMIT); |
- break; |
- } |
if (maxML == INT32_MAX) { |
error(U_REGEX_LOOK_BEHIND_LIMIT); |
break; |
@@ -2214,7 +2157,7 @@ void RegexCompile::handleCloseParen() { |
U_ASSERT(URX_TYPE(startOp) == URX_LB_START); |
int32_t dataLoc = URX_VAL(startOp); |
int32_t op = URX_BUILD(URX_LBN_END, dataLoc); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
// Determine the min and max bounds for the length of the |
// string that the pattern can match. |
@@ -2222,10 +2165,6 @@ void RegexCompile::handleCloseParen() { |
int32_t patEnd = fRXPat->fCompiledPat->size() - 1; |
int32_t minML = minMatchLength(fMatchOpenParen, patEnd); |
int32_t maxML = maxMatchLength(fMatchOpenParen, patEnd); |
- if (URX_TYPE(maxML) != 0) { |
- error(U_REGEX_LOOK_BEHIND_LIMIT); |
- break; |
- } |
if (maxML == INT32_MAX) { |
error(U_REGEX_LOOK_BEHIND_LIMIT); |
break; |
@@ -2280,7 +2219,7 @@ void RegexCompile::compileSet(UnicodeSet *theSet) |
case 0: |
{ |
// Set of no elements. Always fails to match. |
- appendOp(URX_BUILD(URX_BACKTRACK, 0)); |
+ fRXPat->fCompiledPat->addElement(URX_BUILD(URX_BACKTRACK, 0), *fStatus); |
delete theSet; |
} |
break; |
@@ -2302,7 +2241,7 @@ void RegexCompile::compileSet(UnicodeSet *theSet) |
int32_t setNumber = fRXPat->fSets->size(); |
fRXPat->fSets->addElement(theSet, *fStatus); |
int32_t setOp = URX_BUILD(URX_SETREF, setNumber); |
- appendOp(setOp); |
+ fRXPat->fCompiledPat->addElement(setOp, *fStatus); |
} |
} |
} |
@@ -2341,8 +2280,11 @@ void RegexCompile::compileInterval(int32_t InitOp, int32_t LoopOp) |
// counterLoc --> Loop counter |
// +1 --> Input index (for breaking non-progressing loops) |
// (Only present if unbounded upper limit on loop) |
- int32_t dataSize = fIntervalUpper < 0 ? 2 : 1; |
- int32_t counterLoc = allocateStackData(dataSize); |
+ int32_t counterLoc = fRXPat->fFrameSize; |
+ fRXPat->fFrameSize++; |
+ if (fIntervalUpper < 0) { |
+ fRXPat->fFrameSize++; |
+ } |
int32_t op = URX_BUILD(InitOp, counterLoc); |
fRXPat->fCompiledPat->setElementAt(op, topOfBlock); |
@@ -2362,7 +2304,7 @@ void RegexCompile::compileInterval(int32_t InitOp, int32_t LoopOp) |
// Apend the CTR_LOOP op. The operand is the location of the CTR_INIT op. |
// Goes at end of the block being looped over, so just append to the code so far. |
op = URX_BUILD(LoopOp, topOfBlock); |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
if ((fIntervalLow & 0xff000000) != 0 || |
(fIntervalUpper > 0 && (fIntervalUpper & 0xff000000) != 0)) { |
@@ -2386,15 +2328,7 @@ UBool RegexCompile::compileInlineInterval() { |
int32_t topOfBlock = blockTopLoc(FALSE); |
if (fIntervalUpper == 0) { |
// Pathological case. Attempt no matches, as if the block doesn't exist. |
- // Discard the generated code for the block. |
- // If the block included parens, discard the info pertaining to them as well. |
fRXPat->fCompiledPat->setSize(topOfBlock); |
- if (fMatchOpenParen >= topOfBlock) { |
- fMatchOpenParen = -1; |
- } |
- if (fMatchCloseParen >= topOfBlock) { |
- fMatchCloseParen = -1; |
- } |
return TRUE; |
} |
@@ -2429,12 +2363,12 @@ UBool RegexCompile::compileInlineInterval() { |
int32_t i; |
for (i=1; i<fIntervalUpper; i++ ) { |
if (i == fIntervalLow) { |
- appendOp(saveOp); |
+ fRXPat->fCompiledPat->addElement(saveOp, *fStatus); |
} |
if (i > fIntervalLow) { |
- appendOp(saveOp); |
+ fRXPat->fCompiledPat->addElement(saveOp, *fStatus); |
} |
- appendOp(op); |
+ fRXPat->fCompiledPat->addElement(op, *fStatus); |
} |
return TRUE; |
} |
@@ -2443,6 +2377,105 @@ UBool RegexCompile::compileInlineInterval() { |
//------------------------------------------------------------------------------ |
// |
+// caseInsensitiveStart given a single code point from a pattern string, determine the |
+// set of characters that could potentially begin a case-insensitive |
+// match of a string beginning with that character, using full Unicode |
+// case insensitive matching. |
+// |
+// This is used in optimizing find(). |
+// |
+// closeOver(USET_CASE_INSENSITIVE) does most of what is needed, but |
+// misses cases like this: |
+// A string from the pattern begins with 'ss' (although all we know |
+// in this context is that it begins with 's') |
+// The pattern could match a string beginning with a German sharp-s |
+// |
+// To the ordinary case closure for a character c, we add all other |
+// characters cx where the case closure of cx incudes a string form that begins |
+// with the original character c. |
+// |
+// This function could be made smarter. The full pattern string is available |
+// and it would be possible to verify that the extra characters being added |
+// to the starting set fully match, rather than having just a first-char of the |
+// folded form match. |
+// |
+//------------------------------------------------------------------------------ |
+void RegexCompile::findCaseInsensitiveStarters(UChar32 c, UnicodeSet *starterChars) { |
+ |
+// Machine Generated below. |
+// It may need updating with new versions of Unicode. |
+// Intltest test RegexTest::TestCaseInsensitiveStarters will fail if an update is needed. |
+// The update tool is here: svn+ssh://source.icu-project.org/repos/icu/tools/trunk/unicode/c/genregexcasing |
+ |
+// Machine Generated Data. Do not hand edit. |
+ static const UChar32 RECaseFixCodePoints[] = { |
+ 0x61, 0x66, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x77, 0x79, 0x2bc, |
+ 0x3ac, 0x3ae, 0x3b1, 0x3b7, 0x3b9, 0x3c1, 0x3c5, 0x3c9, 0x3ce, 0x565, |
+ 0x574, 0x57e, 0x1f00, 0x1f01, 0x1f02, 0x1f03, 0x1f04, 0x1f05, 0x1f06, 0x1f07, |
+ 0x1f20, 0x1f21, 0x1f22, 0x1f23, 0x1f24, 0x1f25, 0x1f26, 0x1f27, 0x1f60, 0x1f61, |
+ 0x1f62, 0x1f63, 0x1f64, 0x1f65, 0x1f66, 0x1f67, 0x1f70, 0x1f74, 0x1f7c, 0x110000}; |
+ |
+ static const int16_t RECaseFixStringOffsets[] = { |
+ 0x0, 0x1, 0x6, 0x7, 0x8, 0x9, 0xd, 0xe, 0xf, 0x10, |
+ 0x11, 0x12, 0x13, 0x17, 0x1b, 0x20, 0x21, 0x2a, 0x2e, 0x2f, |
+ 0x30, 0x34, 0x35, 0x37, 0x39, 0x3b, 0x3d, 0x3f, 0x41, 0x43, |
+ 0x45, 0x47, 0x49, 0x4b, 0x4d, 0x4f, 0x51, 0x53, 0x55, 0x57, |
+ 0x59, 0x5b, 0x5d, 0x5f, 0x61, 0x63, 0x65, 0x66, 0x67, 0}; |
+ |
+ static const int16_t RECaseFixCounts[] = { |
+ 0x1, 0x5, 0x1, 0x1, 0x1, 0x4, 0x1, 0x1, 0x1, 0x1, |
+ 0x1, 0x1, 0x4, 0x4, 0x5, 0x1, 0x9, 0x4, 0x1, 0x1, |
+ 0x4, 0x1, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, |
+ 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, |
+ 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0}; |
+ |
+ static const UChar RECaseFixData[] = { |
+ 0x1e9a, 0xfb00, 0xfb01, 0xfb02, 0xfb03, 0xfb04, 0x1e96, 0x130, 0x1f0, 0xdf, |
+ 0x1e9e, 0xfb05, 0xfb06, 0x1e97, 0x1e98, 0x1e99, 0x149, 0x1fb4, 0x1fc4, 0x1fb3, |
+ 0x1fb6, 0x1fb7, 0x1fbc, 0x1fc3, 0x1fc6, 0x1fc7, 0x1fcc, 0x390, 0x1fd2, 0x1fd3, |
+ 0x1fd6, 0x1fd7, 0x1fe4, 0x3b0, 0x1f50, 0x1f52, 0x1f54, 0x1f56, 0x1fe2, 0x1fe3, |
+ 0x1fe6, 0x1fe7, 0x1ff3, 0x1ff6, 0x1ff7, 0x1ffc, 0x1ff4, 0x587, 0xfb13, 0xfb14, |
+ 0xfb15, 0xfb17, 0xfb16, 0x1f80, 0x1f88, 0x1f81, 0x1f89, 0x1f82, 0x1f8a, 0x1f83, |
+ 0x1f8b, 0x1f84, 0x1f8c, 0x1f85, 0x1f8d, 0x1f86, 0x1f8e, 0x1f87, 0x1f8f, 0x1f90, |
+ 0x1f98, 0x1f91, 0x1f99, 0x1f92, 0x1f9a, 0x1f93, 0x1f9b, 0x1f94, 0x1f9c, 0x1f95, |
+ 0x1f9d, 0x1f96, 0x1f9e, 0x1f97, 0x1f9f, 0x1fa0, 0x1fa8, 0x1fa1, 0x1fa9, 0x1fa2, |
+ 0x1faa, 0x1fa3, 0x1fab, 0x1fa4, 0x1fac, 0x1fa5, 0x1fad, 0x1fa6, 0x1fae, 0x1fa7, |
+ 0x1faf, 0x1fb2, 0x1fc2, 0x1ff2, 0}; |
+ |
+// End of machine generated data. |
+ |
+ if (u_hasBinaryProperty(c, UCHAR_CASE_SENSITIVE)) { |
+ UChar32 caseFoldedC = u_foldCase(c, U_FOLD_CASE_DEFAULT); |
+ starterChars->set(caseFoldedC, caseFoldedC); |
+ |
+ int32_t i; |
+ for (i=0; RECaseFixCodePoints[i]<c ; i++) { |
+ // Simple linear search through the sorted list of interesting code points. |
+ } |
+ |
+ if (RECaseFixCodePoints[i] == c) { |
+ int32_t dataIndex = RECaseFixStringOffsets[i]; |
+ int32_t numCharsToAdd = RECaseFixCounts[i]; |
+ UChar32 cpToAdd = 0; |
+ for (int32_t j=0; j<numCharsToAdd; j++) { |
+ U16_NEXT_UNSAFE(RECaseFixData, dataIndex, cpToAdd); |
+ starterChars->add(cpToAdd); |
+ } |
+ } |
+ |
+ starterChars->closeOver(USET_CASE_INSENSITIVE); |
+ starterChars->removeAllStrings(); |
+ } else { |
+ // Not a cased character. Just return it alone. |
+ starterChars->set(c, c); |
+ } |
+} |
+ |
+ |
+ |
+ |
+//------------------------------------------------------------------------------ |
+// |
// matchStartType Determine how a match can start. |
// Used to optimize find() operations. |
// |
@@ -2514,7 +2547,7 @@ void RegexCompile::matchStartType() { |
case URX_STO_INP_LOC: |
case URX_BACKREF: // BackRef. Must assume that it might be a zero length match |
case URX_BACKREF_I: |
- |
+ |
case URX_STO_SP: // Setup for atomic or possessive blocks. Doesn't change what can match. |
case URX_LD_SP: |
break; |
@@ -2631,17 +2664,12 @@ void RegexCompile::matchStartType() { |
if (currentLen == 0) { |
UChar32 c = URX_VAL(op); |
if (u_hasBinaryProperty(c, UCHAR_CASE_SENSITIVE)) { |
- |
- // Disable optimizations on first char of match. |
- // TODO: Compute the set of chars that case fold to this char, or to |
- // a string that begins with this char. |
- // For simple case folding, this code worked: |
- // UnicodeSet s(c, c); |
- // s.closeOver(USET_CASE_INSENSITIVE); |
- // fRXPat->fInitialChars->addAll(s); |
- |
- fRXPat->fInitialChars->clear(); |
- fRXPat->fInitialChars->complement(); |
+ UnicodeSet starters(c, c); |
+ starters.closeOver(USET_CASE_INSENSITIVE); |
+ // findCaseInsensitiveStarters(c, &starters); |
+ // For ONECHAR_I, no need to worry about text chars that expand on folding into strings. |
+ // The expanded folding can't match the pattern. |
+ fRXPat->fInitialChars->addAll(starters); |
} else { |
// Char has no case variants. Just add it as-is to the |
// set of possible starting chars. |
@@ -2764,14 +2792,8 @@ void RegexCompile::matchStartType() { |
// characters for this pattern. |
int32_t stringStartIdx = URX_VAL(op); |
UChar32 c = fRXPat->fLiteralText.char32At(stringStartIdx); |
- UnicodeSet s(c, c); |
- |
- // TODO: compute correct set of starting chars for full case folding. |
- // For the moment, say any char can start. |
- // s.closeOver(USET_CASE_INSENSITIVE); |
- s.clear(); |
- s.complement(); |
- |
+ UnicodeSet s; |
+ findCaseInsensitiveStarters(c, &s); |
fRXPat->fInitialChars->addAll(s); |
numInitialStrings += 2; // Matching on an initial string not possible. |
} |
@@ -2827,7 +2849,7 @@ void RegexCompile::matchStartType() { |
{ |
// Look-around. Scan forward until the matching look-ahead end, |
// without processing the look-around block. This is overly pessimistic. |
- |
+ |
// Keep track of the nesting depth of look-around blocks. Boilerplate code for |
// lookahead contains two LA_END instructions, so count goes up by two |
// for each LA_START. |
@@ -3387,7 +3409,7 @@ int32_t RegexCompile::maxMatchLength(int32_t start, int32_t end) { |
// compiled (folded) string. Folding may add code points, but |
// not remove them. |
// |
- // There is a potential problem if a supplemental code point |
+ // There is a potential problem if a supplemental code point |
// case-folds to a BMP code point. In this case our compiled string |
// could be shorter (in code units) than a matching user string. |
// |
@@ -3418,7 +3440,7 @@ int32_t RegexCompile::maxMatchLength(int32_t start, int32_t end) { |
loc = loopEndLoc; |
break; |
} |
- |
+ |
int32_t maxLoopCount = fRXPat->fCompiledPat->elementAti(loc+3); |
if (maxLoopCount == -1) { |
// Unbounded Loop. No upper bound on match length. |
@@ -3536,7 +3558,7 @@ void RegexCompile::stripNOPs() { |
d++; |
} |
} |
- |
+ |
UnicodeString caseStringBuffer; |
// Make a second pass over the code, removing the NOPs by moving following |
@@ -3583,7 +3605,7 @@ void RegexCompile::stripNOPs() { |
op = URX_BUILD(opType, where); |
fRXPat->fCompiledPat->setElementAt(op, dst); |
dst++; |
- |
+ |
fRXPat->fNeedsAltInput = TRUE; |
break; |
} |
@@ -3674,7 +3696,7 @@ void RegexCompile::error(UErrorCode e) { |
fParseErr->line = (int32_t)fLineNum; |
fParseErr->offset = (int32_t)fCharNum; |
} |
- |
+ |
UErrorCode status = U_ZERO_ERROR; // throwaway status for extracting context |
// Fill in the context. |
@@ -3728,7 +3750,7 @@ UChar32 RegexCompile::nextCharLL() { |
fPeekChar = -1; |
return ch; |
} |
- |
+ |
// assume we're already in the right place |
ch = UTEXT_NEXT32(fRXPat->fPattern); |
if (ch == U_SENTINEL) { |
@@ -3784,7 +3806,7 @@ void RegexCompile::nextChar(RegexPatternChar &c) { |
if (fQuoteMode) { |
c.fQuoted = TRUE; |
- if ((c.fChar==chBackSlash && peekCharLL()==chE && ((fModeFlags & UREGEX_LITERAL) == 0)) || |
+ if ((c.fChar==chBackSlash && peekCharLL()==chE && ((fModeFlags & UREGEX_LITERAL) == 0)) || |
c.fChar == (UChar32)-1) { |
fQuoteMode = FALSE; // Exit quote mode, |
nextCharLL(); // discard the E |
@@ -3845,11 +3867,11 @@ void RegexCompile::nextChar(RegexPatternChar &c) { |
// |
nextCharLL(); // get & discard the peeked char. |
c.fQuoted = TRUE; |
- |
+ |
if (UTEXT_FULL_TEXT_IN_CHUNK(fRXPat->fPattern, fPatternLength)) { |
int32_t endIndex = (int32_t)pos; |
c.fChar = u_unescapeAt(uregex_ucstr_unescape_charAt, &endIndex, (int32_t)fPatternLength, (void *)fRXPat->fPattern->chunkContents); |
- |
+ |
if (endIndex == pos) { |
error(U_REGEX_BAD_ESCAPE_SEQUENCE); |
} |
@@ -3858,7 +3880,7 @@ void RegexCompile::nextChar(RegexPatternChar &c) { |
} else { |
int32_t offset = 0; |
struct URegexUTextUnescapeCharContext context = U_REGEX_UTEXT_UNESCAPE_CONTEXT(fRXPat->fPattern); |
- |
+ |
UTEXT_SETNATIVEINDEX(fRXPat->fPattern, pos); |
c.fChar = u_unescapeAt(uregex_utext_unescape_charAt, &offset, INT32_MAX, &context); |
@@ -3901,8 +3923,8 @@ void RegexCompile::nextChar(RegexPatternChar &c) { |
c.fChar >>= 3; |
} |
} |
- c.fQuoted = TRUE; |
- } |
+ c.fQuoted = TRUE; |
+ } |
else if (peekCharLL() == chQ) { |
// "\Q" enter quote mode, which will continue until "\E" |
fQuoteMode = TRUE; |
@@ -3950,7 +3972,7 @@ UChar32 RegexCompile::scanNamedChar() { |
error(U_REGEX_PROPERTY_SYNTAX); |
return 0; |
} |
- |
+ |
UnicodeString charName; |
for (;;) { |
nextChar(fC); |
@@ -3963,7 +3985,7 @@ UChar32 RegexCompile::scanNamedChar() { |
} |
charName.append(fC.fChar); |
} |
- |
+ |
char name[100]; |
if (!uprv_isInvariantUString(charName.getBuffer(), charName.length()) || |
(uint32_t)charName.length()>=sizeof(name)) { |
@@ -4002,6 +4024,7 @@ UnicodeSet *RegexCompile::scanProp() { |
if (U_FAILURE(*fStatus)) { |
return NULL; |
} |
+ (void)chLowerP; // Suppress compiler unused variable warning. |
U_ASSERT(fC.fChar == chLowerP || fC.fChar == chP); |
UBool negated = (fC.fChar == chP); |
@@ -4071,7 +4094,7 @@ UnicodeSet *RegexCompile::scanPosixProp() { |
// Scan for a closing ]. A little tricky because there are some perverse |
// edge cases possible. "[:abc\Qdef:] \E]" is a valid non-property expression, |
- // ending on the second closing ]. |
+ // ending on the second closing ]. |
UnicodeString propName; |
UBool negated = FALSE; |
@@ -4082,7 +4105,7 @@ UnicodeSet *RegexCompile::scanPosixProp() { |
negated = TRUE; |
nextChar(fC); |
} |
- |
+ |
// Scan for the closing ":]", collecting the property name along the way. |
UBool sawPropSetTerminator = FALSE; |
for (;;) { |
@@ -4100,7 +4123,7 @@ UnicodeSet *RegexCompile::scanPosixProp() { |
break; |
} |
} |
- |
+ |
if (sawPropSetTerminator) { |
uset = createSetForProperty(propName, negated); |
} |
@@ -4133,7 +4156,7 @@ static inline void addIdentifierIgnorable(UnicodeSet *set, UErrorCode& ec) { |
// Create a Unicode Set from a Unicode Property expression. |
// This is common code underlying both \p{...} ane [:...:] expressions. |
// Includes trying the Java "properties" that aren't supported as |
-// normal ICU UnicodeSet properties |
+// normal ICU UnicodeSet properties |
// |
static const UChar posSetPrefix[] = {0x5b, 0x5c, 0x70, 0x7b, 0}; // "[\p{" |
static const UChar negSetPrefix[] = {0x5b, 0x5c, 0x50, 0x7b, 0}; // "[\P{" |
@@ -4141,7 +4164,7 @@ UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UB |
UnicodeString setExpr; |
UnicodeSet *set; |
uint32_t usetFlags = 0; |
- |
+ |
if (U_FAILURE(*fStatus)) { |
return NULL; |
} |
@@ -4166,13 +4189,13 @@ UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UB |
} |
delete set; |
set = NULL; |
- |
+ |
// |
// The property as it was didn't work. |
- // Do [:word:]. It is not recognized as a property by UnicodeSet. "word" not standard POSIX |
+ // Do [:word:]. It is not recognized as a property by UnicodeSet. "word" not standard POSIX |
// or standard Java, but many other regular expression packages do recognize it. |
- |
+ |
if (propName.caseCompare(UNICODE_STRING_SIMPLE("word"), 0) == 0) { |
*fStatus = U_ZERO_ERROR; |
set = new UnicodeSet(*(fRXPat->fStaticSets[URX_ISWORD_SET])); |
@@ -4192,7 +4215,7 @@ UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UB |
// InCombiningMarksforSymbols -> InCombiningDiacriticalMarksforSymbols. |
// |
// Note on Spaces: either "InCombiningMarksForSymbols" or "InCombining Marks for Symbols" |
- // is accepted by Java. The property part of the name is compared |
+ // is accepted by Java. The property part of the name is compared |
// case-insenstively. The spaces must be exactly as shown, either |
// all there, or all omitted, with exactly one at each position |
// if they are present. From checking against JDK 1.6 |
@@ -4211,7 +4234,7 @@ UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UB |
else if (mPropName.compare(UNICODE_STRING_SIMPLE("all")) == 0) { |
mPropName = UNICODE_STRING_SIMPLE("javaValidCodePoint"); |
} |
- |
+ |
// See if the property looks like a Java "InBlockName", which |
// we will recast as "Block=BlockName" |
// |
@@ -4335,7 +4358,7 @@ UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UB |
set = NULL; |
} |
error(*fStatus); |
- return NULL; |
+ return NULL; |
} |