michael@0: // michael@0: // file: repattrn.cpp michael@0: // michael@0: /* michael@0: *************************************************************************** michael@0: * Copyright (C) 2002-2012 International Business Machines Corporation * michael@0: * and others. All rights reserved. * michael@0: *************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_REGULAR_EXPRESSIONS michael@0: michael@0: #include "unicode/regex.h" michael@0: #include "unicode/uclean.h" michael@0: #include "uassert.h" michael@0: #include "uvector.h" michael@0: #include "uvectr32.h" michael@0: #include "uvectr64.h" michael@0: #include "regexcmp.h" michael@0: #include "regeximp.h" michael@0: #include "regexst.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // RegexPattern Default Constructor michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: RegexPattern::RegexPattern() { michael@0: // Init all of this instances data. michael@0: init(); michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // Copy Constructor Note: This is a rather inefficient implementation, michael@0: // but it probably doesn't matter. michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: RegexPattern::RegexPattern(const RegexPattern &other) : UObject(other) { michael@0: init(); michael@0: *this = other; michael@0: } michael@0: michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // Assignment Operator michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: RegexPattern &RegexPattern::operator = (const RegexPattern &other) { michael@0: if (this == &other) { michael@0: // Source and destination are the same. Don't do anything. michael@0: return *this; michael@0: } michael@0: michael@0: // Clean out any previous contents of object being assigned to. michael@0: zap(); michael@0: michael@0: // Give target object a default initialization michael@0: init(); michael@0: michael@0: // Copy simple fields michael@0: if ( other.fPatternString == NULL ) { michael@0: fPatternString = NULL; michael@0: fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus); michael@0: } else { michael@0: fPatternString = new UnicodeString(*(other.fPatternString)); michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: fPattern = utext_openConstUnicodeString(NULL, fPatternString, &status); michael@0: if (U_FAILURE(status)) { michael@0: fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; michael@0: return *this; michael@0: } michael@0: } michael@0: fFlags = other.fFlags; michael@0: fLiteralText = other.fLiteralText; michael@0: fDeferredStatus = other.fDeferredStatus; michael@0: fMinMatchLen = other.fMinMatchLen; michael@0: fFrameSize = other.fFrameSize; michael@0: fDataSize = other.fDataSize; michael@0: fMaxCaptureDigits = other.fMaxCaptureDigits; michael@0: fStaticSets = other.fStaticSets; michael@0: fStaticSets8 = other.fStaticSets8; michael@0: michael@0: fStartType = other.fStartType; michael@0: fInitialStringIdx = other.fInitialStringIdx; michael@0: fInitialStringLen = other.fInitialStringLen; michael@0: *fInitialChars = *other.fInitialChars; michael@0: fInitialChar = other.fInitialChar; michael@0: *fInitialChars8 = *other.fInitialChars8; michael@0: fNeedsAltInput = other.fNeedsAltInput; michael@0: michael@0: // Copy the pattern. It's just values, nothing deep to copy. michael@0: fCompiledPat->assign(*other.fCompiledPat, fDeferredStatus); michael@0: fGroupMap->assign(*other.fGroupMap, fDeferredStatus); michael@0: michael@0: // Copy the Unicode Sets. michael@0: // Could be made more efficient if the sets were reference counted and shared, michael@0: // but I doubt that pattern copying will be particularly common. michael@0: // Note: init() already added an empty element zero to fSets michael@0: int32_t i; michael@0: int32_t numSets = other.fSets->size(); michael@0: fSets8 = new Regex8BitSet[numSets]; michael@0: if (fSets8 == NULL) { michael@0: fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; michael@0: return *this; michael@0: } michael@0: for (i=1; ielementAt(i); michael@0: UnicodeSet *newSet = new UnicodeSet(*sourceSet); michael@0: if (newSet == NULL) { michael@0: fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; michael@0: break; michael@0: } michael@0: fSets->addElement(newSet, fDeferredStatus); michael@0: fSets8[i] = other.fSets8[i]; michael@0: } michael@0: michael@0: return *this; michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // init Shared initialization for use by constructors. michael@0: // Bring an uninitialized RegexPattern up to a default state. michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: void RegexPattern::init() { michael@0: fFlags = 0; michael@0: fCompiledPat = 0; michael@0: fLiteralText.remove(); michael@0: fSets = NULL; michael@0: fSets8 = NULL; michael@0: fDeferredStatus = U_ZERO_ERROR; michael@0: fMinMatchLen = 0; michael@0: fFrameSize = 0; michael@0: fDataSize = 0; michael@0: fGroupMap = NULL; michael@0: fMaxCaptureDigits = 1; michael@0: fStaticSets = NULL; michael@0: fStaticSets8 = NULL; michael@0: fStartType = START_NO_INFO; michael@0: fInitialStringIdx = 0; michael@0: fInitialStringLen = 0; michael@0: fInitialChars = NULL; michael@0: fInitialChar = 0; michael@0: fInitialChars8 = NULL; michael@0: fNeedsAltInput = FALSE; michael@0: michael@0: fPattern = NULL; // will be set later michael@0: fPatternString = NULL; // may be set later michael@0: fCompiledPat = new UVector64(fDeferredStatus); michael@0: fGroupMap = new UVector32(fDeferredStatus); michael@0: fSets = new UVector(fDeferredStatus); michael@0: fInitialChars = new UnicodeSet; michael@0: fInitialChars8 = new Regex8BitSet; michael@0: if (U_FAILURE(fDeferredStatus)) { michael@0: return; michael@0: } michael@0: if (fCompiledPat == NULL || fGroupMap == NULL || fSets == NULL || michael@0: fInitialChars == NULL || fInitialChars8 == NULL) { michael@0: fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; michael@0: return; michael@0: } michael@0: michael@0: // Slot zero of the vector of sets is reserved. Fill it here. michael@0: fSets->addElement((int32_t)0, fDeferredStatus); michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // zap Delete everything owned by this RegexPattern. michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: void RegexPattern::zap() { michael@0: delete fCompiledPat; michael@0: fCompiledPat = NULL; michael@0: int i; michael@0: for (i=1; isize(); i++) { michael@0: UnicodeSet *s; michael@0: s = (UnicodeSet *)fSets->elementAt(i); michael@0: if (s != NULL) { michael@0: delete s; michael@0: } michael@0: } michael@0: delete fSets; michael@0: fSets = NULL; michael@0: delete[] fSets8; michael@0: fSets8 = NULL; michael@0: delete fGroupMap; michael@0: fGroupMap = NULL; michael@0: delete fInitialChars; michael@0: fInitialChars = NULL; michael@0: delete fInitialChars8; michael@0: fInitialChars8 = NULL; michael@0: if (fPattern != NULL) { michael@0: utext_close(fPattern); michael@0: fPattern = NULL; michael@0: } michael@0: if (fPatternString != NULL) { michael@0: delete fPatternString; michael@0: fPatternString = NULL; michael@0: } michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // Destructor michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: RegexPattern::~RegexPattern() { michael@0: zap(); michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // Clone michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: RegexPattern *RegexPattern::clone() const { michael@0: RegexPattern *copy = new RegexPattern(*this); michael@0: return copy; michael@0: } michael@0: michael@0: michael@0: //-------------------------------------------------------------------------- michael@0: // michael@0: // operator == (comparison) Consider to patterns to be == if the michael@0: // pattern strings and the flags are the same. michael@0: // Note that pattern strings with the same michael@0: // characters can still be considered different. michael@0: // michael@0: //-------------------------------------------------------------------------- michael@0: UBool RegexPattern::operator ==(const RegexPattern &other) const { michael@0: if (this->fFlags == other.fFlags && this->fDeferredStatus == other.fDeferredStatus) { michael@0: if (this->fPatternString != NULL && other.fPatternString != NULL) { michael@0: return *(this->fPatternString) == *(other.fPatternString); michael@0: } else if (this->fPattern == NULL) { michael@0: if (other.fPattern == NULL) { michael@0: return TRUE; michael@0: } michael@0: } else if (other.fPattern != NULL) { michael@0: UTEXT_SETNATIVEINDEX(this->fPattern, 0); michael@0: UTEXT_SETNATIVEINDEX(other.fPattern, 0); michael@0: return utext_equals(this->fPattern, other.fPattern); michael@0: } michael@0: } michael@0: return FALSE; michael@0: } michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // compile michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(const UnicodeString ®ex, michael@0: uint32_t flags, michael@0: UParseError &pe, michael@0: UErrorCode &status) michael@0: { michael@0: if (U_FAILURE(status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: const uint32_t allFlags = UREGEX_CANON_EQ | UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | michael@0: UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD | michael@0: UREGEX_ERROR_ON_UNKNOWN_ESCAPES | UREGEX_UNIX_LINES | UREGEX_LITERAL; michael@0: michael@0: if ((flags & ~allFlags) != 0) { michael@0: status = U_REGEX_INVALID_FLAG; michael@0: return NULL; michael@0: } michael@0: michael@0: if ((flags & UREGEX_CANON_EQ) != 0) { michael@0: status = U_REGEX_UNIMPLEMENTED; michael@0: return NULL; michael@0: } michael@0: michael@0: RegexPattern *This = new RegexPattern; michael@0: if (This == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: return NULL; michael@0: } michael@0: if (U_FAILURE(This->fDeferredStatus)) { michael@0: status = This->fDeferredStatus; michael@0: delete This; michael@0: return NULL; michael@0: } michael@0: This->fFlags = flags; michael@0: michael@0: RegexCompile compiler(This, status); michael@0: compiler.compile(regex, pe, status); michael@0: michael@0: if (U_FAILURE(status)) { michael@0: delete This; michael@0: This = NULL; michael@0: } michael@0: michael@0: return This; michael@0: } michael@0: michael@0: michael@0: // michael@0: // compile, UText mode michael@0: // michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(UText *regex, michael@0: uint32_t flags, michael@0: UParseError &pe, michael@0: UErrorCode &status) michael@0: { michael@0: if (U_FAILURE(status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: const uint32_t allFlags = UREGEX_CANON_EQ | UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS | michael@0: UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD | michael@0: UREGEX_ERROR_ON_UNKNOWN_ESCAPES | UREGEX_UNIX_LINES | UREGEX_LITERAL; michael@0: michael@0: if ((flags & ~allFlags) != 0) { michael@0: status = U_REGEX_INVALID_FLAG; michael@0: return NULL; michael@0: } michael@0: michael@0: if ((flags & UREGEX_CANON_EQ) != 0) { michael@0: status = U_REGEX_UNIMPLEMENTED; michael@0: return NULL; michael@0: } michael@0: michael@0: RegexPattern *This = new RegexPattern; michael@0: if (This == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: return NULL; michael@0: } michael@0: if (U_FAILURE(This->fDeferredStatus)) { michael@0: status = This->fDeferredStatus; michael@0: delete This; michael@0: return NULL; michael@0: } michael@0: This->fFlags = flags; michael@0: michael@0: RegexCompile compiler(This, status); michael@0: compiler.compile(regex, pe, status); michael@0: michael@0: if (U_FAILURE(status)) { michael@0: delete This; michael@0: This = NULL; michael@0: } michael@0: michael@0: return This; michael@0: } michael@0: michael@0: // michael@0: // compile with default flags. michael@0: // michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(const UnicodeString ®ex, michael@0: UParseError &pe, michael@0: UErrorCode &err) michael@0: { michael@0: return compile(regex, 0, pe, err); michael@0: } michael@0: michael@0: michael@0: // michael@0: // compile with default flags, UText mode michael@0: // michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(UText *regex, michael@0: UParseError &pe, michael@0: UErrorCode &err) michael@0: { michael@0: return compile(regex, 0, pe, err); michael@0: } michael@0: michael@0: michael@0: // michael@0: // compile with no UParseErr parameter. michael@0: // michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(const UnicodeString ®ex, michael@0: uint32_t flags, michael@0: UErrorCode &err) michael@0: { michael@0: UParseError pe; michael@0: return compile(regex, flags, pe, err); michael@0: } michael@0: michael@0: michael@0: // michael@0: // compile with no UParseErr parameter, UText mode michael@0: // michael@0: RegexPattern * U_EXPORT2 michael@0: RegexPattern::compile(UText *regex, michael@0: uint32_t flags, michael@0: UErrorCode &err) michael@0: { michael@0: UParseError pe; michael@0: return compile(regex, flags, pe, err); michael@0: } michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // flags michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: uint32_t RegexPattern::flags() const { michael@0: return fFlags; michael@0: } michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // matcher(UnicodeString, err) michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: RegexMatcher *RegexPattern::matcher(const UnicodeString &input, michael@0: UErrorCode &status) const { michael@0: RegexMatcher *retMatcher = matcher(status); michael@0: if (retMatcher != NULL) { michael@0: retMatcher->fDeferredStatus = status; michael@0: retMatcher->reset(input); michael@0: } michael@0: return retMatcher; michael@0: } michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // matcher(status) michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: RegexMatcher *RegexPattern::matcher(UErrorCode &status) const { michael@0: RegexMatcher *retMatcher = NULL; michael@0: michael@0: if (U_FAILURE(status)) { michael@0: return NULL; michael@0: } michael@0: if (U_FAILURE(fDeferredStatus)) { michael@0: status = fDeferredStatus; michael@0: return NULL; michael@0: } michael@0: michael@0: retMatcher = new RegexMatcher(this); michael@0: if (retMatcher == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: return NULL; michael@0: } michael@0: return retMatcher; michael@0: } michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // matches Convenience function to test for a match, starting michael@0: // with a pattern string and a data string. michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: UBool U_EXPORT2 RegexPattern::matches(const UnicodeString ®ex, michael@0: const UnicodeString &input, michael@0: UParseError &pe, michael@0: UErrorCode &status) { michael@0: michael@0: if (U_FAILURE(status)) {return FALSE;} michael@0: michael@0: UBool retVal; michael@0: RegexPattern *pat = NULL; michael@0: RegexMatcher *matcher = NULL; michael@0: michael@0: pat = RegexPattern::compile(regex, 0, pe, status); michael@0: matcher = pat->matcher(input, status); michael@0: retVal = matcher->matches(status); michael@0: michael@0: delete matcher; michael@0: delete pat; michael@0: return retVal; michael@0: } michael@0: michael@0: michael@0: // michael@0: // matches, UText mode michael@0: // michael@0: UBool U_EXPORT2 RegexPattern::matches(UText *regex, michael@0: UText *input, michael@0: UParseError &pe, michael@0: UErrorCode &status) { michael@0: michael@0: if (U_FAILURE(status)) {return FALSE;} michael@0: michael@0: UBool retVal = FALSE; michael@0: RegexPattern *pat = NULL; michael@0: RegexMatcher *matcher = NULL; michael@0: michael@0: pat = RegexPattern::compile(regex, 0, pe, status); michael@0: matcher = pat->matcher(status); michael@0: if (U_SUCCESS(status)) { michael@0: matcher->reset(input); michael@0: retVal = matcher->matches(status); michael@0: } michael@0: michael@0: delete matcher; michael@0: delete pat; michael@0: return retVal; michael@0: } michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // pattern michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: UnicodeString RegexPattern::pattern() const { michael@0: if (fPatternString != NULL) { michael@0: return *fPatternString; michael@0: } else if (fPattern == NULL) { michael@0: return UnicodeString(); michael@0: } else { michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: int64_t nativeLen = utext_nativeLength(fPattern); michael@0: int32_t len16 = utext_extract(fPattern, 0, nativeLen, NULL, 0, &status); // buffer overflow error michael@0: UnicodeString result; michael@0: michael@0: status = U_ZERO_ERROR; michael@0: UChar *resultChars = result.getBuffer(len16); michael@0: utext_extract(fPattern, 0, nativeLen, resultChars, len16, &status); // unterminated warning michael@0: result.releaseBuffer(len16); michael@0: michael@0: return result; michael@0: } michael@0: } michael@0: michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // patternText michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: UText *RegexPattern::patternText(UErrorCode &status) const { michael@0: if (U_FAILURE(status)) {return NULL;} michael@0: status = U_ZERO_ERROR; michael@0: michael@0: if (fPattern != NULL) { michael@0: return fPattern; michael@0: } else { michael@0: RegexStaticSets::initGlobals(&status); michael@0: return RegexStaticSets::gStaticSets->fEmptyText; michael@0: } michael@0: } michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // split michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: int32_t RegexPattern::split(const UnicodeString &input, michael@0: UnicodeString dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status) const michael@0: { michael@0: if (U_FAILURE(status)) { michael@0: return 0; michael@0: }; michael@0: michael@0: RegexMatcher m(this); michael@0: int32_t r = 0; michael@0: // Check m's status to make sure all is ok. michael@0: if (U_SUCCESS(m.fDeferredStatus)) { michael@0: r = m.split(input, dest, destCapacity, status); michael@0: } michael@0: return r; michael@0: } michael@0: michael@0: // michael@0: // split, UText mode michael@0: // michael@0: int32_t RegexPattern::split(UText *input, michael@0: UText *dest[], michael@0: int32_t destCapacity, michael@0: UErrorCode &status) const michael@0: { michael@0: if (U_FAILURE(status)) { michael@0: return 0; michael@0: }; michael@0: michael@0: RegexMatcher m(this); michael@0: int32_t r = 0; michael@0: // Check m's status to make sure all is ok. michael@0: if (U_SUCCESS(m.fDeferredStatus)) { michael@0: r = m.split(input, dest, destCapacity, status); michael@0: } michael@0: return r; michael@0: } michael@0: michael@0: michael@0: michael@0: //--------------------------------------------------------------------- michael@0: // michael@0: // dump Output the compiled form of the pattern. michael@0: // Debugging function only. michael@0: // michael@0: //--------------------------------------------------------------------- michael@0: #if defined(REGEX_DEBUG) michael@0: void RegexPattern::dumpOp(int32_t index) const { michael@0: static const char * const opNames[] = {URX_OPCODE_NAMES}; michael@0: int32_t op = fCompiledPat->elementAti(index); michael@0: int32_t val = URX_VAL(op); michael@0: int32_t type = URX_TYPE(op); michael@0: int32_t pinnedType = type; michael@0: if ((uint32_t)pinnedType >= sizeof(opNames)/sizeof(char *)) { michael@0: pinnedType = 0; michael@0: } michael@0: michael@0: REGEX_DUMP_DEBUG_PRINTF(("%4d %08x %-15s ", index, op, opNames[pinnedType])); michael@0: switch (type) { michael@0: case URX_NOP: michael@0: case URX_DOTANY: michael@0: case URX_DOTANY_ALL: michael@0: case URX_FAIL: michael@0: case URX_CARET: michael@0: case URX_DOLLAR: michael@0: case URX_BACKSLASH_G: michael@0: case URX_BACKSLASH_X: michael@0: case URX_END: michael@0: case URX_DOLLAR_M: michael@0: case URX_CARET_M: michael@0: // Types with no operand field of interest. michael@0: break; michael@0: michael@0: case URX_RESERVED_OP: michael@0: case URX_START_CAPTURE: michael@0: case URX_END_CAPTURE: michael@0: case URX_STATE_SAVE: michael@0: case URX_JMP: michael@0: case URX_JMP_SAV: michael@0: case URX_JMP_SAV_X: michael@0: case URX_BACKSLASH_B: michael@0: case URX_BACKSLASH_BU: michael@0: case URX_BACKSLASH_D: michael@0: case URX_BACKSLASH_Z: michael@0: case URX_STRING_LEN: michael@0: case URX_CTR_INIT: michael@0: case URX_CTR_INIT_NG: michael@0: case URX_CTR_LOOP: michael@0: case URX_CTR_LOOP_NG: michael@0: case URX_RELOC_OPRND: michael@0: case URX_STO_SP: michael@0: case URX_LD_SP: michael@0: case URX_BACKREF: michael@0: case URX_STO_INP_LOC: michael@0: case URX_JMPX: michael@0: case URX_LA_START: michael@0: case URX_LA_END: michael@0: case URX_BACKREF_I: michael@0: case URX_LB_START: michael@0: case URX_LB_CONT: michael@0: case URX_LB_END: michael@0: case URX_LBN_CONT: michael@0: case URX_LBN_END: michael@0: case URX_LOOP_C: michael@0: case URX_LOOP_DOT_I: michael@0: // types with an integer operand field. michael@0: REGEX_DUMP_DEBUG_PRINTF(("%d", val)); michael@0: break; michael@0: michael@0: case URX_ONECHAR: michael@0: case URX_ONECHAR_I: michael@0: REGEX_DUMP_DEBUG_PRINTF(("%c", val<256?val:'?')); michael@0: break; michael@0: michael@0: case URX_STRING: michael@0: case URX_STRING_I: michael@0: { michael@0: int32_t lengthOp = fCompiledPat->elementAti(index+1); michael@0: U_ASSERT(URX_TYPE(lengthOp) == URX_STRING_LEN); michael@0: int32_t length = URX_VAL(lengthOp); michael@0: int32_t i; michael@0: for (i=val; i= 256) {c = '.';} michael@0: REGEX_DUMP_DEBUG_PRINTF(("%c", c)); michael@0: } michael@0: } michael@0: break; michael@0: michael@0: case URX_SETREF: michael@0: case URX_LOOP_SR_I: michael@0: { michael@0: UnicodeString s; michael@0: UnicodeSet *set = (UnicodeSet *)fSets->elementAt(val); michael@0: set->toPattern(s, TRUE); michael@0: for (int32_t i=0; itoPattern(s, TRUE); michael@0: for (int32_t i=0; ifPattern, 0); michael@0: while (c != U_SENTINEL) { michael@0: if (c<32 || c>256) { michael@0: c = '.'; michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF(("%c", c)); michael@0: michael@0: c = UTEXT_NEXT32(This->fPattern); michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF(("\n")); michael@0: REGEX_DUMP_DEBUG_PRINTF((" Min Match Length: %d\n", This->fMinMatchLen)); michael@0: REGEX_DUMP_DEBUG_PRINTF((" Match Start Type: %s\n", START_OF_MATCH_STR(This->fStartType))); michael@0: if (This->fStartType == START_STRING) { michael@0: REGEX_DUMP_DEBUG_PRINTF((" Initial match string: \"")); michael@0: for (i=This->fInitialStringIdx; ifInitialStringIdx+This->fInitialStringLen; i++) { michael@0: REGEX_DUMP_DEBUG_PRINTF(("%c", This->fLiteralText[i])); // TODO: non-printables, surrogates. michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF(("\"\n")); michael@0: michael@0: } else if (This->fStartType == START_SET) { michael@0: int32_t numSetChars = This->fInitialChars->size(); michael@0: if (numSetChars > 20) { michael@0: numSetChars = 20; michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF((" Match First Chars : ")); michael@0: for (i=0; ifInitialChars->charAt(i); michael@0: if (0x20fInitialChars->size()) { michael@0: REGEX_DUMP_DEBUG_PRINTF((" ...")); michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF(("\n")); michael@0: michael@0: } else if (This->fStartType == START_CHAR) { michael@0: REGEX_DUMP_DEBUG_PRINTF((" First char of Match : ")); michael@0: if (0x20 < This->fInitialChar && This->fInitialChar<0x7e) { michael@0: REGEX_DUMP_DEBUG_PRINTF(("%c\n", This->fInitialChar)); michael@0: } else { michael@0: REGEX_DUMP_DEBUG_PRINTF(("%#x\n", This->fInitialChar)); michael@0: } michael@0: } michael@0: michael@0: REGEX_DUMP_DEBUG_PRINTF(("\nIndex Binary Type Operand\n" \ michael@0: "-------------------------------------------\n")); michael@0: for (index = 0; indexfCompiledPat->size(); index++) { michael@0: This->dumpOp(index); michael@0: } michael@0: REGEX_DUMP_DEBUG_PRINTF(("\n\n")); michael@0: } michael@0: #endif michael@0: michael@0: michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexPattern) michael@0: michael@0: U_NAMESPACE_END michael@0: #endif // !UCONFIG_NO_REGULAR_EXPRESSIONS