#include "unicode/utypes.h"
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
#include "unicode/regex.h"
#include "unicode/uniset.h"
#include "unicode/uchar.h"
#include "unicode/ustring.h"
#include "unicode/rbbi.h"
#include "uassert.h"
#include "cmemory.h"
#include "uvector.h"
#include "uvectr32.h"
#include "regeximp.h"
#include "regexst.h"
U_NAMESPACE_BEGIN
RegexMatcher::RegexMatcher(const RegexPattern *pat) {
fPattern = pat;
fPatternOwned = NULL;
fInput = NULL;
fTraceDebug = FALSE;
fDeferredStatus = U_ZERO_ERROR;
fStack = new UVector32(fDeferredStatus);
fData = fSmallData;
fWordBreakItr = NULL;
if (pat==NULL) {
fDeferredStatus = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if (pat->fDataSize > (int32_t)(sizeof(fSmallData)/sizeof(int32_t))) {
fData = (int32_t *)uprv_malloc(pat->fDataSize * sizeof(int32_t));
}
if (fStack == NULL || fData == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
}
reset(*RegexStaticSets::gStaticSets->fEmptyString);
}
RegexMatcher::RegexMatcher(const UnicodeString ®exp, const UnicodeString &input,
uint32_t flags, UErrorCode &status) {
UParseError pe;
fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
fPattern = fPatternOwned;
fTraceDebug = FALSE;
fDeferredStatus = U_ZERO_ERROR;
fStack = new UVector32(status);
fData = fSmallData;
fWordBreakItr = NULL;
if (U_FAILURE(status)) {
return;
}
if (fPattern->fDataSize > (int32_t)(sizeof(fSmallData)/sizeof(int32_t))) {
fData = (int32_t *)uprv_malloc(fPattern->fDataSize * sizeof(int32_t));
}
if (fStack == NULL || fData == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
reset(input);
}
RegexMatcher::RegexMatcher(const UnicodeString ®exp,
uint32_t flags, UErrorCode &status) {
UParseError pe;
fTraceDebug = FALSE;
fDeferredStatus = U_ZERO_ERROR;
fStack = new UVector32(status);
fData = fSmallData;
fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
fPattern = fPatternOwned;
fWordBreakItr = NULL;
if (U_FAILURE(status)) {
return;
}
if (fPattern->fDataSize > (int32_t)(sizeof(fSmallData)/sizeof(int32_t))) {
fData = (int32_t *)uprv_malloc(fPattern->fDataSize * sizeof(int32_t));
}
if (fStack == NULL || fData == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
reset(*RegexStaticSets::gStaticSets->fEmptyString);
}
RegexMatcher::~RegexMatcher() {
delete fStack;
if (fData != fSmallData) {
uprv_free(fData);
fData = NULL;
}
if (fPatternOwned) {
delete fPatternOwned;
fPatternOwned = NULL;
fPattern = NULL;
}
#if UCONFIG_NO_BREAK_ITERATION==0
delete fWordBreakItr;
#endif
}
static const UChar BACKSLASH = 0x5c;
static const UChar DOLLARSIGN = 0x24;
RegexMatcher &RegexMatcher::appendReplacement(UnicodeString &dest,
const UnicodeString &replacement,
UErrorCode &status) {
if (U_FAILURE(status)) {
return *this;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return *this;
}
if (fMatch == FALSE) {
status = U_REGEX_INVALID_STATE;
return *this;
}
int32_t len = fMatchStart-fLastReplaceEnd;
if (len > 0) {
dest.append(*fInput, fLastReplaceEnd, len);
}
fLastReplaceEnd = fMatchEnd;
int32_t replLen = replacement.length();
int32_t replIdx = 0;
while (replIdx<replLen) {
UChar c = replacement.charAt(replIdx);
replIdx++;
if (c == BACKSLASH) {
if (replIdx >= replLen) {
break;
}
c = replacement.charAt(replIdx);
if (c==0x55 || c==0x75) {
UChar32 escapedChar = replacement.unescapeAt(replIdx);
if (escapedChar != (UChar32)0xFFFFFFFF) {
dest.append(escapedChar);
continue;
}
}
dest.append(c);
replIdx++;
continue;
}
if (c != DOLLARSIGN) {
dest.append(c);
continue;
}
int32_t numDigits = 0;
int32_t groupNum = 0;
UChar32 digitC;
for (;;) {
if (replIdx >= replLen) {
break;
}
digitC = replacement.char32At(replIdx);
if (u_isdigit(digitC) == FALSE) {
break;
}
replIdx = replacement.moveIndex32(replIdx, 1);
groupNum=groupNum*10 + u_charDigitValue(digitC);
numDigits++;
if (numDigits >= fPattern->fMaxCaptureDigits) {
break;
}
}
if (numDigits == 0) {
dest.append(DOLLARSIGN);
continue;
}
dest.append(group(groupNum, status));
if (U_FAILURE(status)) {
break;
}
}
return *this;
}
UnicodeString &RegexMatcher::appendTail(UnicodeString &dest) {
int32_t len = fInput->length()-fMatchEnd;
if (len > 0) {
dest.append(*fInput, fMatchEnd, len);
}
return dest;
}
int32_t RegexMatcher::end(UErrorCode &err) const {
return end(0, err);
}
int32_t RegexMatcher::end(int group, UErrorCode &err) const {
if (U_FAILURE(err)) {
return -1;
}
if (fMatch == FALSE) {
err = U_REGEX_INVALID_STATE;
return -1;
}
if (group < 0 || group > fPattern->fGroupMap->size()) {
err = U_INDEX_OUTOFBOUNDS_ERROR;
return -1;
}
int32_t e = -1;
if (group == 0) {
e = fMatchEnd;
} else {
int32_t groupOffset = fPattern->fGroupMap->elementAti(group-1);
U_ASSERT(groupOffset < fPattern->fFrameSize);
U_ASSERT(groupOffset >= 0);
e = fFrame->fExtra[groupOffset + 1];
}
return e;
}
UBool RegexMatcher::find() {
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
int32_t startPos = fMatchEnd;
if (fMatch) {
fLastMatchEnd = fMatchEnd;
if (fMatchStart == fMatchEnd) {
if (startPos == fInput->length()) {
fMatch = FALSE;
return FALSE;
}
startPos = fInput->moveIndex32(startPos, 1);
}
} else {
if (fLastMatchEnd >= 0) {
return FALSE;
}
}
int32_t inputLen = fInput->length();
int32_t testLen = inputLen - fPattern->fMinMatchLen;
if (startPos > testLen) {
fMatch = FALSE;
return FALSE;
}
const UChar *inputBuf = fInput->getBuffer();
UChar32 c;
U_ASSERT(startPos >= 0);
switch (fPattern->fStartType) {
case START_NO_INFO:
for (;;) {
MatchAt(startPos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
if (fMatch) {
return TRUE;
}
if (startPos >= testLen) {
return FALSE;
}
U16_FWD_1(inputBuf, startPos, inputLen);
}
U_ASSERT(FALSE);
case START_START:
if (startPos > 0) {
fMatch = FALSE;
return FALSE;
}
MatchAt(startPos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
return fMatch;
case START_SET:
{
U_ASSERT(fPattern->fMinMatchLen > 0);
for (;;) {
int32_t pos = startPos;
U16_NEXT(inputBuf, startPos, inputLen, c); if (c<256 && fPattern->fInitialChars8->contains(c) ||
c>=256 && fPattern->fInitialChars->contains(c)) {
MatchAt(pos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
if (fMatch) {
return TRUE;
}
}
if (pos >= testLen) {
fMatch = FALSE;
return FALSE;
}
}
}
U_ASSERT(FALSE);
case START_STRING:
case START_CHAR:
{
U_ASSERT(fPattern->fMinMatchLen > 0);
UChar32 theChar = fPattern->fInitialChar;
for (;;) {
int32_t pos = startPos;
U16_NEXT(inputBuf, startPos, inputLen, c); if (c == theChar) {
MatchAt(pos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
if (fMatch) {
return TRUE;
}
}
if (pos >= testLen) {
fMatch = FALSE;
return FALSE;
}
}
}
U_ASSERT(FALSE);
case START_LINE:
{
UChar32 c;
if (startPos == 0) {
MatchAt(startPos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
if (fMatch) {
return TRUE;
}
U16_NEXT(inputBuf, startPos, inputLen, c); }
for (;;) {
c = inputBuf[startPos-1];
if (((c & 0x7f) <= 0x29) && (c == 0x0a || c == 0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029 )) {
if (c == 0x0d && startPos < inputLen && inputBuf[startPos] == 0x0a) {
startPos++;
}
MatchAt(startPos, fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return FALSE;
}
if (fMatch) {
return TRUE;
}
}
if (startPos >= testLen) {
fMatch = FALSE;
return FALSE;
}
U16_NEXT(inputBuf, startPos, inputLen, c); }
}
default:
U_ASSERT(FALSE);
}
U_ASSERT(FALSE);
return FALSE;
}
UBool RegexMatcher::find(int32_t start, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return FALSE;
}
int32_t inputLen = fInput->length();
if (start < 0 || start > inputLen) {
status = U_INDEX_OUTOFBOUNDS_ERROR;
return FALSE;
}
this->reset();
fMatchEnd = start;
return find();
}
UnicodeString RegexMatcher::group(UErrorCode &status) const {
return group(0, status);
}
UnicodeString RegexMatcher::group(int32_t groupNum, UErrorCode &status) const {
int32_t s = start(groupNum, status);
int32_t e = end(groupNum, status);
if (U_FAILURE(status)) {
return UnicodeString();
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return UnicodeString();
}
if (s < 0) {
return UnicodeString();
}
U_ASSERT(s <= e);
return UnicodeString(*fInput, s, e-s);
}
int32_t RegexMatcher::groupCount() const {
return fPattern->fGroupMap->size();
}
const UnicodeString &RegexMatcher::input() const {
return *fInput;
}
UBool RegexMatcher::lookingAt(UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return FALSE;
}
reset();
MatchAt(0, status);
return fMatch;
}
UBool RegexMatcher::lookingAt(int32_t start, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return FALSE;
}
if (start < 0 || start > fInput->length()) {
status = U_INDEX_OUTOFBOUNDS_ERROR;
return FALSE;
}
reset();
MatchAt(start, status);
return fMatch;
}
UBool RegexMatcher::matches(UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return FALSE;
}
reset();
MatchAt(0, status);
UBool success = (fMatch && fMatchEnd==fInput->length());
return success;
}
UBool RegexMatcher::matches(int32_t start, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return FALSE;
}
if (start < 0 || start > fInput->length()) {
status = U_INDEX_OUTOFBOUNDS_ERROR;
return FALSE;
}
reset();
MatchAt(start, status);
UBool success = (fMatch && fMatchEnd==fInput->length());
return success;
}
const RegexPattern &RegexMatcher::pattern() const {
return *fPattern;
}
UnicodeString RegexMatcher::replaceAll(const UnicodeString &replacement, UErrorCode &status) {
if (U_FAILURE(status)) {
return *fInput;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return *fInput;
}
UnicodeString destString;
for (reset(); find(); ) {
appendReplacement(destString, replacement, status);
if (U_FAILURE(status)) {
break;
}
}
appendTail(destString);
return destString;
}
UnicodeString RegexMatcher::replaceFirst(const UnicodeString &replacement, UErrorCode &status) {
if (U_FAILURE(status)) {
return *fInput;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return *fInput;
}
reset();
if (!find()) {
return *fInput;
}
UnicodeString destString;
appendReplacement(destString, replacement, status);
appendTail(destString);
return destString;
}
RegexMatcher &RegexMatcher::reset() {
fMatchStart = 0;
fMatchEnd = 0;
fLastMatchEnd = -1;
fLastReplaceEnd = 0;
fMatch = FALSE;
resetStack();
return *this;
}
RegexMatcher &RegexMatcher::reset(const UnicodeString &input) {
fInput = &input;
reset();
if (fWordBreakItr != NULL) {
#if UCONFIG_NO_BREAK_ITERATION==0
fWordBreakItr->setText(input);
#endif
}
return *this;
}
RegexMatcher &RegexMatcher::reset(const UChar *) {
fDeferredStatus = U_INTERNAL_PROGRAM_ERROR;
return *this;
}
RegexMatcher &RegexMatcher::reset(int32_t position, UErrorCode &status) {
if (U_FAILURE(status)) {
return *this;
}
reset();
if (position < 0 || position >= fInput->length()) {
status = U_INDEX_OUTOFBOUNDS_ERROR;
return *this;
}
fMatchEnd = position;
return *this;
}
void RegexMatcher::setTrace(UBool state) {
fTraceDebug = state;
}
int32_t RegexMatcher::split(const UnicodeString &input,
UnicodeString dest[],
int32_t destCapacity,
UErrorCode &status)
{
if (U_FAILURE(status)) {
return 0;
};
if (destCapacity < 1) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
reset(input);
int32_t inputLen = input.length();
int32_t nextOutputStringStart = 0;
if (inputLen == 0) {
return 0;
}
int i;
int32_t numCaptureGroups = fPattern->fGroupMap->size();
for (i=0; ; i++) {
if (i>=destCapacity-1) {
i = destCapacity-1;
int32_t remainingLength = inputLen-nextOutputStringStart;
if (remainingLength > 0) {
dest[i].setTo(input, nextOutputStringStart, remainingLength);
}
break;
}
if (find()) {
int32_t fieldLen = fMatchStart - nextOutputStringStart;
dest[i].setTo(input, nextOutputStringStart, fieldLen);
nextOutputStringStart = fMatchEnd;
int32_t groupNum;
for (groupNum=1; groupNum<=numCaptureGroups; groupNum++) {
if (i==destCapacity-1) {
break;
}
i++;
dest[i] = group(groupNum, status);
}
if (nextOutputStringStart == inputLen) {
break;
}
}
else
{
dest[i].setTo(input, nextOutputStringStart, inputLen-nextOutputStringStart);
break;
}
}
return i+1;
}
int32_t RegexMatcher::start(UErrorCode &status) const {
return start(0, status);
}
int32_t RegexMatcher::start(int group, UErrorCode &status) const {
if (U_FAILURE(status)) {
return -1;
}
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return -1;
}
if (fMatch == FALSE) {
status = U_REGEX_INVALID_STATE;
return -1;
}
if (group < 0 || group > fPattern->fGroupMap->size()) {
status = U_INDEX_OUTOFBOUNDS_ERROR;
return -1;
}
int32_t s;
if (group == 0) {
s = fMatchStart;
} else {
int32_t groupOffset = fPattern->fGroupMap->elementAti(group-1);
U_ASSERT(groupOffset < fPattern->fFrameSize);
U_ASSERT(groupOffset >= 0);
s = fFrame->fExtra[groupOffset];
}
return s;
}
REStackFrame *RegexMatcher::resetStack() {
fStack->removeAllElements();
int32_t *iFrame = fStack->reserveBlock(fPattern->fFrameSize, fDeferredStatus);
int i;
for (i=0; i<fPattern->fFrameSize; i++) {
iFrame[i] = -1;
}
return (REStackFrame *)iFrame;
}
UBool RegexMatcher::isWordBoundary(int32_t pos) {
UBool isBoundary = FALSE;
UBool cIsWord = FALSE;
if (pos < fInput->length()) {
UChar32 c = fInput->char32At(pos);
int8_t ctype = u_charType(c);
if (ctype==U_NON_SPACING_MARK || ctype==U_ENCLOSING_MARK) {
return FALSE;
}
cIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(c);
}
UBool prevCIsWord = FALSE;
int32_t prevPos = pos;
for (;;) {
if (prevPos == 0) {
break;
}
prevPos = fInput->moveIndex32(prevPos, -1);
UChar32 prevChar = fInput->char32At(prevPos);
int8_t prevCType = u_charType(prevChar);
if (!(prevCType==U_NON_SPACING_MARK || prevCType==U_ENCLOSING_MARK)) {
prevCIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(prevChar);
break;
}
}
isBoundary = cIsWord ^ prevCIsWord;
return isBoundary;
}
UBool RegexMatcher::isUWordBoundary(int32_t pos) {
UBool returnVal = FALSE;
#if UCONFIG_NO_BREAK_ITERATION==0
UErrorCode status = U_ZERO_ERROR;
if (fWordBreakItr == NULL) {
fWordBreakItr =
(RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status);
if (U_FAILURE(status)) {
return FALSE;
}
fWordBreakItr->setText(*fInput);
}
returnVal = fWordBreakItr->isBoundary(pos);
#endif
return returnVal;
}
inline REStackFrame *RegexMatcher::StateSave(REStackFrame *fp, int32_t savePatIdx, int32_t frameSize, UErrorCode &status) {
int32_t *newFP = fStack->reserveBlock(frameSize, status);
fp = (REStackFrame *)(newFP - frameSize);
int32_t *source = (int32_t *)fp;
int32_t *dest = newFP;
for (;;) {
*dest++ = *source++;
if (source == newFP) {
break;
}
}
fp->fPatIdx = savePatIdx;
return (REStackFrame *)newFP;
}
void RegexMatcher::MatchAt(int32_t startIdx, UErrorCode &status) {
UBool isMatch = FALSE;
int32_t op; int32_t opType; int32_t opValue;
#ifdef REGEX_RUN_DEBUG
if (fTraceDebug)
{
printf("MatchAt(startIdx=%d)\n", startIdx);
printf("Original Pattern: ");
int i;
for (i=0; i<fPattern->fPattern.length(); i++) {
printf("%c", fPattern->fPattern.charAt(i));
}
printf("\n");
printf("Input String: ");
for (i=0; i<fInput->length(); i++) {
UChar c = fInput->charAt(i);
if (c<32 || c>256) {
c = '.';
}
printf("%c", c);
}
printf("\n");
printf("\n");
}
#endif
if (U_FAILURE(status)) {
return;
}
int32_t *pat = fPattern->fCompiledPat->getBuffer();
const UChar *litText = fPattern->fLiteralText.getBuffer();
UVector *sets = fPattern->fSets;
int32_t inputLen = fInput->length();
const UChar *inputBuf = fInput->getBuffer();
REStackFrame *fp = resetStack();
int32_t frameSize = fPattern->fFrameSize;
fp->fPatIdx = 0;
fp->fInputIdx = startIdx;
int32_t i;
for (i = 0; i<fPattern->fDataSize; i++) {
fData[i] = 0;
}
for (;;) {
#if 0
if (_heapchk() != _HEAPOK) {
fprintf(stderr, "Heap Trouble\n");
}
#endif
op = pat[fp->fPatIdx];
opType = URX_TYPE(op);
opValue = URX_VAL(op);
#ifdef REGEX_RUN_DEBUG
if (fTraceDebug) {
printf("inputIdx=%d inputChar=%c sp=%3d ", fp->fInputIdx,
fInput->char32At(fp->fInputIdx), (int32_t *)fp-fStack->getBuffer());
fPattern->dumpOp(fp->fPatIdx);
}
#endif
fp->fPatIdx++;
switch (opType) {
case URX_NOP:
break;
case URX_BACKTRACK:
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
case URX_ONECHAR:
if (fp->fInputIdx < inputLen) {
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (c == opValue) {
break;
}
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
case URX_STRING:
{
int32_t stringStartIdx = opValue;
int32_t stringLen;
op = pat[fp->fPatIdx]; fp->fPatIdx++;
opType = URX_TYPE(op);
stringLen = URX_VAL(op);
U_ASSERT(opType == URX_STRING_LEN);
U_ASSERT(stringLen >= 2);
if (fp->fInputIdx + stringLen > inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
const UChar * pInp = inputBuf + fp->fInputIdx;
const UChar * pPat = litText+stringStartIdx;
const UChar * pEnd = pInp + stringLen;
for(;;) {
if (*pInp == *pPat) {
pInp++;
pPat++;
if (pInp == pEnd) {
fp->fInputIdx += stringLen;
break;
}
} else {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
}
break;
}
break;
case URX_STATE_SAVE:
fp = StateSave(fp, opValue, frameSize, status);
break;
case URX_END:
isMatch = TRUE;
goto breakFromLoop;
case URX_START_CAPTURE:
U_ASSERT(opValue >= 0 && opValue < frameSize-3);
fp->fExtra[opValue+2] = fp->fInputIdx;
break;
case URX_END_CAPTURE:
U_ASSERT(opValue >= 0 && opValue < frameSize-3);
U_ASSERT(fp->fExtra[opValue+2] >= 0); fp->fExtra[opValue] = fp->fExtra[opValue+2]; fp->fExtra[opValue+1] = fp->fInputIdx; U_ASSERT(fp->fExtra[opValue] <= fp->fExtra[opValue+1]);
break;
case URX_DOLLAR: if (fp->fInputIdx < inputLen-2) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
if (fp->fInputIdx >= inputLen) {
break;
}
if (fp->fInputIdx == inputLen-1) {
UChar32 c = fInput->char32At(fp->fInputIdx);
if (c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029) {
if ( !(c==0x0a && fp->fInputIdx>0 && inputBuf[fp->fInputIdx-1]==0x0d)) {
break;
}
}
}
if (fp->fInputIdx == inputLen-2) {
if (fInput->char32At(fp->fInputIdx) == 0x0d && fInput->char32At(fp->fInputIdx+1) == 0x0a) {
break; }
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
case URX_DOLLAR_M: {
if (fp->fInputIdx >= inputLen) {
break;
}
UChar32 c = inputBuf[fp->fInputIdx];
if (c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029) {
if ( !(c==0x0a && fp->fInputIdx>0 && inputBuf[fp->fInputIdx-1]==0x0d)) {
break; }
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_CARET: if (fp->fInputIdx != 0) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_CARET_M: {
if (fp->fInputIdx == 0) {
break;
}
UChar c = inputBuf[fp->fInputIdx - 1];
if ((fp->fInputIdx < inputLen) &&
(c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029)) {
break;
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_BACKSLASH_B: {
UBool success = isWordBoundary(fp->fInputIdx);
success ^= (opValue != 0); if (!success) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
}
break;
case URX_BACKSLASH_BU: {
UBool success = isUWordBoundary(fp->fInputIdx);
success ^= (opValue != 0); if (!success) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
}
break;
case URX_BACKSLASH_D: {
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UChar32 c = fInput->char32At(fp->fInputIdx);
int8_t ctype = u_charType(c);
UBool success = (ctype == U_DECIMAL_DIGIT_NUMBER);
success ^= (opValue != 0); if (success) {
fp->fInputIdx = fInput->moveIndex32(fp->fInputIdx, 1);
} else {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
}
break;
case URX_BACKSLASH_G: if (!((fMatch && fp->fInputIdx==fMatchEnd) || fMatch==FALSE && fp->fInputIdx==0)) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_BACKSLASH_X:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
UnicodeSet **sets = fPattern->fStaticSets;
if (sets[URX_GC_NORMAL]->contains(c)) goto GC_Extend;
if (sets[URX_GC_CONTROL]->contains(c)) goto GC_Control;
if (sets[URX_GC_L]->contains(c)) goto GC_L;
if (sets[URX_GC_LV]->contains(c)) goto GC_V;
if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
if (sets[URX_GC_V]->contains(c)) goto GC_V;
if (sets[URX_GC_T]->contains(c)) goto GC_T;
goto GC_Extend;
GC_L:
if (fp->fInputIdx >= inputLen) goto GC_Done;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (sets[URX_GC_L]->contains(c)) goto GC_L;
if (sets[URX_GC_LV]->contains(c)) goto GC_V;
if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
if (sets[URX_GC_V]->contains(c)) goto GC_V;
U16_PREV(inputBuf, 0, fp->fInputIdx, c);
goto GC_Extend;
GC_V:
if (fp->fInputIdx >= inputLen) goto GC_Done;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (sets[URX_GC_V]->contains(c)) goto GC_V;
if (sets[URX_GC_T]->contains(c)) goto GC_T;
U16_PREV(inputBuf, 0, fp->fInputIdx, c);
goto GC_Extend;
GC_T:
if (fp->fInputIdx >= inputLen) goto GC_Done;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (sets[URX_GC_T]->contains(c)) goto GC_T;
U16_PREV(inputBuf, 0, fp->fInputIdx, c);
goto GC_Extend;
GC_Extend:
for (;;) {
if (fp->fInputIdx >= inputLen) {
break;
}
U16_GET(inputBuf, 0, fp->fInputIdx, inputLen, c);
if (sets[URX_GC_EXTEND]->contains(c) == FALSE) {
break;
}
U16_FWD_1(inputBuf, fp->fInputIdx, inputLen);
}
goto GC_Done;
GC_Control:
if (c == 0x0d && fp->fInputIdx < inputLen && inputBuf[fp->fInputIdx] == 0x0a) {
fp->fInputIdx++;
}
GC_Done:
break;
}
case URX_BACKSLASH_Z: if (fp->fInputIdx < inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_STATIC_SETREF:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UBool success = ((opValue & URX_NEG_SET) == URX_NEG_SET);
opValue &= ~URX_NEG_SET;
U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (c < 256) {
Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
if (s8->contains(c)) {
success = !success;
}
} else {
const UnicodeSet *s = fPattern->fStaticSets[opValue];
if (s->contains(c)) {
success = !success;
}
}
if (!success) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
}
break;
case URX_STAT_SETREF_N:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (c < 256) {
Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
if (s8->contains(c) == FALSE) {
break;
}
} else {
const UnicodeSet *s = fPattern->fStaticSets[opValue];
if (s->contains(c) == FALSE) {
break;
}
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_SETREF:
if (fp->fInputIdx < inputLen) {
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
U_ASSERT(opValue > 0 && opValue < sets->size());
if (c<256) {
Regex8BitSet *s8 = &fPattern->fSets8[opValue];
if (s8->contains(c)) {
break;
}
} else {
UnicodeSet *s = (UnicodeSet *)sets->elementAt(opValue);
if (s->contains(c)) {
break;
}
}
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
case URX_DOTANY:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (((c & 0x7f) <= 0x29) && (c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029)) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
}
break;
case URX_DOTANY_ALL:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (c==0x0d) {
UChar nextc = inputBuf[fp->fInputIdx];
if (nextc == 0x0a) {
fp->fInputIdx++;
}
}
}
break;
case URX_DOTANY_PL:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (((c & 0x7f) <= 0x29) && (c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029)) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
while (fp->fInputIdx < inputLen) {
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (((c & 0x7f) <= 0x29) && (c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029)) {
U16_BACK_1(inputBuf, 0, fp->fInputIdx)
break;
}
}
}
break;
case URX_DOTANY_ALL_PL:
{
if (fp->fInputIdx >= inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
} else {
fp->fInputIdx = inputLen;
}
}
break;
case URX_JMP:
fp->fPatIdx = opValue;
break;
case URX_FAIL:
isMatch = FALSE;
goto breakFromLoop;
case URX_JMP_SAV:
U_ASSERT(opValue < fPattern->fCompiledPat->size());
fp = StateSave(fp, fp->fPatIdx, frameSize, status); fp->fPatIdx = opValue; break;
case URX_JMP_SAV_X:
{
U_ASSERT(opValue > 0 && opValue < fPattern->fCompiledPat->size());
int32_t stoOp = pat[opValue-1];
U_ASSERT(URX_TYPE(stoOp) == URX_STO_INP_LOC);
int32_t frameLoc = URX_VAL(stoOp);
U_ASSERT(frameLoc >= 0 && frameLoc < frameSize);
int32_t prevInputIdx = fp->fExtra[frameLoc];
U_ASSERT(prevInputIdx <= fp->fInputIdx);
if (prevInputIdx < fp->fInputIdx) {
fp = StateSave(fp, fp->fPatIdx, frameSize, status); fp->fPatIdx = opValue;
fp->fExtra[frameLoc] = fp->fInputIdx;
}
}
break;
case URX_CTR_INIT:
{
U_ASSERT(opValue >= 0 && opValue < frameSize-2);
fp->fExtra[opValue] = 0;
int32_t instrOperandLoc = fp->fPatIdx;
fp->fPatIdx += 3;
int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
int32_t minCount = pat[instrOperandLoc+1];
int32_t maxCount = pat[instrOperandLoc+2];
U_ASSERT(minCount>=0);
U_ASSERT(maxCount>=minCount || maxCount==-1);
U_ASSERT(loopLoc>fp->fPatIdx);
if (minCount == 0) {
fp = StateSave(fp, loopLoc+1, frameSize, status);
}
if (maxCount == 0) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
}
break;
case URX_CTR_LOOP:
{
U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
int32_t initOp = pat[opValue];
U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT);
int32_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
int32_t minCount = pat[opValue+2];
int32_t maxCount = pat[opValue+3];
(*pCounter)++;
U_ASSERT(*pCounter > 0);
if ((uint32_t)*pCounter >= (uint32_t)maxCount) {
U_ASSERT(*pCounter == maxCount || maxCount == -1);
break;
}
if (*pCounter >= minCount) {
fp = StateSave(fp, fp->fPatIdx, frameSize, status);
}
fp->fPatIdx = opValue + 4; }
break;
case URX_CTR_INIT_NG:
{
U_ASSERT(opValue >= 0 && opValue < frameSize-2);
fp->fExtra[opValue] = 0;
int32_t instrOperandLoc = fp->fPatIdx;
fp->fPatIdx += 3;
int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
int32_t minCount = pat[instrOperandLoc+1];
int32_t maxCount = pat[instrOperandLoc+2];
U_ASSERT(minCount>=0);
U_ASSERT(maxCount>=minCount || maxCount==-1);
U_ASSERT(loopLoc>fp->fPatIdx);
if (minCount == 0) {
if (maxCount != 0) {
fp = StateSave(fp, fp->fPatIdx, frameSize, status);
}
fp->fPatIdx = loopLoc+1; }
}
break;
case URX_CTR_LOOP_NG:
{
U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
int32_t initOp = pat[opValue];
U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT_NG);
int32_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
int32_t minCount = pat[opValue+2];
int32_t maxCount = pat[opValue+3];
(*pCounter)++;
U_ASSERT(*pCounter > 0);
if ((uint32_t)*pCounter >= (uint32_t)maxCount) {
U_ASSERT(*pCounter == maxCount || maxCount == -1);
break;
}
if (*pCounter < minCount) {
fp->fPatIdx = opValue + 4; } else {
fp = StateSave(fp, opValue + 4, frameSize, status);
}
}
break;
case URX_STO_SP:
U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
fData[opValue] = fStack->size();
break;
case URX_LD_SP:
{
U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
int32_t newStackSize = fData[opValue];
U_ASSERT(newStackSize <= fStack->size());
int32_t *newFP = fStack->getBuffer() + newStackSize - frameSize;
if (newFP == (int32_t *)fp) {
break;
}
int32_t i;
for (i=0; i<frameSize; i++) {
newFP[i] = ((int32_t *)fp)[i];
}
fp = (REStackFrame *)newFP;
fStack->setSize(newStackSize);
}
break;
case URX_BACKREF:
case URX_BACKREF_I:
{
U_ASSERT(opValue < frameSize);
int32_t groupStartIdx = fp->fExtra[opValue];
int32_t groupEndIdx = fp->fExtra[opValue+1];
U_ASSERT(groupStartIdx <= groupEndIdx);
int32_t len = groupEndIdx-groupStartIdx;
if (groupStartIdx < 0) {
fp = (REStackFrame *)fStack->popFrame(frameSize); }
if (len == 0) {
break;
}
UBool haveMatch = FALSE;
if (fp->fInputIdx + len <= inputLen) {
if (opType == URX_BACKREF) {
if (u_strncmp(inputBuf+groupStartIdx, inputBuf+fp->fInputIdx, len) == 0) {
haveMatch = TRUE;
}
} else {
if (u_strncasecmp(inputBuf+groupStartIdx, inputBuf+fp->fInputIdx,
len, U_FOLD_CASE_DEFAULT) == 0) {
haveMatch = TRUE;
}
}
}
if (haveMatch) {
fp->fInputIdx += len; } else {
fp = (REStackFrame *)fStack->popFrame(frameSize); }
}
break;
case URX_STO_INP_LOC:
{
U_ASSERT(opValue >= 0 && opValue < frameSize);
fp->fExtra[opValue] = fp->fInputIdx;
}
break;
case URX_JMPX:
{
int32_t instrOperandLoc = fp->fPatIdx;
fp->fPatIdx += 1;
int32_t dataLoc = URX_VAL(pat[instrOperandLoc]);
U_ASSERT(dataLoc >= 0 && dataLoc < frameSize);
int32_t savedInputIdx = fp->fExtra[dataLoc];
U_ASSERT(savedInputIdx <= fp->fInputIdx);
if (savedInputIdx < fp->fInputIdx) {
fp->fPatIdx = opValue; } else {
fp = (REStackFrame *)fStack->popFrame(frameSize); }
}
break;
case URX_LA_START:
{
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
fData[opValue] = fStack->size();
fData[opValue+1] = fp->fInputIdx;
}
break;
case URX_LA_END:
{
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
int32_t stackSize = fStack->size();
int32_t newStackSize = fData[opValue];
U_ASSERT(stackSize >= newStackSize);
if (stackSize > newStackSize) {
int32_t *newFP = fStack->getBuffer() + newStackSize - frameSize;
int32_t i;
for (i=0; i<frameSize; i++) {
newFP[i] = ((int32_t *)fp)[i];
}
fp = (REStackFrame *)newFP;
fStack->setSize(newStackSize);
}
fp->fInputIdx = fData[opValue+1];
}
break;
case URX_ONECHAR_I:
if (fp->fInputIdx < inputLen) {
UChar32 c;
U16_NEXT(inputBuf, fp->fInputIdx, inputLen, c);
if (u_foldCase(c, U_FOLD_CASE_DEFAULT) == opValue) {
break;
}
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
case URX_STRING_I:
{
int32_t stringStartIdx, stringLen;
stringStartIdx = opValue;
op = pat[fp->fPatIdx];
fp->fPatIdx++;
opType = URX_TYPE(op);
opValue = URX_VAL(op);
U_ASSERT(opType == URX_STRING_LEN);
stringLen = opValue;
int32_t stringEndIndex = fp->fInputIdx + stringLen;
if (stringEndIndex <= inputLen) {
if (u_strncasecmp(inputBuf+fp->fInputIdx, litText+stringStartIdx,
stringLen, U_FOLD_CASE_DEFAULT) == 0) {
fp->fInputIdx = stringEndIndex;
break;
}
}
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_LB_START:
{
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
fData[opValue] = fStack->size();
fData[opValue+1] = fp->fInputIdx;
fData[opValue+2] = -1;
fData[opValue+3] = inputLen;
inputLen = fp->fInputIdx;
}
break;
case URX_LB_CONT:
{
int32_t minML = pat[fp->fPatIdx++];
int32_t maxML = pat[fp->fPatIdx++];
U_ASSERT(minML <= maxML);
U_ASSERT(minML >= 0);
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
int32_t *lbStartIdx = &fData[opValue+2];
if (*lbStartIdx < 0) {
*lbStartIdx = fp->fInputIdx - minML;
} else {
if (*lbStartIdx == 0) {
(*lbStartIdx)--; } else {
U16_BACK_1(inputBuf, 0, *lbStartIdx);
}
}
if (*lbStartIdx < 0 || *lbStartIdx < fp->fInputIdx - maxML) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
int32_t restoreInputLen = fData[opValue+3];
U_ASSERT(restoreInputLen >= inputLen);
U_ASSERT(restoreInputLen <= fInput->length());
inputLen = restoreInputLen;
break;
}
fp = StateSave(fp, fp->fPatIdx-3, frameSize, status);
fp->fInputIdx = *lbStartIdx;
}
break;
case URX_LB_END:
{
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
if (fp->fInputIdx != inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
int32_t originalInputLen = fData[opValue+3];
U_ASSERT(originalInputLen >= inputLen);
U_ASSERT(originalInputLen <= fInput->length());
inputLen = originalInputLen;
}
break;
case URX_LBN_CONT:
{
int32_t minML = pat[fp->fPatIdx++];
int32_t maxML = pat[fp->fPatIdx++];
int32_t continueLoc = pat[fp->fPatIdx++];
continueLoc = URX_VAL(continueLoc);
U_ASSERT(minML <= maxML);
U_ASSERT(minML >= 0);
U_ASSERT(continueLoc > fp->fPatIdx);
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
int32_t *lbStartIdx = &fData[opValue+2];
if (*lbStartIdx < 0) {
*lbStartIdx = fp->fInputIdx - minML;
} else {
if (*lbStartIdx == 0) {
(*lbStartIdx)--; } else {
U16_BACK_1(inputBuf, 0, *lbStartIdx);
}
}
if (*lbStartIdx < 0 || *lbStartIdx < fp->fInputIdx - maxML) {
int32_t restoreInputLen = fData[opValue+3];
U_ASSERT(restoreInputLen >= inputLen);
U_ASSERT(restoreInputLen <= fInput->length());
inputLen = restoreInputLen;
fp->fPatIdx = continueLoc;
break;
}
fp = StateSave(fp, fp->fPatIdx-4, frameSize, status);
fp->fInputIdx = *lbStartIdx;
}
break;
case URX_LBN_END:
{
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
if (fp->fInputIdx != inputLen) {
fp = (REStackFrame *)fStack->popFrame(frameSize);
break;
}
int32_t originalInputLen = fData[opValue+3];
U_ASSERT(originalInputLen >= inputLen);
U_ASSERT(originalInputLen <= fInput->length());
inputLen = originalInputLen;
U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
int32_t newStackSize = fData[opValue];
U_ASSERT(fStack->size() > newStackSize);
fStack->setSize(newStackSize);
fp = (REStackFrame *)fStack->popFrame(frameSize);
}
break;
case URX_LOOP_SR_I:
{
U_ASSERT(opValue > 0 && opValue < sets->size());
Regex8BitSet *s8 = &fPattern->fSets8[opValue];
UnicodeSet *s = (UnicodeSet *)sets->elementAt(opValue);
int32_t ix = fp->fInputIdx;
for (;;) {
if (ix >= inputLen) {
break;
}
UChar32 c;
U16_NEXT(inputBuf, ix, inputLen, c);
if (c<256) {
if (s8->contains(c) == FALSE) {
U16_BACK_1(inputBuf, 0, ix);
break;
}
} else {
if (s->contains(c) == FALSE) {
U16_BACK_1(inputBuf, 0, ix);
break;
}
}
}
if (ix == fp->fInputIdx) {
fp->fPatIdx++; break;
}
int32_t loopcOp = pat[fp->fPatIdx];
U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
int32_t stackLoc = URX_VAL(loopcOp);
U_ASSERT(stackLoc >= 0 && stackLoc < frameSize);
fp->fExtra[stackLoc] = fp->fInputIdx;
fp->fInputIdx = ix;
fp = StateSave(fp, fp->fPatIdx, frameSize, status);
fp->fPatIdx++;
}
break;
case URX_LOOP_DOT_I:
{
int32_t ix;
if (opValue == 1) {
ix = inputLen;
} else {
ix = fp->fInputIdx;
for (;;) {
if (ix >= inputLen) {
ix = inputLen;
break;
}
UChar32 c;
U16_NEXT(inputBuf, ix, inputLen, c); if (((c & 0x7f) <= 0x29) &&
(c == 0x0a || c==0x0d || c==0x0c || c==0x85 ||c==0x2028 || c==0x2029)) {
U16_BACK_1(inputBuf, 0, ix);
break;
}
}
}
if (ix == fp->fInputIdx) {
fp->fPatIdx++; break;
}
int32_t loopcOp = pat[fp->fPatIdx];
U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
int32_t stackLoc = URX_VAL(loopcOp);
U_ASSERT(stackLoc >= 0 && stackLoc < frameSize);
fp->fExtra[stackLoc] = fp->fInputIdx;
fp->fInputIdx = ix;
fp = StateSave(fp, fp->fPatIdx, frameSize, status);
fp->fPatIdx++;
}
break;
case URX_LOOP_C:
{
U_ASSERT(opValue>=0 && opValue<frameSize);
int32_t terminalIdx = fp->fExtra[opValue];
U_ASSERT(terminalIdx <= fp->fInputIdx);
if (terminalIdx == fp->fInputIdx) {
break;
}
U_ASSERT(fp->fInputIdx > 0);
U16_BACK_1(inputBuf, 0, fp->fInputIdx);
if (inputBuf[fp->fInputIdx] == 0x0a &&
fp->fInputIdx > terminalIdx &&
inputBuf[fp->fInputIdx-1] == 0x0d) {
int32_t prevOp = pat[fp->fPatIdx-2];
if (URX_TYPE(prevOp) == URX_LOOP_DOT_I) {
fp->fInputIdx--;
}
}
fp = StateSave(fp, fp->fPatIdx-1, frameSize, status);
}
break;
default:
U_ASSERT(FALSE);
}
if (U_FAILURE(status)) {
break;
}
}
breakFromLoop:
fMatch = isMatch;
if (isMatch) {
fLastMatchEnd = fMatchEnd;
fMatchStart = startIdx;
fMatchEnd = fp->fInputIdx;
if (fTraceDebug) {
REGEX_RUN_DEBUG_PRINTF(("Match. start=%d end=%d\n\n", fMatchStart, fMatchEnd));
}
}
else
{
if (fTraceDebug) {
REGEX_RUN_DEBUG_PRINTF(("No match\n\n"));
}
}
fFrame = fp;
return;
}
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexMatcher)
U_NAMESPACE_END
#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS