bool t4p::FinderClass::GetLastReplacementText(const UnicodeString& text, UnicodeString& replacementText) const { UBool matchFound = FALSE; if (IsFound && (LastPosition + LastLength) <= text.length()) { UnicodeString matchedText(text, LastPosition, LastLength); UnicodeString replaceWith = ReplaceExpression; UErrorCode error = U_ZERO_ERROR; RegexMatcher* matcher = NULL; switch (Mode) { case EXACT: matchFound = Expression == matchedText; if (matchFound) { replacementText = replaceWith; } break; case REGULAR_EXPRESSION: matcher = Pattern->matcher(matchedText, error); if (U_SUCCESS(error) && matcher && matcher->matches(error) && U_SUCCESS(error)) { replacementText = matcher->replaceFirst(replaceWith, error); matchFound = TRUE; } break; } if (matcher) { delete matcher; } } return matchFound == TRUE; }
//--------------------------------------------------------------------- // // matches Convenience function to test for a match, starting // with a pattern string and a data string. // //--------------------------------------------------------------------- UBool U_EXPORT2 RegexPattern::matches(const UnicodeString ®ex, const UnicodeString &input, UParseError &pe, UErrorCode &status) { if (U_FAILURE(status)) {return FALSE;} UBool retVal; RegexPattern *pat = NULL; RegexMatcher *matcher = NULL; pat = RegexPattern::compile(regex, 0, pe, status); matcher = pat->matcher(input, status); retVal = matcher->matches(status); delete matcher; delete pat; return retVal; }
// // matches, UText mode // UBool U_EXPORT2 RegexPattern::matches(UText *regex, UText *input, UParseError &pe, UErrorCode &status) { if (U_FAILURE(status)) {return FALSE;} UBool retVal; RegexPattern *pat = NULL; RegexMatcher *matcher = NULL; pat = RegexPattern::compile(regex, 0, pe, status); matcher = pat->matcher(input, PATTERN_IS_UTEXT, status); retVal = matcher->matches(status); delete matcher; delete pat; return retVal; }
// // matches, UText mode // UBool U_EXPORT2 RegexPattern::matches(UText *regex, UText *input, UParseError &pe, UErrorCode &status) { if (U_FAILURE(status)) {return FALSE;} UBool retVal = FALSE; RegexPattern *pat = NULL; RegexMatcher *matcher = NULL; pat = RegexPattern::compile(regex, 0, pe, status); matcher = pat->matcher(status); if (U_SUCCESS(status)) { matcher->reset(input); retVal = matcher->matches(status); } delete matcher; delete pat; return retVal; }