diff options
author | claireho <chinglanho@gmail.com> | 2010-06-30 14:48:01 -0700 |
---|---|---|
committer | claireho <chinglanho@gmail.com> | 2010-06-30 14:57:29 -0700 |
commit | 2e615e9896b12236afe0ff2695e8afc2ee73f961 (patch) | |
tree | 4c074a8190a3298f4b2a584206c87eb4ce87b60e /i18n | |
parent | 2bae19d8f45dbf334f2ca6b38bb9f82357455a8f (diff) | |
download | icu4c-2e615e9896b12236afe0ff2695e8afc2ee73f961.tar.gz |
Bug 2777924:Matcher copies the Java String it's applied to onto
the native heap.
Added RegexMatcher::refreshInputText APIs.
Change-Id: Ie8eee7d23f64fc4b213a60726c1e58af4af9484f
Diffstat (limited to 'i18n')
-rw-r--r-- | i18n/rematch.cpp | 37 | ||||
-rw-r--r-- | i18n/unicode/regex.h | 23 | ||||
-rw-r--r-- | i18n/unicode/uregex.h | 27 | ||||
-rw-r--r-- | i18n/uregex.cpp | 21 |
4 files changed, 107 insertions, 1 deletions
diff --git a/i18n/rematch.cpp b/i18n/rematch.cpp index 92bad256..74e8fa2a 100644 --- a/i18n/rematch.cpp +++ b/i18n/rematch.cpp @@ -1927,7 +1927,44 @@ RegexMatcher &RegexMatcher::reset(int32_t position, UErrorCode &status) { return *this; } +// BEGIN android-added +// Removed this function after Android upgrad to ICU4.6. +//-------------------------------------------------------------------------------- +// +// refresh +// +//-------------------------------------------------------------------------------- +RegexMatcher &RegexMatcher::refreshInputText(UText *input, UErrorCode &status) { + if (U_FAILURE(status)) { + return *this; + } + if (input == NULL) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return *this; + } + if (utext_nativeLength(fInputText) != utext_nativeLength(input)) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return *this; + } + int64_t pos = utext_getNativeIndex(fInputText); + // Shallow read-only clone of the new UText into the existing input UText + fInputText = utext_clone(fInputText, input, FALSE, TRUE, &status); + if (U_FAILURE(status)) { + return *this; + } + utext_setNativeIndex(fInputText, pos); + if (fAltInputText != NULL) { + pos = utext_getNativeIndex(fAltInputText); + fAltInputText = utext_clone(fAltInputText, input, FALSE, TRUE, &status); + if (U_FAILURE(status)) { + return *this; + } + utext_setNativeIndex(fAltInputText, pos); + } + return *this; +} +// END android-added diff --git a/i18n/unicode/regex.h b/i18n/unicode/regex.h index 672f7ea5..a27480b1 100644 --- a/i18n/unicode/regex.h +++ b/i18n/unicode/regex.h @@ -1032,6 +1032,29 @@ public: */ virtual RegexMatcher &reset(UText *input); + // BEGIN android-added + // Removed this API after Android upgrade to ICU4.6. + /** + * Set the subject text string upon which the regular expression is looking for matches + * without changing any other aspect of the matching state. + * The new and previous text strings must have the same content. + * + * This function is intended for use in environments where ICU is operating on + * strings that may move around in memory. It provides a mechanism for notifying + * ICU that the string has been relocated, and providing a new UText to access the + * string in its new position. + * + * Caution: this function is normally used only by very specialized, + * system-level code. + * + * @param input The new (moved) text string. + * @param status Receives errors detected by this function. + * + * @internal ICU 4.6 + */ + virtual RegexMatcher &refreshInputText(UText *input, UErrorCode &status); + // END android-added + private: /** * Cause a compilation error if an application accidently attempts to diff --git a/i18n/unicode/uregex.h b/i18n/unicode/uregex.h index 0e8787de..4638ab80 100644 --- a/i18n/unicode/uregex.h +++ b/i18n/unicode/uregex.h @@ -395,6 +395,33 @@ uregex_getUText(URegularExpression *regexp, UText *dest, UErrorCode *status); +// BEGIN android-added +// Removed it after Android upgrade to ICU4.6. +/** + * Set the subject text string upon which the regular expression is looking for matches + * without changing any other aspect of the matching state. + * The new and previous text strings must have the same content. + * + * This function is intended for use in environments where ICU is operating on + * strings that may move around in memory. It provides a mechanism for notifying + * ICU that the string has been relocated, and providing a new UText to access the + * string in its new position. + * + * Caution: this function is normally used only by very specialized + * system-level code. + * + * @param regexp The compiled regular expression. + * @param text The new (moved) text string. + * @param status Receives errors detected by this function. + * + * @internal ICU 4.6 + */ +U_INTERNAL void U_EXPORT2 +uregex_refreshUText(URegularExpression *regexp, + UText *text, + UErrorCode *status); +// END android-added + /** * Attempts to match the input string against the pattern. * To succeed, the match must extend to the end of the string, diff --git a/i18n/uregex.cpp b/i18n/uregex.cpp index 37c567d6..213568cf 100644 --- a/i18n/uregex.cpp +++ b/i18n/uregex.cpp @@ -471,7 +471,7 @@ uregex_getText(URegularExpression *regexp2, // uregex_getUText // //------------------------------------------------------------------------------ -U_CAPI UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 uregex_getUText(URegularExpression *regexp2, UText *dest, UErrorCode *status) { @@ -482,6 +482,25 @@ uregex_getUText(URegularExpression *regexp2, return regexp->fMatcher->getInput(dest); } +// BEGIN android-added +// Removed this function after Android upgrade to ICU4.6. +//------------------------------------------------------------------------------ +// +// uregex_refreshUText +// +//------------------------------------------------------------------------------ +U_CAPI void U_EXPORT2 +uregex_refreshUText(URegularExpression *regexp2, + UText *text, + UErrorCode *status) { + RegularExpression *regexp = (RegularExpression*)regexp2; + if (validateRE(regexp, status, FALSE) == FALSE) { + return; + } + regexp->fMatcher->refreshInputText(text, *status); +} +// END android-added + //------------------------------------------------------------------------------ // |