michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2004-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * file name: uregex.cpp 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/uregex.h" michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/utf16.h" michael@0: #include "umutex.h" michael@0: #include "uassert.h" michael@0: #include "cmemory.h" michael@0: michael@0: #include "regextxt.h" michael@0: michael@0: #include michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: #define REMAINING_CAPACITY(idx,len) ((((len)-(idx))>0)?((len)-(idx)):0) michael@0: michael@0: struct RegularExpression: public UMemory { michael@0: public: michael@0: RegularExpression(); michael@0: ~RegularExpression(); michael@0: int32_t fMagic; michael@0: RegexPattern *fPat; michael@0: u_atomic_int32_t *fPatRefCount; michael@0: UChar *fPatString; michael@0: int32_t fPatStringLen; michael@0: RegexMatcher *fMatcher; michael@0: const UChar *fText; // Text from setText() michael@0: int32_t fTextLength; // Length provided by user with setText(), which michael@0: // may be -1. michael@0: UBool fOwnsText; michael@0: }; michael@0: michael@0: static const int32_t REXP_MAGIC = 0x72657870; // "rexp" in ASCII michael@0: michael@0: RegularExpression::RegularExpression() { michael@0: fMagic = REXP_MAGIC; michael@0: fPat = NULL; michael@0: fPatRefCount = NULL; michael@0: fPatString = NULL; michael@0: fPatStringLen = 0; michael@0: fMatcher = NULL; michael@0: fText = NULL; michael@0: fTextLength = 0; michael@0: fOwnsText = FALSE; michael@0: } michael@0: michael@0: RegularExpression::~RegularExpression() { michael@0: delete fMatcher; michael@0: fMatcher = NULL; michael@0: if (fPatRefCount!=NULL && umtx_atomic_dec(fPatRefCount)==0) { michael@0: delete fPat; michael@0: uprv_free(fPatString); michael@0: uprv_free((void *)fPatRefCount); michael@0: } michael@0: if (fOwnsText && fText!=NULL) { michael@0: uprv_free((void *)fText); michael@0: } michael@0: fMagic = 0; michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: //---------------------------------------------------------------------------------------- michael@0: // michael@0: // validateRE Do boilerplate style checks on API function parameters. michael@0: // Return TRUE if they look OK. michael@0: //---------------------------------------------------------------------------------------- michael@0: static UBool validateRE(const RegularExpression *re, UBool requiresText, UErrorCode *status) { michael@0: if (U_FAILURE(*status)) { michael@0: return FALSE; michael@0: } michael@0: if (re == NULL || re->fMagic != REXP_MAGIC) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return FALSE; michael@0: } michael@0: // !!! Not sure how to update this with the new UText backing, which is stored in re->fMatcher anyway michael@0: if (requiresText && re->fText == NULL && !re->fOwnsText) { michael@0: *status = U_REGEX_INVALID_STATE; michael@0: return FALSE; michael@0: } michael@0: return TRUE; michael@0: } michael@0: michael@0: //---------------------------------------------------------------------------------------- michael@0: // michael@0: // uregex_open michael@0: // michael@0: //---------------------------------------------------------------------------------------- michael@0: U_CAPI URegularExpression * U_EXPORT2 michael@0: uregex_open( const UChar *pattern, michael@0: int32_t patternLength, 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: if (pattern == NULL || patternLength < -1 || patternLength == 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return NULL; michael@0: } michael@0: int32_t actualPatLen = patternLength; michael@0: if (actualPatLen == -1) { michael@0: actualPatLen = u_strlen(pattern); michael@0: } michael@0: michael@0: RegularExpression *re = new RegularExpression; michael@0: u_atomic_int32_t *refC = (u_atomic_int32_t *)uprv_malloc(sizeof(int32_t)); michael@0: UChar *patBuf = (UChar *)uprv_malloc(sizeof(UChar)*(actualPatLen+1)); michael@0: if (re == NULL || refC == NULL || patBuf == NULL) { michael@0: *status = U_MEMORY_ALLOCATION_ERROR; michael@0: delete re; michael@0: uprv_free((void *)refC); michael@0: uprv_free(patBuf); michael@0: return NULL; michael@0: } michael@0: re->fPatRefCount = refC; michael@0: *re->fPatRefCount = 1; michael@0: michael@0: // michael@0: // Make a copy of the pattern string, so we can return it later if asked. michael@0: // For compiling the pattern, we will use a UText wrapper around michael@0: // this local copy, to avoid making even more copies. michael@0: // michael@0: re->fPatString = patBuf; michael@0: re->fPatStringLen = patternLength; michael@0: u_memcpy(patBuf, pattern, actualPatLen); michael@0: patBuf[actualPatLen] = 0; michael@0: michael@0: UText patText = UTEXT_INITIALIZER; michael@0: utext_openUChars(&patText, patBuf, patternLength, status); michael@0: michael@0: // michael@0: // Compile the pattern michael@0: // michael@0: if (pe != NULL) { michael@0: re->fPat = RegexPattern::compile(&patText, flags, *pe, *status); michael@0: } else { michael@0: re->fPat = RegexPattern::compile(&patText, flags, *status); michael@0: } michael@0: utext_close(&patText); michael@0: michael@0: if (U_FAILURE(*status)) { michael@0: goto ErrorExit; michael@0: } michael@0: michael@0: // michael@0: // Create the matcher object michael@0: // michael@0: re->fMatcher = re->fPat->matcher(*status); michael@0: if (U_SUCCESS(*status)) { michael@0: return (URegularExpression*)re; michael@0: } michael@0: michael@0: ErrorExit: michael@0: delete re; michael@0: return NULL; michael@0: michael@0: } michael@0: michael@0: //---------------------------------------------------------------------------------------- michael@0: // michael@0: // uregex_openUText michael@0: // michael@0: //---------------------------------------------------------------------------------------- michael@0: U_CAPI URegularExpression * U_EXPORT2 michael@0: uregex_openUText(UText *pattern, 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: if (pattern == NULL) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return NULL; michael@0: } michael@0: michael@0: int64_t patternNativeLength = utext_nativeLength(pattern); michael@0: michael@0: if (patternNativeLength == 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return NULL; michael@0: } michael@0: michael@0: RegularExpression *re = new RegularExpression; michael@0: michael@0: UErrorCode lengthStatus = U_ZERO_ERROR; michael@0: int32_t pattern16Length = utext_extract(pattern, 0, patternNativeLength, NULL, 0, &lengthStatus); michael@0: michael@0: u_atomic_int32_t *refC = (u_atomic_int32_t *)uprv_malloc(sizeof(int32_t)); michael@0: UChar *patBuf = (UChar *)uprv_malloc(sizeof(UChar)*(pattern16Length+1)); michael@0: if (re == NULL || refC == NULL || patBuf == NULL) { michael@0: *status = U_MEMORY_ALLOCATION_ERROR; michael@0: delete re; michael@0: uprv_free((void *)refC); michael@0: uprv_free(patBuf); michael@0: return NULL; michael@0: } michael@0: re->fPatRefCount = refC; michael@0: *re->fPatRefCount = 1; michael@0: michael@0: // michael@0: // Make a copy of the pattern string, so we can return it later if asked. michael@0: // For compiling the pattern, we will use a read-only UText wrapper michael@0: // around this local copy, to avoid making even more copies. michael@0: // michael@0: re->fPatString = patBuf; michael@0: re->fPatStringLen = pattern16Length; michael@0: utext_extract(pattern, 0, patternNativeLength, patBuf, pattern16Length+1, status); michael@0: michael@0: UText patText = UTEXT_INITIALIZER; michael@0: utext_openUChars(&patText, patBuf, pattern16Length, status); michael@0: michael@0: // michael@0: // Compile the pattern michael@0: // michael@0: if (pe != NULL) { michael@0: re->fPat = RegexPattern::compile(&patText, flags, *pe, *status); michael@0: } else { michael@0: re->fPat = RegexPattern::compile(&patText, flags, *status); michael@0: } michael@0: utext_close(&patText); michael@0: michael@0: if (U_FAILURE(*status)) { michael@0: goto ErrorExit; michael@0: } michael@0: michael@0: // michael@0: // Create the matcher object michael@0: // michael@0: re->fMatcher = re->fPat->matcher(*status); michael@0: if (U_SUCCESS(*status)) { michael@0: return (URegularExpression*)re; michael@0: } michael@0: michael@0: ErrorExit: michael@0: delete re; michael@0: return NULL; michael@0: michael@0: } michael@0: michael@0: //---------------------------------------------------------------------------------------- michael@0: // michael@0: // uregex_close michael@0: // michael@0: //---------------------------------------------------------------------------------------- michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_close(URegularExpression *re2) { michael@0: RegularExpression *re = (RegularExpression*)re2; michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: if (validateRE(re, FALSE, &status) == FALSE) { michael@0: return; michael@0: } michael@0: delete re; michael@0: } michael@0: michael@0: michael@0: //---------------------------------------------------------------------------------------- michael@0: // michael@0: // uregex_clone michael@0: // michael@0: //---------------------------------------------------------------------------------------- michael@0: U_CAPI URegularExpression * U_EXPORT2 michael@0: uregex_clone(const URegularExpression *source2, UErrorCode *status) { michael@0: RegularExpression *source = (RegularExpression*)source2; michael@0: if (validateRE(source, FALSE, status) == FALSE) { michael@0: return NULL; michael@0: } michael@0: michael@0: RegularExpression *clone = new RegularExpression; michael@0: if (clone == NULL) { michael@0: *status = U_MEMORY_ALLOCATION_ERROR; michael@0: return NULL; michael@0: } michael@0: michael@0: clone->fMatcher = source->fPat->matcher(*status); michael@0: if (U_FAILURE(*status)) { michael@0: delete clone; michael@0: return NULL; michael@0: } michael@0: michael@0: clone->fPat = source->fPat; michael@0: clone->fPatRefCount = source->fPatRefCount; michael@0: clone->fPatString = source->fPatString; michael@0: clone->fPatStringLen = source->fPatStringLen; michael@0: umtx_atomic_inc(source->fPatRefCount); michael@0: // Note: fText is not cloned. michael@0: michael@0: return (URegularExpression*)clone; michael@0: } michael@0: michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_pattern michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI const UChar * U_EXPORT2 michael@0: uregex_pattern(const URegularExpression *regexp2, michael@0: int32_t *patLength, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return NULL; michael@0: } michael@0: if (patLength != NULL) { michael@0: *patLength = regexp->fPatStringLen; michael@0: } michael@0: return regexp->fPatString; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_patternUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_patternUText(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: return regexp->fPat->patternText(*status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_flags michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_flags(const URegularExpression *regexp2, UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: int32_t flags = regexp->fPat->flags(); michael@0: return flags; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setText(URegularExpression *regexp2, michael@0: const UChar *text, michael@0: int32_t textLength, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return; michael@0: } michael@0: if (text == NULL || textLength < -1) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return; michael@0: } michael@0: michael@0: if (regexp->fOwnsText && regexp->fText != NULL) { michael@0: uprv_free((void *)regexp->fText); michael@0: } michael@0: michael@0: regexp->fText = text; michael@0: regexp->fTextLength = textLength; michael@0: regexp->fOwnsText = FALSE; michael@0: michael@0: UText input = UTEXT_INITIALIZER; michael@0: utext_openUChars(&input, text, textLength, status); michael@0: regexp->fMatcher->reset(&input); michael@0: utext_close(&input); // reset() made a shallow clone, so we don't need this copy michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setUText(URegularExpression *regexp2, michael@0: UText *text, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return; michael@0: } michael@0: if (text == NULL) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return; michael@0: } michael@0: michael@0: if (regexp->fOwnsText && regexp->fText != NULL) { michael@0: uprv_free((void *)regexp->fText); michael@0: } michael@0: michael@0: regexp->fText = NULL; // only fill it in on request michael@0: regexp->fTextLength = -1; michael@0: regexp->fOwnsText = TRUE; michael@0: regexp->fMatcher->reset(text); michael@0: } michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI const UChar * U_EXPORT2 michael@0: uregex_getText(URegularExpression *regexp2, michael@0: int32_t *textLength, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return NULL; michael@0: } michael@0: michael@0: if (regexp->fText == NULL) { michael@0: // need to fill in the text michael@0: UText *inputText = regexp->fMatcher->inputText(); michael@0: int64_t inputNativeLength = utext_nativeLength(inputText); michael@0: if (UTEXT_FULL_TEXT_IN_CHUNK(inputText, inputNativeLength)) { michael@0: regexp->fText = inputText->chunkContents; michael@0: regexp->fTextLength = (int32_t)inputNativeLength; michael@0: regexp->fOwnsText = FALSE; // because the UText owns it michael@0: } else { michael@0: UErrorCode lengthStatus = U_ZERO_ERROR; michael@0: regexp->fTextLength = utext_extract(inputText, 0, inputNativeLength, NULL, 0, &lengthStatus); // buffer overflow error michael@0: UChar *inputChars = (UChar *)uprv_malloc(sizeof(UChar)*(regexp->fTextLength+1)); michael@0: michael@0: utext_extract(inputText, 0, inputNativeLength, inputChars, regexp->fTextLength+1, status); michael@0: regexp->fText = inputChars; michael@0: regexp->fOwnsText = TRUE; // should already be set but just in case michael@0: } michael@0: } michael@0: michael@0: if (textLength != NULL) { michael@0: *textLength = regexp->fTextLength; michael@0: } michael@0: return regexp->fText; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_getUText(URegularExpression *regexp2, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return dest; michael@0: } michael@0: return regexp->fMatcher->getInput(dest, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_refreshUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_refreshUText(URegularExpression *regexp2, michael@0: UText *text, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->refreshInputText(text, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_matches michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_matches(URegularExpression *regexp2, michael@0: int32_t startIndex, michael@0: UErrorCode *status) { michael@0: return uregex_matches64( regexp2, (int64_t)startIndex, status); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_matches64(URegularExpression *regexp2, michael@0: int64_t startIndex, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: UBool result = FALSE; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return result; michael@0: } michael@0: if (startIndex == -1) { michael@0: result = regexp->fMatcher->matches(*status); michael@0: } else { michael@0: result = regexp->fMatcher->matches(startIndex, *status); michael@0: } michael@0: return result; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_lookingAt michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_lookingAt(URegularExpression *regexp2, michael@0: int32_t startIndex, michael@0: UErrorCode *status) { michael@0: return uregex_lookingAt64( regexp2, (int64_t)startIndex, status); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_lookingAt64(URegularExpression *regexp2, michael@0: int64_t startIndex, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: UBool result = FALSE; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return result; michael@0: } michael@0: if (startIndex == -1) { michael@0: result = regexp->fMatcher->lookingAt(*status); michael@0: } else { michael@0: result = regexp->fMatcher->lookingAt(startIndex, *status); michael@0: } michael@0: return result; michael@0: } michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_find michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_find(URegularExpression *regexp2, michael@0: int32_t startIndex, michael@0: UErrorCode *status) { michael@0: return uregex_find64( regexp2, (int64_t)startIndex, status); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_find64(URegularExpression *regexp2, michael@0: int64_t startIndex, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: UBool result = FALSE; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return result; michael@0: } michael@0: if (startIndex == -1) { michael@0: regexp->fMatcher->resetPreserveRegion(); michael@0: result = regexp->fMatcher->find(); michael@0: } else { michael@0: result = regexp->fMatcher->find(startIndex, *status); michael@0: } michael@0: return result; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_findNext michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_findNext(URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return FALSE; michael@0: } michael@0: UBool result = regexp->fMatcher->find(); michael@0: return result; michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_groupCount michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_groupCount(URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: int32_t result = regexp->fMatcher->groupCount(); michael@0: return result; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_group michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_group(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UChar *dest, michael@0: int32_t destCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (destCapacity < 0 || (destCapacity > 0 && dest == NULL)) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: if (destCapacity == 0 || regexp->fText != NULL) { michael@0: // If preflighting or if we already have the text as UChars, michael@0: // this is a little cheaper than going through uregex_groupUTextDeep() michael@0: michael@0: // michael@0: // Pick up the range of characters from the matcher michael@0: // michael@0: int32_t startIx = regexp->fMatcher->start(groupNum, *status); michael@0: int32_t endIx = regexp->fMatcher->end (groupNum, *status); michael@0: if (U_FAILURE(*status)) { michael@0: return 0; michael@0: } michael@0: michael@0: // michael@0: // Trim length based on buffer capacity michael@0: // michael@0: int32_t fullLength = endIx - startIx; michael@0: int32_t copyLength = fullLength; michael@0: if (copyLength < destCapacity) { michael@0: dest[copyLength] = 0; michael@0: } else if (copyLength == destCapacity) { michael@0: *status = U_STRING_NOT_TERMINATED_WARNING; michael@0: } else { michael@0: copyLength = destCapacity; michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: michael@0: // michael@0: // Copy capture group to user's buffer michael@0: // michael@0: if (copyLength > 0) { michael@0: u_memcpy(dest, ®exp->fText[startIx], copyLength); michael@0: } michael@0: return fullLength; michael@0: } else { michael@0: UText *groupText = uregex_groupUTextDeep(regexp2, groupNum, NULL, status); michael@0: int32_t result = utext_extract(groupText, 0, utext_nativeLength(groupText), dest, destCapacity, status); michael@0: utext_close(groupText); michael@0: return result; michael@0: } michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_groupUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_groupUText(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UText *dest, michael@0: int64_t *groupLength, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: UErrorCode emptyTextStatus = U_ZERO_ERROR; michael@0: return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus)); michael@0: } michael@0: michael@0: return regexp->fMatcher->group(groupNum, dest, *groupLength, *status); michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_groupUTextDeep michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_groupUTextDeep(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: UErrorCode emptyTextStatus = U_ZERO_ERROR; michael@0: return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus)); michael@0: } michael@0: michael@0: if (regexp->fText != NULL) { michael@0: // michael@0: // Pick up the range of characters from the matcher michael@0: // and use our already-extracted characters michael@0: // michael@0: int32_t startIx = regexp->fMatcher->start(groupNum, *status); michael@0: int32_t endIx = regexp->fMatcher->end (groupNum, *status); michael@0: if (U_FAILURE(*status)) { michael@0: UErrorCode emptyTextStatus = U_ZERO_ERROR; michael@0: return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus)); michael@0: } michael@0: michael@0: if (dest) { michael@0: utext_replace(dest, 0, utext_nativeLength(dest), ®exp->fText[startIx], endIx - startIx, status); michael@0: } else { michael@0: UText groupText = UTEXT_INITIALIZER; michael@0: utext_openUChars(&groupText, ®exp->fText[startIx], endIx - startIx, status); michael@0: dest = utext_clone(NULL, &groupText, TRUE, FALSE, status); michael@0: utext_close(&groupText); michael@0: } michael@0: michael@0: return dest; michael@0: } else { michael@0: return regexp->fMatcher->group(groupNum, dest, *status); michael@0: } michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_start michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_start(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UErrorCode *status) { michael@0: return (int32_t)uregex_start64( regexp2, groupNum, status); michael@0: } michael@0: michael@0: U_CAPI int64_t U_EXPORT2 michael@0: uregex_start64(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: int32_t result = regexp->fMatcher->start(groupNum, *status); michael@0: return result; michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_end michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_end(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UErrorCode *status) { michael@0: return (int32_t)uregex_end64( regexp2, groupNum, status); michael@0: } michael@0: michael@0: U_CAPI int64_t U_EXPORT2 michael@0: uregex_end64(URegularExpression *regexp2, michael@0: int32_t groupNum, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: int32_t result = regexp->fMatcher->end(groupNum, *status); michael@0: return result; michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_reset michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_reset(URegularExpression *regexp2, michael@0: int32_t index, michael@0: UErrorCode *status) { michael@0: uregex_reset64( regexp2, (int64_t)index, status); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_reset64(URegularExpression *regexp2, michael@0: int64_t index, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->reset(index, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setRegion michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setRegion(URegularExpression *regexp2, michael@0: int32_t regionStart, michael@0: int32_t regionLimit, michael@0: UErrorCode *status) { michael@0: uregex_setRegion64( regexp2, (int64_t)regionStart, (int64_t)regionLimit, status); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setRegion64(URegularExpression *regexp2, michael@0: int64_t regionStart, michael@0: int64_t regionLimit, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->region(regionStart, regionLimit, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setRegionAndStart michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setRegionAndStart(URegularExpression *regexp2, michael@0: int64_t regionStart, michael@0: int64_t regionLimit, michael@0: int64_t startIndex, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->region(regionStart, regionLimit, startIndex, *status); michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_regionStart michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_regionStart(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: return (int32_t)uregex_regionStart64(regexp2, status); michael@0: } michael@0: michael@0: U_CAPI int64_t U_EXPORT2 michael@0: uregex_regionStart64(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: return regexp->fMatcher->regionStart(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_regionEnd michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_regionEnd(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: return (int32_t)uregex_regionEnd64(regexp2, status); michael@0: } michael@0: michael@0: U_CAPI int64_t U_EXPORT2 michael@0: uregex_regionEnd64(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: return regexp->fMatcher->regionEnd(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_hasTransparentBounds michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_hasTransparentBounds(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return FALSE; michael@0: } michael@0: return regexp->fMatcher->hasTransparentBounds(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_useTransparentBounds michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_useTransparentBounds(URegularExpression *regexp2, michael@0: UBool b, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->useTransparentBounds(b); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_hasAnchoringBounds michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_hasAnchoringBounds(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return FALSE; michael@0: } michael@0: return regexp->fMatcher->hasAnchoringBounds(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_useAnchoringBounds michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_useAnchoringBounds(URegularExpression *regexp2, michael@0: UBool b, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status) == FALSE) { michael@0: return; michael@0: } michael@0: regexp->fMatcher->useAnchoringBounds(b); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_hitEnd michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_hitEnd(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return FALSE; michael@0: } michael@0: return regexp->fMatcher->hitEnd(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_requireEnd michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uregex_requireEnd(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return FALSE; michael@0: } michael@0: return regexp->fMatcher->requireEnd(); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setTimeLimit michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setTimeLimit(URegularExpression *regexp2, michael@0: int32_t limit, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->setTimeLimit(limit, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getTimeLimit michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_getTimeLimit(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: int32_t retVal = 0; michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: retVal = regexp->fMatcher->getTimeLimit(); michael@0: } michael@0: return retVal; michael@0: } michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setStackLimit michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setStackLimit(URegularExpression *regexp2, michael@0: int32_t limit, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->setStackLimit(limit, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getStackLimit michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_getStackLimit(const URegularExpression *regexp2, michael@0: UErrorCode *status) { michael@0: int32_t retVal = 0; michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: retVal = regexp->fMatcher->getStackLimit(); michael@0: } michael@0: return retVal; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setMatchCallback michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setMatchCallback(URegularExpression *regexp2, michael@0: URegexMatchCallback *callback, michael@0: const void *context, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->setMatchCallback(callback, context, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getMatchCallback michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_getMatchCallback(const URegularExpression *regexp2, michael@0: URegexMatchCallback **callback, michael@0: const void **context, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->getMatchCallback(*callback, *context, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_setMatchProgressCallback michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_setFindProgressCallback(URegularExpression *regexp2, michael@0: URegexFindProgressCallback *callback, michael@0: const void *context, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->setFindProgressCallback(callback, context, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_getMatchCallback michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_getFindProgressCallback(const URegularExpression *regexp2, michael@0: URegexFindProgressCallback **callback, michael@0: const void **context, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, FALSE, status)) { michael@0: regexp->fMatcher->getFindProgressCallback(*callback, *context, *status); michael@0: } michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_replaceAll michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_replaceAll(URegularExpression *regexp2, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (replacementText == NULL || replacementLength < -1 || michael@0: (destBuf == NULL && destCapacity > 0) || michael@0: destCapacity < 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: int32_t len = 0; michael@0: michael@0: uregex_reset(regexp2, 0, status); michael@0: michael@0: // Note: Seperate error code variables for findNext() and appendReplacement() michael@0: // are used so that destination buffer overflow errors michael@0: // in appendReplacement won't stop findNext() from working. michael@0: // appendReplacement() and appendTail() special case incoming buffer michael@0: // overflow errors, continuing to return the correct length. michael@0: UErrorCode findStatus = *status; michael@0: while (uregex_findNext(regexp2, &findStatus)) { michael@0: len += uregex_appendReplacement(regexp2, replacementText, replacementLength, michael@0: &destBuf, &destCapacity, status); michael@0: } michael@0: len += uregex_appendTail(regexp2, &destBuf, &destCapacity, status); michael@0: michael@0: if (U_FAILURE(findStatus)) { michael@0: // If anything went wrong with the findNext(), make that error trump michael@0: // whatever may have happened with the append() operations. michael@0: // Errors in findNext() are not expected. michael@0: *status = findStatus; michael@0: } michael@0: michael@0: return len; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_replaceAllUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_replaceAllUText(URegularExpression *regexp2, michael@0: UText *replacementText, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (replacementText == NULL) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: dest = regexp->fMatcher->replaceAll(replacementText, dest, *status); michael@0: return dest; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_replaceFirst michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_replaceFirst(URegularExpression *regexp2, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (replacementText == NULL || replacementLength < -1 || michael@0: (destBuf == NULL && destCapacity > 0) || michael@0: destCapacity < 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: int32_t len = 0; michael@0: UBool findSucceeded; michael@0: uregex_reset(regexp2, 0, status); michael@0: findSucceeded = uregex_find(regexp2, 0, status); michael@0: if (findSucceeded) { michael@0: len = uregex_appendReplacement(regexp2, replacementText, replacementLength, michael@0: &destBuf, &destCapacity, status); michael@0: } michael@0: len += uregex_appendTail(regexp2, &destBuf, &destCapacity, status); michael@0: michael@0: return len; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_replaceFirstUText michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_replaceFirstUText(URegularExpression *regexp2, michael@0: UText *replacementText, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (replacementText == NULL) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: dest = regexp->fMatcher->replaceFirst(replacementText, dest, *status); michael@0: return dest; michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_appendReplacement michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: // michael@0: // Dummy class, because these functions need to be friends of class RegexMatcher, michael@0: // and stand-alone C functions don't work as friends michael@0: // michael@0: class RegexCImpl { michael@0: public: michael@0: inline static int32_t appendReplacement(RegularExpression *regexp, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: inline static int32_t appendTail(RegularExpression *regexp, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status); michael@0: michael@0: inline static int32_t split(RegularExpression *regexp, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: int32_t *requiredCapacity, michael@0: UChar *destFields[], michael@0: int32_t destFieldsCapacity, michael@0: UErrorCode *status); michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: michael@0: michael@0: static const UChar BACKSLASH = 0x5c; michael@0: static const UChar DOLLARSIGN = 0x24; michael@0: michael@0: // michael@0: // Move a character to an output buffer, with bounds checking on the index. michael@0: // Index advances even if capacity is exceeded, for preflight size computations. michael@0: // This little sequence is used a LOT. michael@0: // michael@0: static inline void appendToBuf(UChar c, int32_t *idx, UChar *buf, int32_t bufCapacity) { michael@0: if (*idx < bufCapacity) { michael@0: buf[*idx] = c; michael@0: } michael@0: (*idx)++; michael@0: } michael@0: michael@0: michael@0: // michael@0: // appendReplacement, the actual implementation. michael@0: // michael@0: int32_t RegexCImpl::appendReplacement(RegularExpression *regexp, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status) { michael@0: michael@0: // If we come in with a buffer overflow error, don't suppress the operation. michael@0: // A series of appendReplacements, appendTail need to correctly preflight michael@0: // the buffer size when an overflow happens somewhere in the middle. michael@0: UBool pendingBufferOverflow = FALSE; michael@0: if (*status == U_BUFFER_OVERFLOW_ERROR && destCapacity != NULL && *destCapacity == 0) { michael@0: pendingBufferOverflow = TRUE; michael@0: *status = U_ZERO_ERROR; michael@0: } michael@0: michael@0: // michael@0: // Validate all paramters michael@0: // michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if (replacementText == NULL || replacementLength < -1 || michael@0: destCapacity == NULL || destBuf == NULL || michael@0: (*destBuf == NULL && *destCapacity > 0) || michael@0: *destCapacity < 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: RegexMatcher *m = regexp->fMatcher; michael@0: if (m->fMatch == FALSE) { michael@0: *status = U_REGEX_INVALID_STATE; michael@0: return 0; michael@0: } michael@0: michael@0: UChar *dest = *destBuf; michael@0: int32_t capacity = *destCapacity; michael@0: int32_t destIdx = 0; michael@0: int32_t i; michael@0: michael@0: // If it wasn't supplied by the caller, get the length of the replacement text. michael@0: // TODO: slightly smarter logic in the copy loop could watch for the NUL on michael@0: // the fly and avoid this step. michael@0: if (replacementLength == -1) { michael@0: replacementLength = u_strlen(replacementText); michael@0: } michael@0: michael@0: // Copy input string from the end of previous match to start of current match michael@0: if (regexp->fText != NULL) { michael@0: int32_t matchStart; michael@0: int32_t lastMatchEnd; michael@0: if (UTEXT_USES_U16(m->fInputText)) { michael@0: lastMatchEnd = (int32_t)m->fLastMatchEnd; michael@0: matchStart = (int32_t)m->fMatchStart; michael@0: } else { michael@0: // !!!: Would like a better way to do this! michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: lastMatchEnd = utext_extract(m->fInputText, 0, m->fLastMatchEnd, NULL, 0, &status); michael@0: status = U_ZERO_ERROR; michael@0: matchStart = lastMatchEnd + utext_extract(m->fInputText, m->fLastMatchEnd, m->fMatchStart, NULL, 0, &status); michael@0: } michael@0: for (i=lastMatchEnd; ifText[i], &destIdx, dest, capacity); michael@0: } michael@0: } else { michael@0: UErrorCode possibleOverflowError = U_ZERO_ERROR; // ignore michael@0: destIdx += utext_extract(m->fInputText, m->fLastMatchEnd, m->fMatchStart, michael@0: dest==NULL?NULL:&dest[destIdx], REMAINING_CAPACITY(destIdx, capacity), michael@0: &possibleOverflowError); michael@0: } michael@0: U_ASSERT(destIdx >= 0); michael@0: michael@0: // scan the replacement text, looking for substitutions ($n) and \escapes. michael@0: int32_t replIdx = 0; michael@0: while (replIdx < replacementLength) { michael@0: UChar c = replacementText[replIdx]; michael@0: replIdx++; michael@0: if (c != DOLLARSIGN && c != BACKSLASH) { michael@0: // Common case, no substitution, no escaping, michael@0: // just copy the char to the dest buf. michael@0: appendToBuf(c, &destIdx, dest, capacity); michael@0: continue; michael@0: } michael@0: michael@0: if (c == BACKSLASH) { michael@0: // Backslash Escape. Copy the following char out without further checks. michael@0: // Note: Surrogate pairs don't need any special handling michael@0: // The second half wont be a '$' or a '\', and michael@0: // will move to the dest normally on the next michael@0: // loop iteration. michael@0: if (replIdx >= replacementLength) { michael@0: break; michael@0: } michael@0: c = replacementText[replIdx]; michael@0: michael@0: if (c==0x55/*U*/ || c==0x75/*u*/) { michael@0: // We have a \udddd or \Udddddddd escape sequence. michael@0: UChar32 escapedChar = michael@0: u_unescapeAt(uregex_ucstr_unescape_charAt, michael@0: &replIdx, // Index is updated by unescapeAt michael@0: replacementLength, // Length of replacement text michael@0: (void *)replacementText); michael@0: michael@0: if (escapedChar != (UChar32)0xFFFFFFFF) { michael@0: if (escapedChar <= 0xffff) { michael@0: appendToBuf((UChar)escapedChar, &destIdx, dest, capacity); michael@0: } else { michael@0: appendToBuf(U16_LEAD(escapedChar), &destIdx, dest, capacity); michael@0: appendToBuf(U16_TRAIL(escapedChar), &destIdx, dest, capacity); michael@0: } michael@0: continue; michael@0: } michael@0: // Note: if the \u escape was invalid, just fall through and michael@0: // treat it as a plain \ escape. michael@0: } michael@0: michael@0: // Plain backslash escape. Just put out the escaped character. michael@0: appendToBuf(c, &destIdx, dest, capacity); michael@0: michael@0: replIdx++; michael@0: continue; michael@0: } michael@0: michael@0: michael@0: michael@0: // We've got a $. Pick up a capture group number if one follows. michael@0: // Consume at most the number of digits necessary for the largest capture michael@0: // number that is valid for this pattern. michael@0: michael@0: int32_t numDigits = 0; michael@0: int32_t groupNum = 0; michael@0: UChar32 digitC; michael@0: for (;;) { michael@0: if (replIdx >= replacementLength) { michael@0: break; michael@0: } michael@0: U16_GET(replacementText, 0, replIdx, replacementLength, digitC); michael@0: if (u_isdigit(digitC) == FALSE) { michael@0: break; michael@0: } michael@0: michael@0: U16_FWD_1(replacementText, replIdx, replacementLength); michael@0: groupNum=groupNum*10 + u_charDigitValue(digitC); michael@0: numDigits++; michael@0: if (numDigits >= m->fPattern->fMaxCaptureDigits) { michael@0: break; michael@0: } michael@0: } michael@0: michael@0: michael@0: if (numDigits == 0) { michael@0: // The $ didn't introduce a group number at all. michael@0: // Treat it as just part of the substitution text. michael@0: appendToBuf(DOLLARSIGN, &destIdx, dest, capacity); michael@0: continue; michael@0: } michael@0: michael@0: // Finally, append the capture group data to the destination. michael@0: destIdx += uregex_group((URegularExpression*)regexp, groupNum, michael@0: dest==NULL?NULL:&dest[destIdx], REMAINING_CAPACITY(destIdx, capacity), status); michael@0: if (*status == U_BUFFER_OVERFLOW_ERROR) { michael@0: // Ignore buffer overflow when extracting the group. We need to michael@0: // continue on to get full size of the untruncated result. We will michael@0: // raise our own buffer overflow error at the end. michael@0: *status = U_ZERO_ERROR; michael@0: } michael@0: michael@0: if (U_FAILURE(*status)) { michael@0: // Can fail if group number is out of range. michael@0: break; michael@0: } michael@0: michael@0: } michael@0: michael@0: // michael@0: // Nul Terminate the dest buffer if possible. michael@0: // Set the appropriate buffer overflow or not terminated error, if needed. michael@0: // michael@0: if (destIdx < capacity) { michael@0: dest[destIdx] = 0; michael@0: } else if (destIdx == *destCapacity) { michael@0: *status = U_STRING_NOT_TERMINATED_WARNING; michael@0: } else { michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: michael@0: // michael@0: // Return an updated dest buffer and capacity to the caller. michael@0: // michael@0: if (destIdx > 0 && *destCapacity > 0) { michael@0: if (destIdx < capacity) { michael@0: *destBuf += destIdx; michael@0: *destCapacity -= destIdx; michael@0: } else { michael@0: *destBuf += capacity; michael@0: *destCapacity = 0; michael@0: } michael@0: } michael@0: michael@0: // If we came in with a buffer overflow, make sure we go out with one also. michael@0: // (A zero length match right at the end of the previous match could michael@0: // make this function succeed even though a previous call had overflowed the buf) michael@0: if (pendingBufferOverflow && U_SUCCESS(*status)) { michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: michael@0: return destIdx; michael@0: } michael@0: michael@0: // michael@0: // appendReplacement the actual API function, michael@0: // michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_appendReplacement(URegularExpression *regexp2, michael@0: const UChar *replacementText, michael@0: int32_t replacementLength, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status) { michael@0: michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: return RegexCImpl::appendReplacement( michael@0: regexp, replacementText, replacementLength,destBuf, destCapacity, status); michael@0: } michael@0: michael@0: // michael@0: // uregex_appendReplacementUText...can just use the normal C++ method michael@0: // michael@0: U_CAPI void U_EXPORT2 michael@0: uregex_appendReplacementUText(URegularExpression *regexp2, michael@0: UText *replText, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: regexp->fMatcher->appendReplacement(dest, replText, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // uregex_appendTail michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: int32_t RegexCImpl::appendTail(RegularExpression *regexp, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status) michael@0: { michael@0: michael@0: // If we come in with a buffer overflow error, don't suppress the operation. michael@0: // A series of appendReplacements, appendTail need to correctly preflight michael@0: // the buffer size when an overflow happens somewhere in the middle. michael@0: UBool pendingBufferOverflow = FALSE; michael@0: if (*status == U_BUFFER_OVERFLOW_ERROR && destCapacity != NULL && *destCapacity == 0) { michael@0: pendingBufferOverflow = TRUE; michael@0: *status = U_ZERO_ERROR; michael@0: } michael@0: michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: michael@0: if (destCapacity == NULL || destBuf == NULL || michael@0: (*destBuf == NULL && *destCapacity > 0) || michael@0: *destCapacity < 0) michael@0: { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: RegexMatcher *m = regexp->fMatcher; michael@0: michael@0: int32_t destIdx = 0; michael@0: int32_t destCap = *destCapacity; michael@0: UChar *dest = *destBuf; michael@0: michael@0: if (regexp->fText != NULL) { michael@0: int32_t srcIdx; michael@0: int64_t nativeIdx = (m->fMatch ? m->fMatchEnd : m->fLastMatchEnd); michael@0: if (nativeIdx == -1) { michael@0: srcIdx = 0; michael@0: } else if (UTEXT_USES_U16(m->fInputText)) { michael@0: srcIdx = (int32_t)nativeIdx; michael@0: } else { michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: srcIdx = utext_extract(m->fInputText, 0, nativeIdx, NULL, 0, &status); michael@0: } michael@0: michael@0: for (;;) { michael@0: U_ASSERT(destIdx >= 0); michael@0: michael@0: if (srcIdx == regexp->fTextLength) { michael@0: break; michael@0: } michael@0: UChar c = regexp->fText[srcIdx]; michael@0: if (c == 0 && regexp->fTextLength == -1) { michael@0: regexp->fTextLength = srcIdx; michael@0: break; michael@0: } michael@0: michael@0: if (destIdx < destCap) { michael@0: dest[destIdx] = c; michael@0: } else { michael@0: // We've overflowed the dest buffer. michael@0: // If the total input string length is known, we can michael@0: // compute the total buffer size needed without scanning through the string. michael@0: if (regexp->fTextLength > 0) { michael@0: destIdx += (regexp->fTextLength - srcIdx); michael@0: break; michael@0: } michael@0: } michael@0: srcIdx++; michael@0: destIdx++; michael@0: } michael@0: } else { michael@0: int64_t srcIdx; michael@0: if (m->fMatch) { michael@0: // The most recent call to find() succeeded. michael@0: srcIdx = m->fMatchEnd; michael@0: } else { michael@0: // The last call to find() on this matcher failed(). michael@0: // Look back to the end of the last find() that succeeded for src index. michael@0: srcIdx = m->fLastMatchEnd; michael@0: if (srcIdx == -1) { michael@0: // There has been no successful match with this matcher. michael@0: // We want to copy the whole string. michael@0: srcIdx = 0; michael@0: } michael@0: } michael@0: michael@0: destIdx = utext_extract(m->fInputText, srcIdx, m->fInputLength, dest, destCap, status); michael@0: } michael@0: michael@0: // michael@0: // NUL terminate the output string, if possible, otherwise issue the michael@0: // appropriate error or warning. michael@0: // michael@0: if (destIdx < destCap) { michael@0: dest[destIdx] = 0; michael@0: } else if (destIdx == destCap) { michael@0: *status = U_STRING_NOT_TERMINATED_WARNING; michael@0: } else { michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: michael@0: // michael@0: // Update the user's buffer ptr and capacity vars to reflect the michael@0: // amount used. michael@0: // michael@0: if (destIdx < destCap) { michael@0: *destBuf += destIdx; michael@0: *destCapacity -= destIdx; michael@0: } else if (*destBuf != NULL) { michael@0: *destBuf += destCap; michael@0: *destCapacity = 0; michael@0: } michael@0: michael@0: if (pendingBufferOverflow && U_SUCCESS(*status)) { michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: michael@0: return destIdx; michael@0: } michael@0: michael@0: michael@0: // michael@0: // appendTail the actual API function michael@0: // michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_appendTail(URegularExpression *regexp2, michael@0: UChar **destBuf, michael@0: int32_t *destCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: return RegexCImpl::appendTail(regexp, destBuf, destCapacity, status); michael@0: } michael@0: michael@0: michael@0: // michael@0: // uregex_appendTailUText...can just use the normal C++ method michael@0: // michael@0: U_CAPI UText * U_EXPORT2 michael@0: uregex_appendTailUText(URegularExpression *regexp2, michael@0: UText *dest, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: return regexp->fMatcher->appendTail(dest, *status); michael@0: } michael@0: michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // michael@0: // copyString Internal utility to copy a string to an output buffer, michael@0: // while managing buffer overflow and preflight size michael@0: // computation. NUL termination is added to destination, michael@0: // and the NUL is counted in the output size. michael@0: // michael@0: //------------------------------------------------------------------------------ michael@0: #if 0 michael@0: static void copyString(UChar *destBuffer, // Destination buffer. michael@0: int32_t destCapacity, // Total capacity of dest buffer michael@0: int32_t *destIndex, // Index into dest buffer. Updated on return. michael@0: // Update not clipped to destCapacity. michael@0: const UChar *srcPtr, // Pointer to source string michael@0: int32_t srcLen) // Source string len. michael@0: { michael@0: int32_t si; michael@0: int32_t di = *destIndex; michael@0: UChar c; michael@0: michael@0: for (si=0; sifMatcher->reset(); michael@0: UText *inputText = regexp->fMatcher->fInputText; michael@0: int64_t nextOutputStringStart = 0; michael@0: int64_t inputLen = regexp->fMatcher->fInputLength; michael@0: if (inputLen == 0) { michael@0: return 0; michael@0: } michael@0: michael@0: // michael@0: // Loop through the input text, searching for the delimiter pattern michael@0: // michael@0: int32_t i; // Index of the field being processed. michael@0: int32_t destIdx = 0; // Next available position in destBuf; michael@0: int32_t numCaptureGroups = regexp->fMatcher->groupCount(); michael@0: UErrorCode tStatus = U_ZERO_ERROR; // Want to ignore any buffer overflow errors so that the strings are still counted michael@0: for (i=0; ; i++) { michael@0: if (i>=destFieldsCapacity-1) { michael@0: // There are one or zero output strings left. michael@0: // Fill the last output string with whatever is left from the input, then exit the loop. michael@0: // ( i will be == destFieldsCapacity if we filled the output array while processing michael@0: // capture groups of the delimiter expression, in which case we will discard the michael@0: // last capture group saved in favor of the unprocessed remainder of the michael@0: // input string.) michael@0: if (inputLen > nextOutputStringStart) { michael@0: if (i != destFieldsCapacity-1) { michael@0: // No fields are left. Recycle the last one for holding the trailing part of michael@0: // the input string. michael@0: i = destFieldsCapacity-1; michael@0: destIdx = (int32_t)(destFields[i] - destFields[0]); michael@0: } michael@0: michael@0: destFields[i] = &destBuf[destIdx]; michael@0: destIdx += 1 + utext_extract(inputText, nextOutputStringStart, inputLen, michael@0: &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), status); michael@0: } michael@0: break; michael@0: } michael@0: michael@0: if (regexp->fMatcher->find()) { michael@0: // We found another delimiter. Move everything from where we started looking michael@0: // up until the start of the delimiter into the next output string. michael@0: destFields[i] = &destBuf[destIdx]; michael@0: michael@0: destIdx += 1 + utext_extract(inputText, nextOutputStringStart, regexp->fMatcher->fMatchStart, michael@0: &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), &tStatus); michael@0: if (tStatus == U_BUFFER_OVERFLOW_ERROR) { michael@0: tStatus = U_ZERO_ERROR; michael@0: } else { michael@0: *status = tStatus; michael@0: } michael@0: nextOutputStringStart = regexp->fMatcher->fMatchEnd; michael@0: michael@0: // If the delimiter pattern has capturing parentheses, the captured michael@0: // text goes out into the next n destination strings. michael@0: int32_t groupNum; michael@0: for (groupNum=1; groupNum<=numCaptureGroups; groupNum++) { michael@0: // If we've run out of output string slots, bail out. michael@0: if (i==destFieldsCapacity-1) { michael@0: break; michael@0: } michael@0: i++; michael@0: michael@0: // Set up to extract the capture group contents into the dest buffer. michael@0: destFields[i] = &destBuf[destIdx]; michael@0: tStatus = U_ZERO_ERROR; michael@0: int32_t t = uregex_group((URegularExpression*)regexp, michael@0: groupNum, michael@0: destFields[i], michael@0: REMAINING_CAPACITY(destIdx, destCapacity), michael@0: &tStatus); michael@0: destIdx += t + 1; // Record the space used in the output string buffer. michael@0: // +1 for the NUL that terminates the string. michael@0: if (tStatus == U_BUFFER_OVERFLOW_ERROR) { michael@0: tStatus = U_ZERO_ERROR; michael@0: } else { michael@0: *status = tStatus; michael@0: } michael@0: } michael@0: michael@0: if (nextOutputStringStart == inputLen) { michael@0: // The delimiter was at the end of the string. michael@0: // Output an empty string, and then we are done. michael@0: if (destIdx < destCapacity) { michael@0: destBuf[destIdx] = 0; michael@0: } michael@0: if (i < destFieldsCapacity-1) { michael@0: ++i; michael@0: } michael@0: if (destIdx < destCapacity) { michael@0: destFields[i] = destBuf + destIdx; michael@0: } michael@0: ++destIdx; michael@0: break; michael@0: } michael@0: michael@0: } michael@0: else michael@0: { michael@0: // We ran off the end of the input while looking for the next delimiter. michael@0: // All the remaining text goes into the current output string. michael@0: destFields[i] = &destBuf[destIdx]; michael@0: destIdx += 1 + utext_extract(inputText, nextOutputStringStart, inputLen, michael@0: &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), status); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: // Zero out any unused portion of the destFields array michael@0: int j; michael@0: for (j=i+1; j destCapacity) { michael@0: *status = U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: return i+1; michael@0: } michael@0: michael@0: // michael@0: // uregex_split The actual API function michael@0: // michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_split(URegularExpression *regexp2, michael@0: UChar *destBuf, michael@0: int32_t destCapacity, michael@0: int32_t *requiredCapacity, michael@0: UChar *destFields[], michael@0: int32_t destFieldsCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: if (validateRE(regexp, TRUE, status) == FALSE) { michael@0: return 0; michael@0: } michael@0: if ((destBuf == NULL && destCapacity > 0) || michael@0: destCapacity < 0 || michael@0: destFields == NULL || michael@0: destFieldsCapacity < 1 ) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: return RegexCImpl::split(regexp, destBuf, destCapacity, requiredCapacity, destFields, destFieldsCapacity, status); michael@0: } michael@0: michael@0: michael@0: // michael@0: // uregex_splitUText...can just use the normal C++ method michael@0: // michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uregex_splitUText(URegularExpression *regexp2, michael@0: UText *destFields[], michael@0: int32_t destFieldsCapacity, michael@0: UErrorCode *status) { michael@0: RegularExpression *regexp = (RegularExpression*)regexp2; michael@0: return regexp->fMatcher->split(regexp->fMatcher->inputText(), destFields, destFieldsCapacity, *status); michael@0: } michael@0: michael@0: michael@0: #endif // !UCONFIG_NO_REGULAR_EXPRESSIONS michael@0: