X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/f3c0d7a59d99c2a94c6b8822291f0e42be3773c9..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/common/unistr_case.cpp diff --git a/icuSources/common/unistr_case.cpp b/icuSources/common/unistr_case.cpp index 1c62ce5e..2138d60c 100644 --- a/icuSources/common/unistr_case.cpp +++ b/icuSources/common/unistr_case.cpp @@ -19,6 +19,7 @@ */ #include "unicode/utypes.h" +#include "unicode/brkiter.h" #include "unicode/casemap.h" #include "unicode/edits.h" #include "unicode/putil.h" @@ -104,6 +105,12 @@ UnicodeString::caseMap(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITER UBool writable = isBufferWritable(); UErrorCode errorCode = U_ZERO_ERROR; +#if !UCONFIG_NO_BREAK_ITERATION + // Read-only alias to the original string contents for the titlecasing BreakIterator. + // We cannot set the iterator simply to *this because *this is being modified. + UnicodeString oldString; +#endif + // Try to avoid heap-allocating a new character array for this string. if (writable ? oldLength <= UPRV_LENGTHOF(oldBuffer) : oldLength < US_STACKBUF_SIZE) { // Short string: Copy the contents into a temporary buffer and @@ -123,6 +130,12 @@ UnicodeString::caseMap(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITER buffer = fUnion.fStackFields.fBuffer; capacity = US_STACKBUF_SIZE; } +#if !UCONFIG_NO_BREAK_ITERATION + if (iter != nullptr) { + oldString.setTo(FALSE, oldArray, oldLength); + iter->setText(oldString); + } +#endif newLength = stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR buffer, capacity, oldArray, oldLength, NULL, errorCode); @@ -143,7 +156,13 @@ UnicodeString::caseMap(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITER oldArray = getArrayStart(); Edits edits; UChar replacementChars[200]; - stringCaseMapper(caseLocale, options | UCASEMAP_OMIT_UNCHANGED_TEXT, UCASEMAP_BREAK_ITERATOR +#if !UCONFIG_NO_BREAK_ITERATION + if (iter != nullptr) { + oldString.setTo(FALSE, oldArray, oldLength); + iter->setText(oldString); + } +#endif + stringCaseMapper(caseLocale, options | U_OMIT_UNCHANGED_TEXT, UCASEMAP_BREAK_ITERATOR replacementChars, UPRV_LENGTHOF(replacementChars), oldArray, oldLength, &edits, errorCode); if (U_SUCCESS(errorCode)) { @@ -179,6 +198,7 @@ UnicodeString::caseMap(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITER return *this; } errorCode = U_ZERO_ERROR; + // No need to iter->setText() again: The case mapper restarts via iter->first(). newLength = stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR getArrayStart(), getCapacity(), oldArray, oldLength, NULL, errorCode);