TextBreakIterator's should support Latin-1 for all iterator types (Part 1)
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 01:28:53 +0000 (01:28 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 01:28:53 +0000 (01:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126856

Reviewed by Darin Adler.

- Do some initial cleanup before adding complete Latin-1 support.

* platform/text/TextBreakIterator.cpp:
Remove non-ICU acquireLineBreakIterator() implementation.

* platform/text/TextBreakIterator.h:
- Changes acquireLineBreakIterator() to take a StringView.

* platform/text/TextBreakIteratorICU.cpp:
- Refactor iterator initialization and setting of text on the iterator.
- Add support for using a Latin-1 provider (this is not currently used).

* platform/text/icu/UTextProviderLatin1.cpp:
* platform/text/icu/UTextProviderLatin1.h:
- Add back non-context aware Latin-1 provider (from r129662).
- Rename context aware provider.

* platform/text/icu/UTextProviderUTF16.cpp:
* platform/text/icu/UTextProviderUTF16.h:
- Rename context aware provider.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161844 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/text/TextBreakIterator.cpp
Source/WebCore/platform/text/TextBreakIterator.h
Source/WebCore/platform/text/TextBreakIteratorICU.cpp
Source/WebCore/platform/text/icu/UTextProvider.h
Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp
Source/WebCore/platform/text/icu/UTextProviderLatin1.h
Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp
Source/WebCore/platform/text/icu/UTextProviderUTF16.h

index a96be9e..b37f431 100644 (file)
@@ -1,3 +1,31 @@
+2014-01-12  Sam Weinig  <sam@webkit.org>
+
+        TextBreakIterator's should support Latin-1 for all iterator types (Part 1)
+        https://bugs.webkit.org/show_bug.cgi?id=126856
+
+        Reviewed by Darin Adler.
+
+        - Do some initial cleanup before adding complete Latin-1 support.
+
+        * platform/text/TextBreakIterator.cpp:
+        Remove non-ICU acquireLineBreakIterator() implementation.
+
+        * platform/text/TextBreakIterator.h:
+        - Changes acquireLineBreakIterator() to take a StringView.
+
+        * platform/text/TextBreakIteratorICU.cpp:
+        - Refactor iterator initialization and setting of text on the iterator.
+        - Add support for using a Latin-1 provider (this is not currently used).
+
+        * platform/text/icu/UTextProviderLatin1.cpp:
+        * platform/text/icu/UTextProviderLatin1.h:
+        - Add back non-context aware Latin-1 provider (from r129662).
+        - Rename context aware provider.
+
+        * platform/text/icu/UTextProviderUTF16.cpp:
+        * platform/text/icu/UTextProviderUTF16.h:
+        - Rename context aware provider.
+
 2014-01-12  Brent Fulgham  <bfulgham@apple.com>
 
         [WebGL] Error messages should use source code labels, not internal mangled symbols.
index af26dbd..afd6dd0 100644 (file)
@@ -67,14 +67,4 @@ unsigned numCharactersInGraphemeClusters(const String& s, unsigned numGraphemeCl
     return textBreakCurrent(it);
 }
 
-#if !USE(ICU_UNICODE)
-TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
-{
-    Vector<UChar> utf16string(length);
-    for (int i = 0; i < length; ++i)
-        utf16string[i] = string[i];
-    return acquireLineBreakIterator(utf16string.data(), length, locale, priorContext, priorContextLength);
-}
-#endif
-
 } // namespace WebCore
index ebf22f1..1ae6719 100644 (file)
@@ -23,6 +23,7 @@
 #define TextBreakIterator_h
 
 #include <wtf/text/AtomicString.h>
+#include <wtf/text/StringView.h>
 #include <wtf/unicode/Unicode.h>
 
 namespace WebCore {
@@ -38,11 +39,11 @@ class TextBreakIterator;
 TextBreakIterator* cursorMovementIterator(const UChar*, int length);
 
 TextBreakIterator* wordBreakIterator(const UChar*, int length);
-TextBreakIterator* acquireLineBreakIterator(const LChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
-TextBreakIterator* acquireLineBreakIterator(const UChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
-void releaseLineBreakIterator(TextBreakIterator*);
 TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
 
+TextBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
+void releaseLineBreakIterator(TextBreakIterator*);
+
 int textBreakFirst(TextBreakIterator*);
 int textBreakLast(TextBreakIterator*);
 int textBreakNext(TextBreakIterator*);
@@ -130,10 +131,7 @@ public:
         ASSERT(priorContextLength <= priorContextCapacity);
         const UChar* priorContext = priorContextLength ? &m_priorContext[priorContextCapacity - priorContextLength] : 0;
         if (!m_iterator) {
-            if (m_string.is8Bit())
-                m_iterator = acquireLineBreakIterator(m_string.characters8(), m_string.length(), m_locale, priorContext, priorContextLength);
-            else
-                m_iterator = acquireLineBreakIterator(m_string.characters16(), m_string.length(), m_locale, priorContext, priorContextLength);
+            m_iterator = acquireLineBreakIterator(m_string, m_locale, priorContext, priorContextLength);
             m_cachedPriorContext = priorContext;
             m_cachedPriorContextLength = priorContextLength;
         } else if (priorContext != m_cachedPriorContext || priorContextLength != m_cachedPriorContextLength) {
index 7893ef1..a543390 100644 (file)
 #include "UTextProviderLatin1.h"
 #include "UTextProviderUTF16.h"
 #include <wtf/Atomics.h>
+#include <wtf/text/StringView.h>
 #include <wtf/text/WTFString.h>
 
 using namespace WTF;
 
 namespace WebCore {
 
-static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const UChar* string, int length)
-{
-    if (!string)
-        return 0;
-
-    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);
-    }
-    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;
-}
-
-TextBreakIterator* wordBreakIterator(const UChar* string, int length)
-{
-    static bool createdWordBreakIterator = false;
-    static TextBreakIterator* staticWordBreakIterator;
-    return setUpIterator(createdWordBreakIterator, staticWordBreakIterator, UBRK_WORD, string, length);
-}
-
-static UText emptyText = UTEXT_INITIALIZER;
+// Iterator initialization
 
-TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
+static TextBreakIterator* initializeIterator(UBreakIteratorType type, const char* locale = currentTextBreakLocaleID())
 {
-    UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
-    if (!iterator)
-        return 0;
-
-    UTextWithBuffer textLocal;
-    textLocal.text = emptyText;
-    textLocal.text.extraSize = sizeof(textLocal.buffer);
-    textLocal.text.pExtra = textLocal.buffer;
-
     UErrorCode openStatus = U_ZERO_ERROR;
-    UText* text = uTextOpenLatin1(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
-    if (U_FAILURE(openStatus)) {
-        LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
-        return 0;
-    }
-
-    UErrorCode setTextStatus = U_ZERO_ERROR;
-    ubrk_setUText(iterator, text, &setTextStatus);
-    if (U_FAILURE(setTextStatus)) {
-        LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
-        return 0;
-    }
-
-    utext_close(text);
-
-    return reinterpret_cast<TextBreakIterator*>(iterator);
+    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, locale, 0, 0, &openStatus));
+    ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
+    return iterator;
 }
 
-TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
+#if !PLATFORM(IOS)
+static TextBreakIterator* initializeIteratorWithRules(const char* breakRules)
 {
-    UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
-    if (!iterator)
-        return 0;
-
-    UText textLocal = UTEXT_INITIALIZER;
-
+    UParseError parseStatus;
     UErrorCode openStatus = U_ZERO_ERROR;
-    UText* text = uTextOpenUTF16(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
-    if (U_FAILURE(openStatus)) {
-        LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
-        return 0;
-    }
-
-    UErrorCode setTextStatus = U_ZERO_ERROR;
-    ubrk_setUText(iterator, text, &setTextStatus);
-    if (U_FAILURE(setTextStatus)) {
-        LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
-        return 0;
-    }
-
-    utext_close(text);
-
-    return reinterpret_cast<TextBreakIterator*>(iterator);
+    String rules(breakRules);
+    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
+    ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
+    return iterator;
 }
+#endif // !PLATFORM(IOS)
 
-void releaseLineBreakIterator(TextBreakIterator* iterator)
-{
-    ASSERT_ARG(iterator, iterator);
-
-    LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
-}
 
-static TextBreakIterator* nonSharedCharacterBreakIterator;
+// Iterator text setting
 
-static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
+static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, StringView string)
 {
-#if ENABLE(COMPARE_AND_SWAP)
-    return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
-#else
-    DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
-    MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
-    if (nonSharedCharacterBreakIterator != expected)
-        return false;
-    nonSharedCharacterBreakIterator = newValue;
-    return true;
-#endif
-}
+    if (string.is8Bit()) {
+        UTextWithBuffer textLocal;
+        textLocal.text = UTEXT_INITIALIZER;
+        textLocal.text.extraSize = sizeof(textLocal.buffer);
+        textLocal.text.pExtra = textLocal.buffer;
 
-NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
-{
-    m_iterator = nonSharedCharacterBreakIterator;
-    bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
-    m_iterator = setUpIterator(createdIterator, m_iterator, UBRK_CHARACTER, buffer, length);
-}
-
-NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
-{
-    if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
-        ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
-}
-
-TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
-{
-    static bool createdSentenceBreakIterator = false;
-    static TextBreakIterator* staticSentenceBreakIterator;
-    return setUpIterator(createdSentenceBreakIterator, staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
-}
+        UErrorCode openStatus = U_ZERO_ERROR;
+        UText* text = openLatin1UTextProvider(&textLocal, string.characters8(), string.length(), &openStatus);
+        if (U_FAILURE(openStatus)) {
+            LOG_ERROR("uTextOpenLatin1 failed with status %d", openStatus);
+            return nullptr;
+        }
+
+        UErrorCode setTextStatus = U_ZERO_ERROR;
+        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        if (U_FAILURE(setTextStatus)) {
+            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+            return nullptr;
+        }
+
+        utext_close(text);
+    } else {
+        UErrorCode setTextStatus = U_ZERO_ERROR;
+        ubrk_setText(reinterpret_cast<UBreakIterator*>(&iterator), string.characters16(), string.length(), &setTextStatus);
+        if (U_FAILURE(setTextStatus))
+            return nullptr;
+    }
 
-int textBreakFirst(TextBreakIterator* iterator)
-{
-    return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
+    return &iterator;
 }
 
-int textBreakLast(TextBreakIterator* iterator)
+static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iterator, StringView string, const UChar* priorContext, unsigned priorContextLength)
 {
-    return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
-}
+    if (string.is8Bit()) {
+        UTextWithBuffer textLocal;
+        textLocal.text = UTEXT_INITIALIZER;
+        textLocal.text.extraSize = sizeof(textLocal.buffer);
+        textLocal.text.pExtra = textLocal.buffer;
 
-int textBreakNext(TextBreakIterator* iterator)
-{
-    return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
-}
+        UErrorCode openStatus = U_ZERO_ERROR;
+        UText* text = openLatin1ContextAwareUTextProvider(&textLocal, string.characters8(), string.length(), priorContext, priorContextLength, &openStatus);
+        if (U_FAILURE(openStatus)) {
+            LOG_ERROR("openLatin1ContextAwareUTextProvider failed with status %d", openStatus);
+            return nullptr;
+        }
+
+        UErrorCode setTextStatus = U_ZERO_ERROR;
+        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        if (U_FAILURE(setTextStatus)) {
+            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+            return nullptr;
+        }
+
+        utext_close(text);
+    } else {
+        UText textLocal = UTEXT_INITIALIZER;
 
-int textBreakPrevious(TextBreakIterator* iterator)
-{
-    return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
-}
+        UErrorCode openStatus = U_ZERO_ERROR;
+        UText* text = openUTF16ContextAwareUTextProvider(&textLocal, string.characters16(), string.length(), priorContext, priorContextLength, &openStatus);
+        if (U_FAILURE(openStatus)) {
+            LOG_ERROR("openUTF16ContextAwareUTextProvider failed with status %d", openStatus);
+            return 0;
+        }
+
+        UErrorCode setTextStatus = U_ZERO_ERROR;
+        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        if (U_FAILURE(setTextStatus)) {
+            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+            return nullptr;
+        }
+
+        utext_close(text);
+    }
 
-int textBreakPreceding(TextBreakIterator* iterator, int pos)
-{
-    return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
+    return &iterator;
 }
 
-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));
-}
+// Static iterators
 
-bool isTextBreak(TextBreakIterator* iterator, int position)
+TextBreakIterator* wordBreakIterator(const UChar* buffer, int length)
 {
-    return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
-}
+    static TextBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
+    if (!staticWordBreakIterator)
+        return nullptr;
 
-bool isWordTextBreak(TextBreakIterator* iterator)
-{
-    int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
-    return ruleStatus != UBRK_WORD_NONE;
+    return setTextForIterator(*staticWordBreakIterator, StringView(buffer, length));
 }
 
-#if !PLATFORM(IOS)
-static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator, const char* breakRules, const UChar* string, int length)
+TextBreakIterator* sentenceBreakIterator(const UChar* buffer, int length)
 {
-    if (!string)
-        return 0;
-
-    if (!createdIterator) {
-        UParseError parseStatus;
-        UErrorCode openStatus = U_ZERO_ERROR;
-        String rules(breakRules);
-        iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
-        createdIterator = true;
-        ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
-    }
-    if (!iterator)
-        return 0;
-
-    UErrorCode setTextStatus = U_ZERO_ERROR;
-    ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
-    if (U_FAILURE(setTextStatus))
-        return 0;
+    static TextBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
+    if (!staticSentenceBreakIterator)
+        return nullptr;
 
-    return iterator;
+    return setTextForIterator(*staticSentenceBreakIterator, StringView(buffer, length));
 }
-#endif // !PLATFORM(IOS)
 
-TextBreakIterator* cursorMovementIterator(const UChar* string, int length)
+TextBreakIterator* cursorMovementIterator(const UChar* buffer, int length)
 {
 #if !PLATFORM(IOS)
     // This rule set is based on character-break iterator rules of ICU 4.0
@@ -320,33 +243,116 @@ 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);
+    static TextBreakIterator* staticCursorMovementIterator = initializeIteratorWithRules(kRules);
 #else // PLATFORM(IOS)
     // Use the special Thai character break iterator for all locales
-    static bool createdCursorBreakIterator;
-    static TextBreakIterator* staticCursorBreakIterator;
+    static TextBreakIterator* staticCursorMovementIterator = createSharedIterator(UBRK_CHARACTER, "th");
+#endif // !PLATFORM(IOS)
 
-    if (!string)
+    if (!staticCursorMovementIterator)
         return nullptr;
 
-    if (!createdCursorBreakIterator) {
-        UErrorCode openStatus = U_ZERO_ERROR;
-        staticCursorBreakIterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(UBRK_CHARACTER, "th", 0, 0, &openStatus));
-        createdCursorBreakIterator = true;
-        ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
-    }
-    if (!staticCursorBreakIterator)
-        return nullptr;
+    return setTextForIterator(*staticCursorMovementIterator, StringView(buffer, length));
+}
 
-    UErrorCode setTextStatus = U_ZERO_ERROR;
-    ubrk_setText(reinterpret_cast<UBreakIterator*>(staticCursorBreakIterator), string, length, &setTextStatus);
-    if (U_FAILURE(setTextStatus))
+TextBreakIterator* acquireLineBreakIterator(StringView string, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
+{
+    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(LineBreakIteratorPool::sharedPool().take(locale));
+    if (!iterator)
         return nullptr;
 
-    return staticCursorBreakIterator;
-#endif // !PLATFORM(IOS)
+    return setContextAwareTextForIterator(*iterator, string, priorContext, priorContextLength);
+}
+
+void releaseLineBreakIterator(TextBreakIterator* iterator)
+{
+    ASSERT_ARG(iterator, iterator);
+
+    LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+static TextBreakIterator* nonSharedCharacterBreakIterator;
+
+static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
+{
+#if ENABLE(COMPARE_AND_SWAP)
+    return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
+#else
+    DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
+    MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
+    if (nonSharedCharacterBreakIterator != expected)
+        return false;
+    nonSharedCharacterBreakIterator = newValue;
+    return true;
+#endif
+}
+
+NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
+{
+    m_iterator = nonSharedCharacterBreakIterator;
+
+    bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
+    if (!createdIterator)
+        m_iterator = initializeIterator(UBRK_CHARACTER);
+    if (!m_iterator)
+        return;
+
+    m_iterator = setTextForIterator(*m_iterator, StringView(buffer, length));
+}
+
+NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
+{
+    if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
+        ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
+}
+
+
+// Iterator implemenation.
+
+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));
+}
+
+bool isTextBreak(TextBreakIterator* iterator, int position)
+{
+    return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
+}
+
+bool isWordTextBreak(TextBreakIterator* iterator)
+{
+    int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
+    return ruleStatus != UBRK_WORD_NONE;
 }
 
 }
index d7a74a6..81a025a 100644 (file)
@@ -46,7 +46,7 @@ inline UTextProviderContext uTextProviderContext(const UText* text, int64_t nati
     return UTextProviderContext::PriorContext;
 }
 
-inline void uTextInitialize(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
+inline void initializeContextAwareUTextProvider(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
 {
     text->pFuncs = funcs;
     text->providerProperties = 1 << UTEXT_PROVIDER_STABLE_CHUNKS;
index 13a5056..8db3513 100644 (file)
 
 namespace WebCore {
 
-static inline UTextProviderContext textLatin1GetCurrentContext(const UText* text)
+// Latin1 provider
+
+static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextLatin1NativeLength(UText*);
+static UBool uTextLatin1Access(UText*, int64_t, UBool);
+static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static int64_t uTextLatin1MapOffsetToNative(const UText*);
+static int32_t uTextLatin1MapNativeIndexToUTF16(const UText*, int64_t);
+static void uTextLatin1Close(UText*);
+
+static struct UTextFuncs uTextLatin1Funcs = {
+    sizeof(UTextFuncs),
+    0,
+    0,
+    0,
+    uTextLatin1Clone,
+    uTextLatin1NativeLength,
+    uTextLatin1Access,
+    uTextLatin1Extract,
+    nullptr,
+    nullptr,
+    uTextLatin1MapOffsetToNative,
+    uTextLatin1MapNativeIndexToUTF16,
+    uTextLatin1Close,
+    nullptr,
+    nullptr,
+    nullptr
+};
+
+static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+{
+    ASSERT_UNUSED(deep, !deep);
+
+    if (U_FAILURE(*status))
+        return 0;
+
+    UText* result = utext_setup(destination, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1), status);
+    if (U_FAILURE(*status))
+        return destination;
+    
+    result->providerProperties = source->providerProperties;
+    
+    // Point at the same position, but with an empty buffer.
+    result->chunkNativeStart = source->chunkNativeStart;
+    result->chunkNativeLimit = source->chunkNativeStart;
+    result->nativeIndexingLimit = source->chunkNativeStart;
+    result->chunkOffset = 0;
+    result->context = source->context;
+    result->a = source->a;
+    result->pFuncs = &uTextLatin1Funcs;
+    result->chunkContents = (UChar*)result->pExtra;
+    memset(const_cast<UChar*>(result->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
+
+    return result;
+}
+
+static int64_t uTextLatin1NativeLength(UText* uText)
+{
+    return uText->a;
+}
+
+static UBool uTextLatin1Access(UText* uText, int64_t index, UBool forward)
+{
+    int64_t length = uText->a;
+
+    if (forward) {
+        if (index < uText->chunkNativeLimit && index >= uText->chunkNativeStart) {
+            // Already inside the buffer. Set the new offset.
+            uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
+            return TRUE;
+        }
+        if (index >= length && uText->chunkNativeLimit == length) {
+            // Off the end of the buffer, but we can't get it.
+            uText->chunkOffset = uText->chunkLength;
+            return FALSE;
+        }
+    } else {
+        if (index <= uText->chunkNativeLimit && index > uText->chunkNativeStart) {
+            // Already inside the buffer. Set the new offset.
+            uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
+            return TRUE;
+        }
+        if (!index && !uText->chunkNativeStart) {
+            // Already at the beginning; can't go any farther.
+            uText->chunkOffset = 0;
+            return FALSE;
+        }
+    }
+    
+    if (forward) {
+        uText->chunkNativeStart = index;
+        uText->chunkNativeLimit = uText->chunkNativeStart + UTextWithBufferInlineCapacity;
+        if (uText->chunkNativeLimit > length)
+            uText->chunkNativeLimit = length;
+
+        uText->chunkOffset = 0;
+    } else {
+        uText->chunkNativeLimit = index;
+        if (uText->chunkNativeLimit > length)
+            uText->chunkNativeLimit = length;
+
+        uText->chunkNativeStart = uText->chunkNativeLimit -  UTextWithBufferInlineCapacity;
+        if (uText->chunkNativeStart < 0)
+            uText->chunkNativeStart = 0;
+
+        uText->chunkOffset = uText->chunkLength;
+    }
+    uText->chunkLength = static_cast<int32_t>(uText->chunkNativeLimit - uText->chunkNativeStart);
+
+    StringImpl::copyChars(const_cast<UChar*>(uText->chunkContents), static_cast<const LChar*>(uText->context) + uText->chunkNativeStart, static_cast<unsigned>(uText->chunkLength));
+
+    uText->nativeIndexingLimit = uText->chunkLength;
+
+    return TRUE;
+}
+
+static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, UChar* dest, int32_t destCapacity, UErrorCode* status)
+{
+    int64_t length = uText->a;
+    if (U_FAILURE(*status))
+        return 0;
+
+    if (destCapacity < 0 || (!dest && destCapacity > 0)) {
+        *status = U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+
+    if (start < 0 || start > limit || (limit - start) > INT32_MAX) {
+        *status = U_INDEX_OUTOFBOUNDS_ERROR;
+        return 0;
+    }
+
+    if (start > length)
+        start = length;
+    if (limit > length)
+        limit = length;
+
+    length = limit - start;
+    
+    if (!length)
+        return 0;
+
+    if (destCapacity > 0 && !dest) {
+        int32_t trimmedLength = length;
+        if (trimmedLength > destCapacity)
+            trimmedLength = destCapacity;
+
+        StringImpl::copyChars(dest, static_cast<const LChar*>(uText->context) + start, static_cast<unsigned>(trimmedLength));
+    }
+
+    if (length < destCapacity) {
+        dest[length] = 0;
+        if (*status == U_STRING_NOT_TERMINATED_WARNING)
+            *status = U_ZERO_ERROR;
+    } else if (length == destCapacity)
+        *status = U_STRING_NOT_TERMINATED_WARNING;
+    else
+        *status = U_BUFFER_OVERFLOW_ERROR;
+
+    return length;
+}
+
+static int64_t uTextLatin1MapOffsetToNative(const UText* uText)
+{
+    return uText->chunkNativeStart + uText->chunkOffset;
+}
+
+static int32_t uTextLatin1MapNativeIndexToUTF16(const UText* uText, int64_t nativeIndex)
+{
+    ASSERT_UNUSED(uText, uText->chunkNativeStart >= nativeIndex);
+    ASSERT_UNUSED(uText, nativeIndex < uText->chunkNativeLimit);
+    return nativeIndex;
+}
+
+static void uTextLatin1Close(UText* uText)
+{
+    uText->context = nullptr;
+}
+
+UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status)
+{
+    if (U_FAILURE(*status))
+        return nullptr;
+    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
+        *status = U_ILLEGAL_ARGUMENT_ERROR;
+        return nullptr;
+    }
+    UText* text = utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status);
+    if (U_FAILURE(*status)) {
+        ASSERT(!text);
+        return nullptr;
+    }
+
+    text->context = string;
+    text->a = length;
+    text->pFuncs = &uTextLatin1Funcs;
+    text->chunkContents = (UChar*)text->pExtra;
+    memset(const_cast<UChar*>(text->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
+
+    return text;
+}
+
+
+// Latin1ContextAware provider
+
+static UText* uTextLatin1ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextLatin1ContextAwareNativeLength(UText*);
+static UBool uTextLatin1ContextAwareAccess(UText*, int64_t, UBool);
+static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static void uTextLatin1ContextAwareClose(UText*);
+
+static const struct UTextFuncs textLatin1ContextAwareFuncs = {
+    sizeof(UTextFuncs),
+    0,
+    0,
+    0,
+    uTextLatin1ContextAwareClone,
+    uTextLatin1ContextAwareNativeLength,
+    uTextLatin1ContextAwareAccess,
+    uTextLatin1ContextAwareExtract,
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    uTextLatin1ContextAwareClose,
+    nullptr,
+    nullptr,
+    nullptr
+};
+
+static inline UTextProviderContext textLatin1ContextAwareGetCurrentContext(const UText* text)
 {
     if (!text->chunkContents)
         return UTextProviderContext::NoContext;
     return text->chunkContents == text->pExtra ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
 }
 
-static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textLatin1ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(text->chunkContents == text->pExtra);
     if (forward) {
@@ -63,14 +293,14 @@ static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int
     StringImpl::copyChars(const_cast<UChar*>(text->chunkContents), static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), static_cast<unsigned>(text->chunkLength));
 }
 
-static void textLatin1SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textLatin1ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(!text->chunkContents || text->chunkContents == text->q);
     text->chunkContents = static_cast<const UChar*>(text->pExtra);
-    textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+    textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
 }
 
-static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textLatin1ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(text->chunkContents == text->q);
     ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
@@ -86,58 +316,50 @@ static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64
     text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
 }
 
-static void textLatin1SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textLatin1ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(!text->chunkContents || text->chunkContents == text->pExtra);
     text->chunkContents = static_cast<const UChar*>(text->q);
-    textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+    textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
 }
 
-// -- Begin Latin-1 provider functions --
-
-static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
-static int64_t uTextLatin1NativeLength(UText*); 
-static UBool uTextLatin1Access(UText*, int64_t, UBool); 
-static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*); 
-static void uTextLatin1Close(UText*);
-
-static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+static UText* uTextLatin1ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
 {
     return uTextCloneImpl(destination, source, deep, status);
 }
 
-static int64_t uTextLatin1NativeLength(UText* text)
+static int64_t uTextLatin1ContextAwareNativeLength(UText* text)
 {
     return text->a + text->b;
 }
 
-static UBool uTextLatin1Access(UText* text, int64_t nativeIndex, UBool forward)
+static UBool uTextLatin1ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
 {
     if (!text->context)
         return FALSE;
-    int64_t nativeLength = uTextLatin1NativeLength(text);
+    int64_t nativeLength = uTextLatin1ContextAwareNativeLength(text);
     UBool isAccessible;
     if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
         return isAccessible;
     nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
-    UTextProviderContext currentContext = textLatin1GetCurrentContext(text);
+    UTextProviderContext currentContext = textLatin1ContextAwareGetCurrentContext(text);
     UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
     ASSERT(newContext != UTextProviderContext::NoContext);
     if (newContext == currentContext) {
         if (currentContext == UTextProviderContext::PrimaryContext)
-            textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+            textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
         else
-            textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+            textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
     } else if (newContext == UTextProviderContext::PrimaryContext)
-        textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
+        textLatin1ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
     else {
         ASSERT(newContext == UTextProviderContext::PriorContext);
-        textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
+        textLatin1ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
     }
     return TRUE;
 }
 
-static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
+static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
 {
     // In the present context, this text provider is used only with ICU functions
     // that do not perform an extract operation.
@@ -146,26 +368,12 @@ static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UEr
     return 0;
 }
 
-static void uTextLatin1Close(UText* text)
+static void uTextLatin1ContextAwareClose(UText* text)
 {
-    text->context = 0;
+    text->context = nullptr;
 }
 
-// -- End Latin-1 provider functions --
-
-static const struct UTextFuncs textLatin1Funcs = {
-    sizeof(UTextFuncs),
-    0, 0, 0,
-    uTextLatin1Clone,
-    uTextLatin1NativeLength,
-    uTextLatin1Access,
-    uTextLatin1Extract,
-    0, 0, 0, 0,
-    uTextLatin1Close,
-    0, 0, 0,
-};
-
-UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
+UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
 {
     if (U_FAILURE(*status))
         return 0;
@@ -178,7 +386,8 @@ UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsig
         ASSERT(!text);
         return 0;
     }
-    uTextInitialize(text, &textLatin1Funcs, string, length, priorContext, priorContextLength);
+
+    initializeContextAwareUTextProvider(text, &textLatin1ContextAwareFuncs, string, length, priorContext, priorContextLength);
     return text;
 }
 
index 6f18240..51347c2 100644 (file)
@@ -38,7 +38,8 @@ struct UTextWithBuffer {
     UChar buffer[UTextWithBufferInlineCapacity];
 };
 
-UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
+UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status);
+UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
 
 } // namespace WebCore
 
index 06fa866..7aaac48 100644 (file)
 
 namespace WebCore {
 
-static inline UTextProviderContext textUTF16GetCurrentContext(const UText* text)
+// UTF16ContextAware provider
+
+static UText* uTextUTF16ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextUTF16ContextAwareNativeLength(UText*);
+static UBool uTextUTF16ContextAwareAccess(UText*, int64_t, UBool);
+static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static void uTextUTF16ContextAwareClose(UText*);
+
+static const struct UTextFuncs textUTF16ContextAwareFuncs = {
+    sizeof(UTextFuncs),
+    0,
+    0,
+    0,
+    uTextUTF16ContextAwareClone,
+    uTextUTF16ContextAwareNativeLength,
+    uTextUTF16ContextAwareAccess,
+    uTextUTF16ContextAwareExtract,
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    uTextUTF16ContextAwareClose,
+    nullptr,
+    nullptr,
+    nullptr
+};
+
+static inline UTextProviderContext textUTF16ContextAwareGetCurrentContext(const UText* text)
 {
     if (!text->chunkContents)
         return UTextProviderContext::NoContext;
     return text->chunkContents == text->p ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
 }
 
-static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textUTF16ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(text->chunkContents == text->p);
     ASSERT_UNUSED(forward, forward ? nativeIndex >= text->b : nativeIndex > text->b);
@@ -55,14 +82,14 @@ static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int6
     text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
 }
 
-static void textUTF16SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textUTF16ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(!text->chunkContents || text->chunkContents == text->q);
     text->chunkContents = static_cast<const UChar*>(text->p);
-    textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+    textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
 }
 
-static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textUTF16ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(text->chunkContents == text->q);
     ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
@@ -78,58 +105,50 @@ static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_
     text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
 }
 
-static void textUTF16SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+static void textUTF16ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
 {
     ASSERT(!text->chunkContents || text->chunkContents == text->p);
     text->chunkContents = static_cast<const UChar*>(text->q);
-    textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+    textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
 }
 
-// -- Begin UTF-16 provider functions --
-
-static UText* uTextUTF16Clone(UText*, const UText*, UBool, UErrorCode*);
-static int64_t uTextUTF16NativeLength(UText*);
-static UBool uTextUTF16Access(UText*, int64_t, UBool);
-static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
-static void uTextUTF16Close(UText*);
-
-static UText* uTextUTF16Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+static UText* uTextUTF16ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
 {
     return uTextCloneImpl(destination, source, deep, status);
 }
 
-static inline int64_t uTextUTF16NativeLength(UText* text)
+static inline int64_t uTextUTF16ContextAwareNativeLength(UText* text)
 {
     return text->a + text->b;
 }
 
-static UBool uTextUTF16Access(UText* text, int64_t nativeIndex, UBool forward)
+static UBool uTextUTF16ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
 {
     if (!text->context)
         return FALSE;
-    int64_t nativeLength = uTextUTF16NativeLength(text);
+    int64_t nativeLength = uTextUTF16ContextAwareNativeLength(text);
     UBool isAccessible;
     if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
         return isAccessible;
     nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
-    UTextProviderContext currentContext = textUTF16GetCurrentContext(text);
+    UTextProviderContext currentContext = textUTF16ContextAwareGetCurrentContext(text);
     UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
     ASSERT(newContext != UTextProviderContext::NoContext);
     if (newContext == currentContext) {
         if (currentContext == UTextProviderContext::PrimaryContext)
-            textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+            textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
         else
-            textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+            textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
     } else if (newContext == UTextProviderContext::PrimaryContext)
-        textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
+        textUTF16ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
     else {
         ASSERT(newContext == UTextProviderContext::PriorContext);
-        textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
+        textUTF16ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
     }
     return TRUE;
 }
 
-static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
+static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
 {
     // In the present context, this text provider is used only with ICU functions
     // that do not perform an extract operation.
@@ -138,26 +157,12 @@ static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErr
     return 0;
 }
 
-static void uTextUTF16Close(UText* text)
+static void uTextUTF16ContextAwareClose(UText* text)
 {
-    text->context = 0;
+    text->context = nullptr;
 }
 
-// -- End UTF-16 provider functions --
-
-static const struct UTextFuncs textUTF16Funcs = {
-    sizeof(UTextFuncs),
-    0, 0, 0,
-    uTextUTF16Clone,
-    uTextUTF16NativeLength,
-    uTextUTF16Access,
-    uTextUTF16Extract,
-    0, 0, 0, 0,
-    uTextUTF16Close,
-    0, 0, 0,
-};
-
-UText* uTextOpenUTF16(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
+UText* openUTF16ContextAwareUTextProvider(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
 {
     if (U_FAILURE(*status))
         return 0;
@@ -170,7 +175,8 @@ UText* uTextOpenUTF16(UText* text, const UChar* string, unsigned length, const U
         ASSERT(!text);
         return 0;
     }
-    uTextInitialize(text, &textUTF16Funcs, string, length, priorContext, priorContextLength);
+
+    initializeContextAwareUTextProvider(text, &textUTF16ContextAwareFuncs, string, length, priorContext, priorContextLength);
     return text;
 }
 
index 9d3c92e..564a37a 100644 (file)
@@ -31,7 +31,7 @@
 
 namespace WebCore {
 
-UText* uTextOpenUTF16(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
+UText* openUTF16ContextAwareUTextProvider(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
 
 } // namespace WebCore