From 4a1c753cf327d2db3f993ba05360b95f9fbdf0ec Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Wed, 26 Apr 2006 00:51:53 +0000 Subject: [PATCH] ICU-5170 fix bug in break iterator use of UText, surfaced as failure in string search tests. X-SVN-Rev: 19593 --- icu4c/source/common/ubrk.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/icu4c/source/common/ubrk.cpp b/icu4c/source/common/ubrk.cpp index 7bf3e1066b6..6abf5396626 100644 --- a/icu4c/source/common/ubrk.cpp +++ b/icu4c/source/common/ubrk.cpp @@ -1,6 +1,6 @@ /* ***************************************************************************************** -* Copyright (C) 1996-2005, International Business Machines +* Copyright (C) 1996-2006, International Business Machines * Corporation and others. All Rights Reserved. ***************************************************************************************** */ @@ -168,26 +168,16 @@ ubrk_setText(UBreakIterator* bi, int32_t textLength, UErrorCode* status) { - - if (U_FAILURE(*status)) return; - - const CharacterIterator& biText = ((BreakIterator*)bi)->getText(); - - int32_t textLen = (textLength == -1 ? u_strlen(text) : textLength); - if (biText.getDynamicClassID() == UCharCharacterIterator::getStaticClassID()) { - ((UCharCharacterIterator&)biText).setText(text, textLen); - } - else { - UCharCharacterIterator *iter = 0; - iter = new UCharCharacterIterator(text, textLen); - if(iter == 0) { - *status = U_MEMORY_ALLOCATION_ERROR; - return; - } - ((BreakIterator*)bi)->adoptText(iter); - } + BreakIterator *brit = (BreakIterator *)bi; + UText ut = UTEXT_INITIALIZER; + utext_openUChars(&ut, text, textLength, status); + brit->setText(&ut, *status); + // A stack allocated UText wrapping a UCHar * string + // can be dumped without explicitly closing it. } + + U_DRAFT void U_EXPORT2 ubrk_setUText(UBreakIterator *bi, UText *text,