| Index: Source/core/platform/text/TextBreakIteratorICU.cpp
|
| diff --git a/Source/core/platform/text/TextBreakIteratorICU.cpp b/Source/core/platform/text/TextBreakIteratorICU.cpp
|
| index e70b19f5e53fab8b9b7bffbdbfdda91357ea967f..06061ac913b5a4b36298b20047b6fa8578f54601 100644
|
| --- a/Source/core/platform/text/TextBreakIteratorICU.cpp
|
| +++ b/Source/core/platform/text/TextBreakIteratorICU.cpp
|
| @@ -31,17 +31,6 @@ using namespace std;
|
|
|
| namespace WebCore {
|
|
|
| -static TextBreakIterator* ensureIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type)
|
| -{
|
| - if (!createdIterator) {
|
| - UErrorCode openStatus = U_ZERO_ERROR;
|
| - iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, currentTextBreakLocaleID(), 0, 0, &openStatus));
|
| - createdIterator = true;
|
| - ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
|
| - }
|
| - return iterator;
|
| -}
|
| -
|
| enum TextContext { NoContext, PriorContext, PrimaryContext };
|
|
|
| const int textBufferCapacity = 16;
|
| @@ -410,31 +399,16 @@ static UText* textOpenUTF16(UText* text, const UChar* string, unsigned length, c
|
|
|
| static UText emptyText = UTEXT_INITIALIZER;
|
|
|
| -static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const UChar* string, int length)
|
| -{
|
| - if (!string)
|
| - return 0;
|
| -
|
| - iterator = ensureIterator(createdIterator, iterator, type);
|
| - if (!iterator)
|
| - return 0;
|
| -
|
| - UErrorCode setTextStatus = U_ZERO_ERROR;
|
| - ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
|
| - if (U_FAILURE(setTextStatus))
|
| - return 0;
|
| -
|
| - return iterator;
|
| -}
|
| -
|
| -static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const LChar* string, int length)
|
| +static TextBreakIterator* wordBreakIterator(const LChar* string, int length)
|
| {
|
| - if (!string)
|
| - return 0;
|
| -
|
| - iterator = ensureIterator(createdIterator, iterator, type);
|
| - if (!iterator)
|
| - return 0;
|
| + UErrorCode errorCode = U_ZERO_ERROR;
|
| + static TextBreakIterator* breakIter = 0;
|
| + if (!breakIter) {
|
| + breakIter = icu::BreakIterator::createWordInstance(currentTextBreakLocaleID(), errorCode);
|
| + ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break iterator: %s (%d)", u_errorName(errorCode), errorCode);
|
| + if (!breakIter)
|
| + return 0;
|
| + }
|
|
|
| UTextWithBuffer textLocal;
|
| textLocal.text = emptyText;
|
| @@ -449,32 +423,30 @@ static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator
|
| }
|
|
|
| UErrorCode setTextStatus = U_ZERO_ERROR;
|
| - ubrk_setUText(reinterpret_cast<UBreakIterator*>(iterator), text, &setTextStatus);
|
| + breakIter->setText(text, setTextStatus);
|
| if (U_FAILURE(setTextStatus)) {
|
| LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
|
| - // FIXME: Do we need to call utext_close(text) here?
|
| - return 0;
|
| + delete breakIter;
|
| }
|
|
|
| utext_close(text);
|
|
|
| - return iterator;
|
| -}
|
| -
|
| -static TextBreakIterator* wordBreakIterator(const LChar* string, int length)
|
| -{
|
| - static bool createdWordBreakIterator8 = false;
|
| - static TextBreakIterator* staticWordBreakIterator8;
|
| - return setUpIterator(createdWordBreakIterator8,
|
| - staticWordBreakIterator8, UBRK_WORD, string, length);
|
| + return breakIter;
|
| }
|
|
|
| TextBreakIterator* wordBreakIterator(const UChar* string, int length)
|
| {
|
| - static bool createdWordBreakIterator16 = false;
|
| - static TextBreakIterator* staticWordBreakIterator16;
|
| - return setUpIterator(createdWordBreakIterator16,
|
| - staticWordBreakIterator16, UBRK_WORD, string, length);
|
| + UErrorCode errorCode = U_ZERO_ERROR;
|
| + static TextBreakIterator* breakIter = 0;
|
| + if (!breakIter) {
|
| + breakIter = icu::BreakIterator::createWordInstance(currentTextBreakLocaleID(), errorCode);
|
| + ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break iterator: %s (%d)", u_errorName(errorCode), errorCode);
|
| + if (!breakIter)
|
| + return 0;
|
| + }
|
| +
|
| + breakIter->setText(icu::UnicodeString(string, length));
|
| + return breakIter;
|
| }
|
|
|
| TextBreakIterator* wordBreakIterator(const String& string, int start, int length)
|
| @@ -488,7 +460,7 @@ TextBreakIterator* wordBreakIterator(const String& string, int start, int length
|
|
|
| TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
|
| {
|
| - UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
|
| + TextBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
|
| if (!iterator)
|
| return 0;
|
|
|
| @@ -505,21 +477,20 @@ TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, con
|
| }
|
|
|
| UErrorCode setTextStatus = U_ZERO_ERROR;
|
| - ubrk_setUText(iterator, text, &setTextStatus);
|
| + iterator->setText(text, setTextStatus);
|
| if (U_FAILURE(setTextStatus)) {
|
| - // FIXME: Do we need to call utext_close(text) here?
|
| LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
|
| return 0;
|
| }
|
|
|
| utext_close(text);
|
|
|
| - return reinterpret_cast<TextBreakIterator*>(iterator);
|
| + return iterator;
|
| }
|
|
|
| TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
|
| {
|
| - UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
|
| + TextBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
|
| if (!iterator)
|
| return 0;
|
|
|
| @@ -533,23 +504,22 @@ TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, con
|
| }
|
|
|
| UErrorCode setTextStatus = U_ZERO_ERROR;
|
| - ubrk_setUText(iterator, text, &setTextStatus);
|
| + iterator->setText(text, setTextStatus);
|
| if (U_FAILURE(setTextStatus)) {
|
| - // FIXME: Do we need to call utext_close(text) here?
|
| LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
|
| return 0;
|
| }
|
|
|
| utext_close(text);
|
|
|
| - return reinterpret_cast<TextBreakIterator*>(iterator);
|
| + return iterator;
|
| }
|
|
|
| void releaseLineBreakIterator(TextBreakIterator* iterator)
|
| {
|
| ASSERT_ARG(iterator, iterator);
|
|
|
| - LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
|
| + LineBreakIteratorPool::sharedPool().put(iterator);
|
| }
|
|
|
| static TextBreakIterator* nonSharedCharacterBreakIterator;
|
| @@ -600,7 +570,13 @@ void NonSharedCharacterBreakIterator::createIteratorForBuffer(const UChar* buffe
|
| {
|
| m_iterator = nonSharedCharacterBreakIterator;
|
| bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
|
| - m_iterator = setUpIterator(createdIterator, m_iterator, UBRK_CHARACTER, buffer, length);
|
| + if (!createdIterator) {
|
| + UErrorCode errorCode = U_ZERO_ERROR;
|
| + m_iterator = icu::BreakIterator::createCharacterInstance(currentTextBreakLocaleID(), errorCode);
|
| + ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break iterator: %s (%d)", u_errorName(errorCode), errorCode);
|
| + }
|
| +
|
| + m_iterator->setText(icu::UnicodeString(buffer, length));
|
| }
|
|
|
| NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
|
| @@ -608,13 +584,13 @@ NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
|
| if (m_is8Bit)
|
| return;
|
| if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
|
| - ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
|
| + delete m_iterator;
|
| }
|
|
|
| int NonSharedCharacterBreakIterator::next()
|
| {
|
| if (!m_is8Bit)
|
| - return textBreakNext(m_iterator);
|
| + return m_iterator->next();
|
|
|
| if (m_offset >= m_length)
|
| return TextBreakDone;
|
| @@ -626,21 +602,21 @@ int NonSharedCharacterBreakIterator::next()
|
| int NonSharedCharacterBreakIterator::current()
|
| {
|
| if (!m_is8Bit)
|
| - return textBreakCurrent(m_iterator);
|
| + return m_iterator->current();
|
| return m_offset;
|
| }
|
|
|
| bool NonSharedCharacterBreakIterator::isBreak(int offset) const
|
| {
|
| if (!m_is8Bit)
|
| - return isTextBreak(m_iterator, offset);
|
| + return m_iterator->isBoundary(offset);
|
| return !isLFAfterCR(offset);
|
| }
|
|
|
| int NonSharedCharacterBreakIterator::preceding(int offset) const
|
| {
|
| if (!m_is8Bit)
|
| - return textBreakPreceding(m_iterator, offset);
|
| + return m_iterator->preceding(offset);
|
| if (offset <= 0)
|
| return TextBreakDone;
|
| if (isLFAfterCR(offset))
|
| @@ -651,7 +627,7 @@ int NonSharedCharacterBreakIterator::preceding(int offset) const
|
| int NonSharedCharacterBreakIterator::following(int offset) const
|
| {
|
| if (!m_is8Bit)
|
| - return textBreakFollowing(m_iterator, offset);
|
| + return m_iterator->following(offset);
|
| if (static_cast<unsigned>(offset) >= m_length)
|
| return TextBreakDone;
|
| return offset + clusterLengthStartingAt(offset);
|
| @@ -659,81 +635,43 @@ int NonSharedCharacterBreakIterator::following(int offset) const
|
|
|
| TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
|
| {
|
| - static bool createdSentenceBreakIterator = false;
|
| - static TextBreakIterator* staticSentenceBreakIterator;
|
| - return setUpIterator(createdSentenceBreakIterator,
|
| - staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
|
| -}
|
| -
|
| -int textBreakFirst(TextBreakIterator* iterator)
|
| -{
|
| - return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
|
| -}
|
| -
|
| -int textBreakLast(TextBreakIterator* iterator)
|
| -{
|
| - return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
|
| -}
|
| -
|
| -int textBreakNext(TextBreakIterator* iterator)
|
| -{
|
| - return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
|
| -}
|
| -
|
| -int textBreakPrevious(TextBreakIterator* iterator)
|
| -{
|
| - return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
|
| -}
|
| -
|
| -int textBreakPreceding(TextBreakIterator* iterator, int pos)
|
| -{
|
| - return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
|
| -}
|
| -
|
| -int textBreakFollowing(TextBreakIterator* iterator, int pos)
|
| -{
|
| - return ubrk_following(reinterpret_cast<UBreakIterator*>(iterator), pos);
|
| -}
|
| -
|
| -int textBreakCurrent(TextBreakIterator* iterator)
|
| -{
|
| - return ubrk_current(reinterpret_cast<UBreakIterator*>(iterator));
|
| -}
|
| + UErrorCode openStatus = U_ZERO_ERROR;
|
| + static TextBreakIterator* iterator = 0;
|
| + if (!iterator) {
|
| + iterator = icu::BreakIterator::createSentenceInstance(currentTextBreakLocaleID(), openStatus);
|
| + ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
|
| + if (!iterator)
|
| + return 0;
|
| + }
|
|
|
| -bool isTextBreak(TextBreakIterator* iterator, int position)
|
| -{
|
| - return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
|
| + iterator->setText(icu::UnicodeString(string, length));
|
| + return iterator;
|
| }
|
|
|
| bool isWordTextBreak(TextBreakIterator* iterator)
|
| {
|
| - int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
|
| + int ruleStatus = iterator->getRuleStatus();
|
| return ruleStatus != UBRK_WORD_NONE;
|
| }
|
|
|
| -static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator,
|
| - const char* breakRules, const UChar* string, int length)
|
| +static TextBreakIterator* setUpIteratorWithRules(const char* breakRules, const UChar* string, int length)
|
| {
|
| if (!string)
|
| return 0;
|
|
|
| - if (!createdIterator) {
|
| - UParseError parseStatus;
|
| - UErrorCode openStatus = U_ZERO_ERROR;
|
| - Vector<UChar> rules;
|
| - String(breakRules).appendTo(rules);
|
| - iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.data(), rules.size(), 0, 0, &parseStatus, &openStatus));
|
| - createdIterator = true;
|
| + static TextBreakIterator* iterator = 0;
|
| + UParseError parseStatus;
|
| + UErrorCode openStatus = U_ZERO_ERROR;
|
| + Vector<UChar> rules;
|
| + String(breakRules).appendTo(rules);
|
| + if (!iterator) {
|
| + iterator = new icu::RuleBasedBreakIterator(icu::UnicodeString(rules.data(), rules.size()), parseStatus, openStatus);
|
| ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
|
| + if (!iterator)
|
| + return 0;
|
| }
|
| - if (!iterator)
|
| - return 0;
|
| -
|
| - UErrorCode setTextStatus = U_ZERO_ERROR;
|
| - ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
|
| - if (U_FAILURE(setTextStatus))
|
| - return 0;
|
|
|
| + iterator->setText(icu::UnicodeString(string, length));
|
| return iterator;
|
| }
|
|
|
| @@ -821,9 +759,8 @@ TextBreakIterator* cursorMovementIterator(const UChar* string, int length)
|
| "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward)
|
| "!!safe_reverse;"
|
| "!!safe_forward;";
|
| - static bool createdCursorMovementIterator = false;
|
| - static TextBreakIterator* staticCursorMovementIterator;
|
| - return setUpIteratorWithRules(createdCursorMovementIterator, staticCursorMovementIterator, kRules, string, length);
|
| +
|
| + return setUpIteratorWithRules(kRules, string, length);
|
| }
|
|
|
| }
|
|
|