Stop reinterpret_casting UBreakIterators to the undefined type TextBreakIterator
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Dec 2016 05:19:32 +0000 (05:19 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Dec 2016 05:19:32 +0000 (05:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165931

Source/WebCore:

Reviewed by Alex Christensen.

No new tests because there is no behavior change.

* dom/CharacterData.cpp:
(WebCore::CharacterData::parserAppendData):
* editing/TextCheckingHelper.cpp:
(WebCore::findMisspellings):
* editing/VisibleUnits.cpp:
(WebCore::wordBreakIteratorForMinOffsetBoundary):
(WebCore::wordBreakIteratorForMaxOffsetBoundary):
(WebCore::isLogicalStartOfWord):
(WebCore::islogicalEndOfWord):
(WebCore::visualWordPosition):
(WebCore::startSentenceBoundary):
(WebCore::endSentenceBoundary):
(WebCore::previousSentencePositionBoundary):
(WebCore::nextSentencePositionBoundary):
* html/HTMLInputElement.cpp:
* html/HTMLTextAreaElement.cpp:
* html/InputType.cpp:
* html/TextFieldInputType.cpp:
* html/TextInputType.cpp:
* platform/graphics/StringTruncator.cpp:
(WebCore::textBreakAtOrPreceding):
(WebCore::boundedTextBreakFollowing):
(WebCore::rightClipToWordBuffer):
* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::offsetForPosition):
* platform/text/TextBoundaries.cpp:
(WebCore::findNextWordFromIndex):
(WebCore::findWordBoundary):
(WebCore::findEndWordBoundary):
* platform/text/mac/TextBoundaries.mm:
(WebCore::findNextWordFromIndex):
* rendering/BreakLines.h:
(WebCore::nextBreakablePositionNonLoosely):
(WebCore::nextBreakablePositionLoosely):
* rendering/RenderBlock.cpp:
* rendering/RenderText.cpp:
(WebCore::makeCapitalized):
(WebCore::RenderText::previousOffset):
(WebCore::RenderText::previousOffsetForBackwardDeletion):
(WebCore::RenderText::nextOffset):
* rendering/SimpleLineLayoutTextFragmentIterator.h:
* rendering/line/LineBreaker.h:

Source/WebKit/ios:

Reviewed by Alex Christensen.

* Misc/WebUIKitSupport.mm:

Source/WTF:

We have a class declaration for TextBreakIterator but no definition for it. When we
create an ICU UBreakIterator, we immediately reinterpret_cast it to this undefined
type, and pass it around our code inside WebCore. Then, whenever we want to actually
use this iterator, we reinterpret_cast it back to UBreakIterator. This is likely due
to some ports historically implementing breaking interators on top of other libraries
other than ICU; however, now, all ports use ICU. Because this internal type is not
helpful and just adds confusion, we should just call our breaking iterators what
they are: UBreakIterators.

This patch is a mechanical replacement of TextBreakIterator to UBreakIterator and
removes the functions we were calling which pass through directly to ubrk_*().

Reviewed by Alex Christensen.

* wtf/text/LineBreakIteratorPoolICU.h:
(WTF::LineBreakIteratorPool::take):
(WTF::LineBreakIteratorPool::put):
* wtf/text/StringView.cpp:
(WTF::StringView::GraphemeClusters::Iterator::Impl::computeIndexEnd):
* wtf/text/TextBreakIterator.cpp:
(WTF::initializeIterator):
(WTF::initializeIteratorWithRules):
(WTF::setTextForIterator):
(WTF::setContextAwareTextForIterator):
(WTF::wordBreakIterator):
(WTF::sentenceBreakIterator):
(WTF::cursorMovementIterator):
(WTF::acquireLineBreakIterator):
(WTF::releaseLineBreakIterator):
(WTF::openLineBreakIterator):
(WTF::closeLineBreakIterator):
(WTF::getNonSharedCharacterBreakIterator):
(WTF::cacheNonSharedCharacterBreakIterator):
(WTF::isWordTextBreak):
(WTF::numGraphemeClusters):
(WTF::numCharactersInGraphemeClusters):
(WTF::textBreakFirst): Deleted.
(WTF::textBreakLast): Deleted.
(WTF::textBreakNext): Deleted.
(WTF::textBreakPrevious): Deleted.
(WTF::textBreakPreceding): Deleted.
(WTF::textBreakFollowing): Deleted.
(WTF::textBreakCurrent): Deleted.
(WTF::isTextBreak): Deleted.
* wtf/text/TextBreakIterator.h:
(WTF::LazyLineBreakIterator::lastCharacter):
(WTF::LazyLineBreakIterator::secondToLastCharacter):
(WTF::LazyLineBreakIterator::setPriorContext):
(WTF::LazyLineBreakIterator::updatePriorContext):
(WTF::LazyLineBreakIterator::resetPriorContext):
(WTF::LazyLineBreakIterator::priorContextLength):
(WTF::LazyLineBreakIterator::get):
(WTF::NonSharedCharacterBreakIterator::operator UBreakIterator*):
(WTF::NonSharedCharacterBreakIterator::operator TextBreakIterator*): Deleted.

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

29 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WTF/wtf/text/LineBreakIteratorPoolICU.h
Source/WTF/wtf/text/StringView.cpp
Source/WTF/wtf/text/TextBreakIterator.cpp
Source/WTF/wtf/text/TextBreakIterator.h
Source/WebCore/ChangeLog
Source/WebCore/dom/CharacterData.cpp
Source/WebCore/editing/TextCheckingHelper.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/TextInputType.cpp
Source/WebCore/platform/graphics/StringTruncator.cpp
Source/WebCore/platform/graphics/mac/ComplexTextController.cpp
Source/WebCore/platform/text/TextBoundaries.cpp
Source/WebCore/platform/text/enchant/TextCheckerEnchant.cpp
Source/WebCore/platform/text/mac/TextBoundaries.mm
Source/WebCore/rendering/BreakLines.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h
Source/WebCore/rendering/line/LineBreaker.h
Source/WebKit/ios/ChangeLog
Source/WebKit/ios/Misc/WebUIKitSupport.mm
Source/WebKit2/UIProcess/efl/TextCheckerEfl.cpp
Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp

index 5015677..b616dfa 100644 (file)
@@ -1,5 +1,65 @@
 2016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
+        Stop reinterpret_casting UBreakIterators to the undefined type TextBreakIterator
+        https://bugs.webkit.org/show_bug.cgi?id=165931
+
+        We have a class declaration for TextBreakIterator but no definition for it. When we
+        create an ICU UBreakIterator, we immediately reinterpret_cast it to this undefined
+        type, and pass it around our code inside WebCore. Then, whenever we want to actually
+        use this iterator, we reinterpret_cast it back to UBreakIterator. This is likely due
+        to some ports historically implementing breaking interators on top of other libraries
+        other than ICU; however, now, all ports use ICU. Because this internal type is not
+        helpful and just adds confusion, we should just call our breaking iterators what
+        they are: UBreakIterators.
+
+        This patch is a mechanical replacement of TextBreakIterator to UBreakIterator and
+        removes the functions we were calling which pass through directly to ubrk_*().
+
+        Reviewed by Alex Christensen.
+
+        * wtf/text/LineBreakIteratorPoolICU.h:
+        (WTF::LineBreakIteratorPool::take):
+        (WTF::LineBreakIteratorPool::put):
+        * wtf/text/StringView.cpp:
+        (WTF::StringView::GraphemeClusters::Iterator::Impl::computeIndexEnd):
+        * wtf/text/TextBreakIterator.cpp:
+        (WTF::initializeIterator):
+        (WTF::initializeIteratorWithRules):
+        (WTF::setTextForIterator):
+        (WTF::setContextAwareTextForIterator):
+        (WTF::wordBreakIterator):
+        (WTF::sentenceBreakIterator):
+        (WTF::cursorMovementIterator):
+        (WTF::acquireLineBreakIterator):
+        (WTF::releaseLineBreakIterator):
+        (WTF::openLineBreakIterator):
+        (WTF::closeLineBreakIterator):
+        (WTF::getNonSharedCharacterBreakIterator):
+        (WTF::cacheNonSharedCharacterBreakIterator):
+        (WTF::isWordTextBreak):
+        (WTF::numGraphemeClusters):
+        (WTF::numCharactersInGraphemeClusters):
+        (WTF::textBreakFirst): Deleted.
+        (WTF::textBreakLast): Deleted.
+        (WTF::textBreakNext): Deleted.
+        (WTF::textBreakPrevious): Deleted.
+        (WTF::textBreakPreceding): Deleted.
+        (WTF::textBreakFollowing): Deleted.
+        (WTF::textBreakCurrent): Deleted.
+        (WTF::isTextBreak): Deleted.
+        * wtf/text/TextBreakIterator.h:
+        (WTF::LazyLineBreakIterator::lastCharacter):
+        (WTF::LazyLineBreakIterator::secondToLastCharacter):
+        (WTF::LazyLineBreakIterator::setPriorContext):
+        (WTF::LazyLineBreakIterator::updatePriorContext):
+        (WTF::LazyLineBreakIterator::resetPriorContext):
+        (WTF::LazyLineBreakIterator::priorContextLength):
+        (WTF::LazyLineBreakIterator::get):
+        (WTF::NonSharedCharacterBreakIterator::operator UBreakIterator*):
+        (WTF::NonSharedCharacterBreakIterator::operator TextBreakIterator*): Deleted.
+
+2016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
         Sort Xcode project files
         https://bugs.webkit.org/show_bug.cgi?id=165937
 
index 6f92759..6409a41 100644 (file)
 #endif
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101201 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-#define HAVE_TOUCH_BAR 1
+#define HAVE_TOUCH_BAR 0
 #define HAVE_ADVANCED_SPELL_CHECKING 1
 
 #if defined(__LP64__)
index 151eadf..c0e0e57 100644 (file)
@@ -60,11 +60,11 @@ public:
         return locale;
     }
 
-    TextBreakIterator* take(const AtomicString& locale, LineBreakIteratorMode mode, bool isCJK)
+    UBreakIterator* take(const AtomicString& locale, LineBreakIteratorMode mode, bool isCJK)
     {
         auto localeWithOptionalBreakKeyword = makeLocaleWithBreakKeyword(locale, mode);
 
-        TextBreakIterator* iterator = nullptr;
+        UBreakIterator* iterator = nullptr;
         for (size_t i = 0; i < m_pool.size(); ++i) {
             if (m_pool[i].first == localeWithOptionalBreakKeyword) {
                 iterator = m_pool[i].second;
@@ -84,7 +84,7 @@ public:
         return iterator;
     }
 
-    void put(TextBreakIterator* iterator)
+    void put(UBreakIterator* iterator)
     {
         ASSERT(m_vendedIterators.contains(iterator));
         if (m_pool.size() == capacity) {
@@ -97,8 +97,8 @@ public:
 private:
     static constexpr size_t capacity = 4;
 
-    Vector<std::pair<AtomicString, TextBreakIterator*>, capacity> m_pool;
-    HashMap<TextBreakIterator*, AtomicString> m_vendedIterators;
+    Vector<std::pair<AtomicString, UBreakIterator*>, capacity> m_pool;
+    HashMap<UBreakIterator*, AtomicString> m_vendedIterators;
 
     friend WTF::ThreadSpecific<LineBreakIteratorPool>::operator LineBreakIteratorPool*();
 };
index 5965d69..d78562e 100644 (file)
@@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "StringView.h"
 
 #include <mutex>
+#include <unicode/ubrk.h>
 #include <wtf/HashMap.h>
 #include <wtf/Lock.h>
 #include <wtf/NeverDestroyed.h>
@@ -131,7 +132,7 @@ public:
             return 0;
         if (m_index == m_stringView.length())
             return m_index;
-        return textBreakFollowing(m_iterator.value(), m_index);
+        return ubrk_following(m_iterator.value(), m_index);
     }
 
 private:
index 05a5195..1da0ab6 100644 (file)
@@ -38,23 +38,23 @@ namespace WTF {
 
 // Iterator initialization
 
-static TextBreakIterator* initializeIterator(UBreakIteratorType type, const char* locale = currentTextBreakLocaleID())
+static UBreakIterator* initializeIterator(UBreakIteratorType type, const char* locale = currentTextBreakLocaleID())
 {
     UErrorCode openStatus = U_ZERO_ERROR;
-    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, locale, 0, 0, &openStatus));
+    UBreakIterator* iterator = 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;
 }
 
 #if !PLATFORM(IOS)
 
-static TextBreakIterator* initializeIteratorWithRules(const char* breakRules)
+static UBreakIterator* initializeIteratorWithRules(const char* breakRules)
 {
     UParseError parseStatus;
     UErrorCode openStatus = U_ZERO_ERROR;
     unsigned length = strlen(breakRules);
     auto upconvertedCharacters = StringView(reinterpret_cast<const LChar*>(breakRules), length).upconvertedCharacters();
-    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(upconvertedCharacters, length, 0, 0, &parseStatus, &openStatus));
+    UBreakIterator* iterator = ubrk_openRules(upconvertedCharacters, 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;
 }
@@ -64,7 +64,7 @@ static TextBreakIterator* initializeIteratorWithRules(const char* breakRules)
 
 // Iterator text setting
 
-static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, StringView string)
+static UBreakIterator* setTextForIterator(UBreakIterator& iterator, StringView string)
 {
     if (string.is8Bit()) {
         UTextWithBuffer textLocal;
@@ -80,7 +80,7 @@ static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, String
         }
 
         UErrorCode setTextStatus = U_ZERO_ERROR;
-        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        ubrk_setUText(&iterator, text, &setTextStatus);
         if (U_FAILURE(setTextStatus)) {
             LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
             return nullptr;
@@ -89,7 +89,7 @@ static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, String
         utext_close(text);
     } else {
         UErrorCode setTextStatus = U_ZERO_ERROR;
-        ubrk_setText(reinterpret_cast<UBreakIterator*>(&iterator), string.characters16(), string.length(), &setTextStatus);
+        ubrk_setText(&iterator, string.characters16(), string.length(), &setTextStatus);
         if (U_FAILURE(setTextStatus))
             return nullptr;
     }
@@ -97,7 +97,7 @@ static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, String
     return &iterator;
 }
 
-static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iterator, StringView string, const UChar* priorContext, unsigned priorContextLength)
+static UBreakIterator* setContextAwareTextForIterator(UBreakIterator& iterator, StringView string, const UChar* priorContext, unsigned priorContextLength)
 {
     if (string.is8Bit()) {
         UTextWithBuffer textLocal;
@@ -113,7 +113,7 @@ static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iter
         }
 
         UErrorCode setTextStatus = U_ZERO_ERROR;
-        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        ubrk_setUText(&iterator, text, &setTextStatus);
         if (U_FAILURE(setTextStatus)) {
             LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
             return nullptr;
@@ -131,7 +131,7 @@ static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iter
         }
 
         UErrorCode setTextStatus = U_ZERO_ERROR;
-        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+        ubrk_setUText(&iterator, text, &setTextStatus);
         if (U_FAILURE(setTextStatus)) {
             LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
             return nullptr;
@@ -146,25 +146,25 @@ static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iter
 
 // Static iterators
 
-TextBreakIterator* wordBreakIterator(StringView string)
+UBreakIterator* wordBreakIterator(StringView string)
 {
-    static TextBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
+    static UBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
     if (!staticWordBreakIterator)
         return nullptr;
 
     return setTextForIterator(*staticWordBreakIterator, string);
 }
 
-TextBreakIterator* sentenceBreakIterator(StringView string)
+UBreakIterator* sentenceBreakIterator(StringView string)
 {
-    static TextBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
+    static UBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
     if (!staticSentenceBreakIterator)
         return nullptr;
 
     return setTextForIterator(*staticSentenceBreakIterator, string);
 }
 
-TextBreakIterator* cursorMovementIterator(StringView string)
+UBreakIterator* cursorMovementIterator(StringView string)
 {
 #if !PLATFORM(IOS)
     // This rule set is based on character-break iterator rules of ICU 57
@@ -291,10 +291,10 @@ TextBreakIterator* cursorMovementIterator(StringView string)
         "!!safe_reverse;"
         "!!safe_forward;";
 #endif
-    static TextBreakIterator* staticCursorMovementIterator = initializeIteratorWithRules(kRules);
+    static UBreakIterator* staticCursorMovementIterator = initializeIteratorWithRules(kRules);
 #else // PLATFORM(IOS)
     // Use the special Thai character break iterator for all locales
-    static TextBreakIterator* staticCursorMovementIterator = initializeIterator(UBRK_CHARACTER, "th");
+    static UBreakIterator* staticCursorMovementIterator = initializeIterator(UBRK_CHARACTER, "th");
 #endif // !PLATFORM(IOS)
 
     if (!staticCursorMovementIterator)
@@ -303,16 +303,16 @@ TextBreakIterator* cursorMovementIterator(StringView string)
     return setTextForIterator(*staticCursorMovementIterator, string);
 }
 
-TextBreakIterator* acquireLineBreakIterator(StringView string, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength, LineBreakIteratorMode mode, bool isCJK)
+UBreakIterator* acquireLineBreakIterator(StringView string, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength, LineBreakIteratorMode mode, bool isCJK)
 {
-    TextBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale, mode, isCJK);
+    UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale, mode, isCJK);
     if (!iterator)
         return nullptr;
 
     return setContextAwareTextForIterator(*iterator, string, priorContext, priorContextLength);
 }
 
-void releaseLineBreakIterator(TextBreakIterator* iterator)
+void releaseLineBreakIterator(UBreakIterator* iterator)
 {
     ASSERT_ARG(iterator, iterator);
 
@@ -780,7 +780,7 @@ bool isCJKLocale(const AtomicString& locale)
     return false;
 }
 
-TextBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIteratorMode mode, bool isCJK)
+UBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIteratorMode mode, bool isCJK)
 {
     UBreakIterator* ubrkIter;
     UErrorCode openStatus = U_ZERO_ERROR;
@@ -804,30 +804,30 @@ TextBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIt
         return nullptr;
     }
 
-    return reinterpret_cast<TextBreakIterator*>(ubrkIter);
+    return ubrkIter;
 }
 
-void closeLineBreakIterator(TextBreakIterator*& iterator)
+void closeLineBreakIterator(UBreakIterator*& iterator)
 {
-    UBreakIterator* ubrkIter = reinterpret_cast<UBreakIterator*>(iterator);
+    UBreakIterator* ubrkIter = iterator;
     ASSERT(ubrkIter);
     ubrk_close(ubrkIter);
     iterator = nullptr;
 }
 
-static std::atomic<TextBreakIterator*> nonSharedCharacterBreakIterator = ATOMIC_VAR_INIT(nullptr);
+static std::atomic<UBreakIterator*> nonSharedCharacterBreakIterator = ATOMIC_VAR_INIT(nullptr);
 
-static inline TextBreakIterator* getNonSharedCharacterBreakIterator()
+static inline UBreakIterator* getNonSharedCharacterBreakIterator()
 {
     if (auto *res = nonSharedCharacterBreakIterator.exchange(nullptr, std::memory_order_acquire))
         return res;
     return initializeIterator(UBRK_CHARACTER);
 }
 
-static inline void cacheNonSharedCharacterBreakIterator(TextBreakIterator* cacheMe)
+static inline void cacheNonSharedCharacterBreakIterator(UBreakIterator* cacheMe)
 {
     if (auto *old = nonSharedCharacterBreakIterator.exchange(cacheMe, std::memory_order_release))
-        ubrk_close(reinterpret_cast<UBreakIterator*>(old));
+        ubrk_close(old);
 }
 
 NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(StringView string)
@@ -848,52 +848,11 @@ NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(NonSharedCharac
     std::swap(m_iterator, other.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)
+bool isWordTextBreak(UBreakIterator* iterator)
 {
-    int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
+    int ruleStatus = ubrk_getRuleStatus(iterator);
     return ruleStatus != UBRK_WORD_NONE;
 }
 
@@ -920,7 +879,7 @@ unsigned numGraphemeClusters(StringView string)
     }
 
     unsigned numGraphemeClusters = 0;
-    while (textBreakNext(iterator) != TextBreakDone)
+    while (ubrk_next(iterator) != UBRK_DONE)
         ++numGraphemeClusters;
     return numGraphemeClusters;
 }
@@ -948,10 +907,10 @@ unsigned numCharactersInGraphemeClusters(StringView string, unsigned numGrapheme
     }
 
     for (unsigned i = 0; i < numGraphemeClusters; ++i) {
-        if (textBreakNext(iterator) == TextBreakDone)
+        if (ubrk_next(iterator) == UBRK_DONE)
             return stringLength;
     }
-    return textBreakCurrent(iterator);
+    return ubrk_current(iterator);
 }
 
 } // namespace WTF
index 8afb558..bcf44c0 100644 (file)
@@ -25,8 +25,6 @@
 
 namespace WTF {
 
-class TextBreakIterator;
-
 // Note: The returned iterator is good only until you get another iterator, with the exception of acquireLineBreakIterator.
 
 enum class LineBreakIteratorMode { Default, Loose, Normal, Strict };
@@ -35,27 +33,17 @@ enum class LineBreakIteratorMode { Default, Loose, Normal, Strict };
 // platform UI conventions. One notable example where this can be different
 // from character break iterator is Thai prepend characters, see bug 24342.
 // Use this for insertion point and selection manipulations.
-WTF_EXPORT_PRIVATE TextBreakIterator* cursorMovementIterator(StringView);
-
-WTF_EXPORT_PRIVATE TextBreakIterator* wordBreakIterator(StringView);
-WTF_EXPORT_PRIVATE TextBreakIterator* sentenceBreakIterator(StringView);
+WTF_EXPORT_PRIVATE UBreakIterator* cursorMovementIterator(StringView);
 
-WTF_EXPORT_PRIVATE TextBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength, LineBreakIteratorMode, bool isCJK);
-WTF_EXPORT_PRIVATE void releaseLineBreakIterator(TextBreakIterator*);
-TextBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIteratorMode, bool isCJK);
-void closeLineBreakIterator(TextBreakIterator*&);
+WTF_EXPORT_PRIVATE UBreakIterator* wordBreakIterator(StringView);
+WTF_EXPORT_PRIVATE UBreakIterator* sentenceBreakIterator(StringView);
 
-WTF_EXPORT_PRIVATE int textBreakFirst(TextBreakIterator*);
-WTF_EXPORT_PRIVATE int textBreakLast(TextBreakIterator*);
-WTF_EXPORT_PRIVATE int textBreakNext(TextBreakIterator*);
-WTF_EXPORT_PRIVATE int textBreakPrevious(TextBreakIterator*);
-WTF_EXPORT_PRIVATE int textBreakCurrent(TextBreakIterator*);
-WTF_EXPORT_PRIVATE int textBreakPreceding(TextBreakIterator*, int);
-WTF_EXPORT_PRIVATE int textBreakFollowing(TextBreakIterator*, int);
-WTF_EXPORT_PRIVATE bool isTextBreak(TextBreakIterator*, int);
-WTF_EXPORT_PRIVATE bool isWordTextBreak(TextBreakIterator*);
+WTF_EXPORT_PRIVATE UBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength, LineBreakIteratorMode, bool isCJK);
+WTF_EXPORT_PRIVATE void releaseLineBreakIterator(UBreakIterator*);
+UBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIteratorMode, bool isCJK);
+void closeLineBreakIterator(UBreakIterator*&);
 
-constexpr int TextBreakDone = -1;
+WTF_EXPORT_PRIVATE bool isWordTextBreak(UBreakIterator*);
 
 WTF_EXPORT_PRIVATE bool isCJKLocale(const AtomicString&);
 
@@ -86,33 +74,33 @@ public:
 
     UChar lastCharacter() const
     {
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         return m_priorContext[1];
     }
 
     UChar secondToLastCharacter() const
     {
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         return m_priorContext[0];
     }
 
     void setPriorContext(UChar last, UChar secondToLast)
     {
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         m_priorContext[0] = secondToLast;
         m_priorContext[1] = last;
     }
 
     void updatePriorContext(UChar last)
     {
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         m_priorContext[0] = m_priorContext[1];
         m_priorContext[1] = last;
     }
 
     void resetPriorContext()
     {
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         m_priorContext[0] = 0;
         m_priorContext[1] = 0;
     }
@@ -120,7 +108,7 @@ public:
     unsigned priorContextLength() const
     {
         unsigned priorContextLength = 0;
-        COMPILE_ASSERT(WTF_ARRAY_LENGTH(m_priorContext) == 2, TextBreakIterator_unexpected_prior_context_length);
+        static_assert(WTF_ARRAY_LENGTH(m_priorContext) == 2, "UBreakIterator unexpected prior context length");
         if (m_priorContext[1]) {
             ++priorContextLength;
             if (m_priorContext[0])
@@ -132,7 +120,7 @@ public:
     // Obtain text break iterator, possibly previously cached, where this iterator is (or has been)
     // initialized to use the previously stored string as the primary breaking context and using
     // previously stored prior context if non-empty.
-    TextBreakIterator* get(unsigned priorContextLength)
+    UBreakIterator* get(unsigned priorContextLength)
     {
         ASSERT(priorContextLength <= priorContextCapacity);
         const UChar* priorContext = priorContextLength ? &m_priorContext[priorContextCapacity - priorContextLength] : 0;
@@ -164,7 +152,7 @@ private:
     static constexpr unsigned priorContextCapacity = 2;
     StringView m_stringView;
     AtomicString m_locale;
-    TextBreakIterator* m_iterator { nullptr };
+    UBreakIterator* m_iterator { nullptr };
     const UChar* m_cachedPriorContext { nullptr };
     LineBreakIteratorMode m_mode { LineBreakIteratorMode::Default };
     unsigned m_cachedPriorContextLength { 0 };
@@ -185,10 +173,10 @@ public:
 
     NonSharedCharacterBreakIterator(NonSharedCharacterBreakIterator&&);
 
-    operator TextBreakIterator*() const { return m_iterator; }
+    operator UBreakIterator*() const { return m_iterator; }
 
 private:
-    TextBreakIterator* m_iterator;
+    UBreakIterator* m_iterator;
 };
 
 // Counts the number of grapheme clusters. A surrogate pair or a sequence
@@ -205,5 +193,4 @@ WTF_EXPORT_PRIVATE unsigned numCharactersInGraphemeClusters(StringView, unsigned
 using WTF::LazyLineBreakIterator;
 using WTF::LineBreakIteratorMode;
 using WTF::NonSharedCharacterBreakIterator;
-using WTF::TextBreakDone;
-using WTF::TextBreakIterator;
+using WTF::isWordTextBreak;
index b2cf245..f8b83f5 100644 (file)
@@ -1,3 +1,55 @@
+2016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Stop reinterpret_casting UBreakIterators to the undefined type TextBreakIterator
+        https://bugs.webkit.org/show_bug.cgi?id=165931
+
+        Reviewed by Alex Christensen.
+
+        No new tests because there is no behavior change.
+
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::parserAppendData):
+        * editing/TextCheckingHelper.cpp:
+        (WebCore::findMisspellings):
+        * editing/VisibleUnits.cpp:
+        (WebCore::wordBreakIteratorForMinOffsetBoundary):
+        (WebCore::wordBreakIteratorForMaxOffsetBoundary):
+        (WebCore::isLogicalStartOfWord):
+        (WebCore::islogicalEndOfWord):
+        (WebCore::visualWordPosition):
+        (WebCore::startSentenceBoundary):
+        (WebCore::endSentenceBoundary):
+        (WebCore::previousSentencePositionBoundary):
+        (WebCore::nextSentencePositionBoundary):
+        * html/HTMLInputElement.cpp:
+        * html/HTMLTextAreaElement.cpp:
+        * html/InputType.cpp:
+        * html/TextFieldInputType.cpp:
+        * html/TextInputType.cpp:
+        * platform/graphics/StringTruncator.cpp:
+        (WebCore::textBreakAtOrPreceding):
+        (WebCore::boundedTextBreakFollowing):
+        (WebCore::rightClipToWordBuffer):
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::offsetForPosition):
+        * platform/text/TextBoundaries.cpp:
+        (WebCore::findNextWordFromIndex):
+        (WebCore::findWordBoundary):
+        (WebCore::findEndWordBoundary):
+        * platform/text/mac/TextBoundaries.mm:
+        (WebCore::findNextWordFromIndex):
+        * rendering/BreakLines.h:
+        (WebCore::nextBreakablePositionNonLoosely):
+        (WebCore::nextBreakablePositionLoosely):
+        * rendering/RenderBlock.cpp:
+        * rendering/RenderText.cpp:
+        (WebCore::makeCapitalized):
+        (WebCore::RenderText::previousOffset):
+        (WebCore::RenderText::previousOffsetForBackwardDeletion):
+        (WebCore::RenderText::nextOffset):
+        * rendering/SimpleLineLayoutTextFragmentIterator.h:
+        * rendering/line/LineBreaker.h:
+
 2016-12-15  Darin Adler  <darin@apple.com>
 
         Use asString instead of toWTFString, toString, or getString when we already checked isString
index 97fa45f..4fd4cb8 100644 (file)
@@ -33,8 +33,8 @@
 #include "ProcessingInstruction.h"
 #include "RenderText.h"
 #include "StyleInheritedData.h"
+#include <unicode/ubrk.h>
 #include <wtf/Ref.h>
-#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
@@ -86,8 +86,8 @@ unsigned CharacterData::parserAppendData(const String& string, unsigned offset,
     // We need at least two characters look-ahead to account for UTF-16 surrogates.
     if (characterLengthLimit < characterLength) {
         NonSharedCharacterBreakIterator it(StringView(string).substring(offset, (characterLengthLimit + 2 > characterLength) ? characterLength : characterLengthLimit + 2));
-        if (!isTextBreak(it, characterLengthLimit))
-            characterLengthLimit = textBreakPreceding(it, characterLengthLimit);
+        if (!ubrk_isBoundary(it, characterLengthLimit))
+            characterLengthLimit = ubrk_preceding(it, characterLengthLimit);
     }
 
     if (!characterLengthLimit)
index 0e5dcd6..379d7d2 100644 (file)
 #include "Frame.h"
 #include "FrameSelection.h"
 #include "Settings.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextCheckerClient.h"
 #include "TextIterator.h"
 #include "VisiblePosition.h"
 #include "VisibleUnits.h"
+#include <unicode/ubrk.h>
 #include <wtf/text/StringView.h>
+#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
@@ -76,11 +77,11 @@ static void findGrammaticalErrors(TextCheckerClient& client, StringView text, Ve
 
 static void findMisspellings(TextCheckerClient& client, StringView text, Vector<TextCheckingResult>& results)
 {
-    TextBreakIterator* iterator = wordBreakIterator(text);
+    UBreakIterator* iterator = wordBreakIterator(text);
     if (!iterator)
         return;
-    for (int wordStart = textBreakCurrent(iterator); wordStart >= 0; ) {
-        int wordEnd = textBreakNext(iterator);
+    for (int wordStart = ubrk_current(iterator); wordStart >= 0; ) {
+        int wordEnd = ubrk_next(iterator);
         if (wordEnd < 0)
             break;
 
index 83cae4c..153f5ea 100644 (file)
 #include "RenderedPosition.h"
 #include "Text.h"
 #include "TextBoundaries.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextIterator.h"
 #include "VisibleSelection.h"
+#include <unicode/ubrk.h>
+#include <wtf/text/TextBreakIterator.h>
 #include "htmlediting.h"
 
 namespace WebCore {
@@ -285,7 +286,7 @@ static const InlineBox* logicallyNextBox(const VisiblePosition& visiblePosition,
     return 0;
 }
 
-static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
+static UBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
     int& previousBoxLength, bool& previousBoxInDifferentBlock, Vector<UChar, 1024>& string, CachedLogicallyOrderedLeafBoxes& leafBoxes)
 {
     previousBoxInDifferentBlock = false;
@@ -305,7 +306,7 @@ static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePos
     return wordBreakIterator(StringView(string.data(), string.size()));
 }
 
-static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
+static UBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox,
     bool& nextBoxInDifferentBlock, Vector<UChar, 1024>& string, CachedLogicallyOrderedLeafBoxes& leafBoxes)
 {
     nextBoxInDifferentBlock = false;
@@ -323,20 +324,20 @@ static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePos
     return wordBreakIterator(StringView(string.data(), string.size()));
 }
 
-static bool isLogicalStartOfWord(TextBreakIterator* iter, int position, bool hardLineBreak)
+static bool isLogicalStartOfWord(UBreakIterator* iter, int position, bool hardLineBreak)
 {
-    bool boundary = hardLineBreak ? true : isTextBreak(iter, position);
+    bool boundary = hardLineBreak ? true : ubrk_isBoundary(iter, position);
     if (!boundary)
         return false;
 
-    textBreakFollowing(iter, position);
+    ubrk_following(iter, position);
     // isWordTextBreak returns true after moving across a word and false after moving across a punctuation/space.
     return isWordTextBreak(iter);
 }
 
-static bool islogicalEndOfWord(TextBreakIterator* iter, int position, bool hardLineBreak)
+static bool islogicalEndOfWord(UBreakIterator* iter, int position, bool hardLineBreak)
 {
-    bool boundary = isTextBreak(iter, position);
+    bool boundary = ubrk_isBoundary(iter, position);
     return (hardLineBreak || boundary) && isWordTextBreak(iter);
 }
 
@@ -351,7 +352,7 @@ static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
     TextDirection blockDirection = directionOfEnclosingBlock(visiblePosition.deepEquivalent());
     InlineBox* previouslyVisitedBox = nullptr;
     VisiblePosition current = visiblePosition;
-    TextBreakIterator* iter = nullptr;
+    UBreakIterator* iter = nullptr;
 
     CachedLogicallyOrderedLeafBoxes leafBoxes;
     Vector<UChar, 1024> string;
@@ -390,7 +391,7 @@ static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
         if (!iter)
             break;
 
-        textBreakFirst(iter);
+        ubrk_first(iter);
         int offsetInIterator = offsetInBox - textBox.start() + previousBoxLength;
 
         bool isWordBreak;
@@ -1109,7 +1110,7 @@ VisiblePosition nextLinePosition(const VisiblePosition& visiblePosition, int lin
 unsigned startSentenceBoundary(StringView text, unsigned, BoundarySearchContextAvailability, bool&)
 {
     // FIXME: The following function can return -1; we don't handle that.
-    return textBreakPreceding(sentenceBreakIterator(text), text.length());
+    return ubrk_preceding(sentenceBreakIterator(text), text.length());
 }
 
 VisiblePosition startOfSentence(const VisiblePosition& position)
@@ -1119,7 +1120,7 @@ VisiblePosition startOfSentence(const VisiblePosition& position)
 
 unsigned endSentenceBoundary(StringView text, unsigned, BoundarySearchContextAvailability, bool&)
 {
-    return textBreakNext(sentenceBreakIterator(text));
+    return ubrk_next(sentenceBreakIterator(text));
 }
 
 VisiblePosition endOfSentence(const VisiblePosition& position)
@@ -1132,7 +1133,7 @@ static unsigned previousSentencePositionBoundary(StringView text, unsigned, Boun
 {
     // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's not right.
     // FIXME: The following function can return -1; we don't handle that.
-    return textBreakPreceding(sentenceBreakIterator(text), text.length());
+    return ubrk_preceding(sentenceBreakIterator(text), text.length());
 }
 
 VisiblePosition previousSentencePosition(const VisiblePosition& position)
@@ -1144,7 +1145,7 @@ static unsigned nextSentencePositionBoundary(StringView text, unsigned, Boundary
 {
     // FIXME: This is identical to endSentenceBoundary.
     // That isn't right. This function needs to move to the equivalent position in the following sentence.
-    return textBreakFollowing(sentenceBreakIterator(text), 0);
+    return ubrk_following(sentenceBreakIterator(text), 0);
 }
 
 VisiblePosition nextSentencePosition(const VisiblePosition& position)
index 6c1d8b3..d43d4ef 100644 (file)
@@ -62,7 +62,6 @@
 #include "StyleResolver.h"
 #include <wtf/MathExtras.h>
 #include <wtf/Ref.h>
-#include <wtf/text/TextBreakIterator.h>
 
 #if ENABLE(TOUCH_EVENTS)
 #include "TouchEvent.h"
index c41bc8f..35a42b3 100644 (file)
@@ -44,7 +44,6 @@
 #include "RenderTextControlMultiLine.h"
 #include "ShadowRoot.h"
 #include "Text.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextControlInnerElements.h"
 #include "TextIterator.h"
 #include "TextNodeTraversal.h"
index 3d47e46..f6a6bbc 100644 (file)
@@ -69,7 +69,6 @@
 #include "ShadowRoot.h"
 #include "SubmitInputType.h"
 #include "TelephoneInputType.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextInputType.h"
 #include "TimeInputType.h"
 #include "URLInputType.h"
@@ -78,6 +77,7 @@
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
 #include <wtf/text/StringHash.h>
+#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
index 5b7d901..f35fb4c 100644 (file)
@@ -52,7 +52,6 @@
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
 #include "ShadowRoot.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextControlInnerElements.h"
 #include "TextEvent.h"
 #include "TextIterator.h"
index f6f0276..9032db6 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "HTMLInputElement.h"
 #include "InputTypeNames.h"
-#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
index afa8e12..85a3ad2 100644 (file)
@@ -32,6 +32,7 @@
 #include "FontCascade.h"
 #include <wtf/text/TextBreakIterator.h>
 #include "TextRun.h"
+#include <unicode/ubrk.h>
 #include <wtf/Assertions.h>
 #include <wtf/Vector.h>
 #include <wtf/text/StringView.h>
@@ -43,19 +44,19 @@ namespace WebCore {
 
 typedef unsigned TruncationFunction(const String&, unsigned length, unsigned keepCount, UChar* buffer, bool shouldInsertEllipsis);
 
-static inline int textBreakAtOrPreceding(TextBreakIterator* it, int offset)
+static inline int textBreakAtOrPreceding(UBreakIterator* it, int offset)
 {
-    if (isTextBreak(it, offset))
+    if (ubrk_isBoundary(it, offset))
         return offset;
 
-    int result = textBreakPreceding(it, offset);
-    return result == TextBreakDone ? 0 : result;
+    int result = ubrk_preceding(it, offset);
+    return result == UBRK_DONE ? 0 : result;
 }
 
-static inline int boundedTextBreakFollowing(TextBreakIterator* it, int offset, int length)
+static inline int boundedTextBreakFollowing(UBreakIterator* it, int offset, int length)
 {
-    int result = textBreakFollowing(it, offset);
-    return result == TextBreakDone ? length : result;
+    int result = ubrk_following(it, offset);
+    return result == UBRK_DONE ? length : result;
 }
 
 static unsigned centerTruncateToBuffer(const String& string, unsigned length, unsigned keepCount, UChar* buffer, bool shouldInsertEllipsis)
@@ -146,7 +147,7 @@ static unsigned rightClipToWordBuffer(const String& string, unsigned length, uns
     ASSERT(keepCount < length);
     ASSERT(keepCount < STRING_BUFFER_SIZE);
 
-    TextBreakIterator* it = wordBreakIterator(StringView(string).substring(0, length));
+    UBreakIterator* it = wordBreakIterator(StringView(string).substring(0, length));
     unsigned keepLength = textBreakAtOrPreceding(it, keepCount);
     StringView(string).substring(0, keepLength).getCharactersWithUpconvert(buffer);
 
index 80f1c63..cfb5671 100644 (file)
 #include "FontCascade.h"
 #include "RenderBlock.h"
 #include "RenderText.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TextRun.h"
+#include <unicode/ubrk.h>
 #include <wtf/Optional.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/text/TextBreakIterator.h>
 #include <wtf/unicode/CharacterNames.h>
 
 #if PLATFORM(IOS)
@@ -176,21 +177,21 @@ unsigned ComplexTextController::offsetForPosition(float h, bool includePartialGl
                 // could use the glyph's "ligature carets". This is available in CoreText via CTFontGetLigatureCaretPositions().
                 CFIndex hitIndex = hitGlyphStart + (hitGlyphEnd - hitGlyphStart) * (m_run.ltr() ? x / adjustedAdvance : 1 - x / adjustedAdvance);
                 int stringLength = complexTextRun.stringLength();
-                TextBreakIterator* cursorPositionIterator = cursorMovementIterator(StringView(complexTextRun.characters(), stringLength));
+                UBreakIterator* cursorPositionIterator = cursorMovementIterator(StringView(complexTextRun.characters(), stringLength));
                 int clusterStart;
-                if (isTextBreak(cursorPositionIterator, hitIndex))
+                if (ubrk_isBoundary(cursorPositionIterator, hitIndex))
                     clusterStart = hitIndex;
                 else {
-                    clusterStart = textBreakPreceding(cursorPositionIterator, hitIndex);
-                    if (clusterStart == TextBreakDone)
+                    clusterStart = ubrk_preceding(cursorPositionIterator, hitIndex);
+                    if (clusterStart == UBRK_DONE)
                         clusterStart = 0;
                 }
 
                 if (!includePartialGlyphs)
                     return complexTextRun.stringLocation() + clusterStart;
 
-                int clusterEnd = textBreakFollowing(cursorPositionIterator, hitIndex);
-                if (clusterEnd == TextBreakDone)
+                int clusterEnd = ubrk_following(cursorPositionIterator, hitIndex);
+                if (clusterEnd == UBRK_DONE)
                     clusterEnd = stringLength;
 
                 CGFloat clusterWidth;
index 47d2447..e780ff6 100644 (file)
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "TextBoundaries.h"
 
+#include <unicode/ubrk.h>
 #include <wtf/text/StringImpl.h>
 #include <wtf/text/TextBreakIterator.h>
 
@@ -62,27 +63,27 @@ unsigned startOfLastWordBoundaryContext(StringView text)
 
 int findNextWordFromIndex(StringView text, int position, bool forward)
 {
-    TextBreakIterator* it = wordBreakIterator(text);
+    UBreakIterator* it = wordBreakIterator(text);
 
     if (forward) {
-        position = textBreakFollowing(it, position);
-        while (position != TextBreakDone) {
+        position = ubrk_following(it, position);
+        while (position != UBRK_DONE) {
             // We stop searching when the character preceeding the break is alphanumeric.
             if (static_cast<unsigned>(position) < text.length() && u_isalnum(text[position - 1]))
                 return position;
 
-            position = textBreakFollowing(it, position);
+            position = ubrk_following(it, position);
         }
 
         return text.length();
     } else {
-        position = textBreakPreceding(it, position);
-        while (position != TextBreakDone) {
+        position = ubrk_preceding(it, position);
+        while (position != UBRK_DONE) {
             // We stop searching when the character following the break is alphanumeric.
             if (position && u_isalnum(text[position]))
                 return position;
 
-            position = textBreakPreceding(it, position);
+            position = ubrk_preceding(it, position);
         }
 
         return 0;
@@ -91,19 +92,19 @@ int findNextWordFromIndex(StringView text, int position, bool forward)
 
 void findWordBoundary(StringView text, int position, int* start, int* end)
 {
-    TextBreakIterator* it = wordBreakIterator(text);
-    *end = textBreakFollowing(it, position);
+    UBreakIterator* it = wordBreakIterator(text);
+    *end = ubrk_following(it, position);
     if (*end < 0)
-        *end = textBreakLast(it);
-    *start = textBreakPrevious(it);
+        *end = ubrk_last(it);
+    *start = ubrk_previous(it);
 }
 
 void findEndWordBoundary(StringView text, int position, int* end)
 {
-    TextBreakIterator* it = wordBreakIterator(text);
-    *end = textBreakFollowing(it, position);
+    UBreakIterator* it = wordBreakIterator(text);
+    *end = ubrk_following(it, position);
     if (*end < 0)
-        *end = textBreakLast(it);
+        *end = ubrk_last(it);
 }
 
 #endif // !PLATFORM(COCOA)
index 411c806..638f76c 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <Language.h>
 #include <glib.h>
+#include <unicode/ubrk.h>
 #include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
@@ -91,13 +92,13 @@ void TextCheckerEnchant::checkSpellingOfString(const String& string, int& misspe
     if (!hasDictionary())
         return;
 
-    TextBreakIterator* iter = wordBreakIterator(string);
+    UBreakIterator* iter = wordBreakIterator(string);
     if (!iter)
         return;
 
     CString utf8String = string.utf8();
-    int start = textBreakFirst(iter);
-    for (int end = textBreakNext(iter); end != TextBreakDone; end = textBreakNext(iter)) {
+    int start = ubrk_first(iter);
+    for (int end = ubrk_next(iter); end != UBRK_DONE; end = ubrk_next(iter)) {
         if (isWordTextBreak(iter)) {
             checkSpellingOfWord(utf8String, start, end, misspellingLocation, misspellingLength);
             // Stop checking the next words If the current word is misspelled, to do not overwrite its misspelled location and length.
index 140d1c9..5c39d63 100644 (file)
@@ -267,18 +267,18 @@ int findNextWordFromIndex(StringView text, int position, bool forward)
     // for the contexts in which it is used on iPhone, and in the future will be
     // tuned to improve the iPhone-specific behavior for the keyboard and text editing.
     int pos = position;
-    TextBreakIterator* boundary = wordBreakIterator(text);
+    UBreakIterator* boundary = wordBreakIterator(text);
     if (boundary) {
         if (forward) {
             do {
-                pos = textBreakFollowing(boundary, pos);
+                pos = ubrk_following(boundary, pos);
                 if (pos == UBRK_DONE)
                     pos = text.length();
             } while (static_cast<unsigned>(pos) < text.length() && (pos == 0 || !isSkipCharacter(text[pos - 1])) && isSkipCharacter(text[pos]));
         }
         else {
             do {
-                pos = textBreakPreceding(boundary, pos);
+                pos = ubrk_preceding(boundary, pos);
                 if (pos == UBRK_DONE)
                     pos = 0;
             } while (pos > 0 && isSkipCharacter(text[pos]) && !isWhitespaceCharacter(text[pos - 1]));
index 88d7e99..7c6e480 100644 (file)
@@ -102,10 +102,10 @@ inline unsigned nextBreakablePositionNonLoosely(LazyLineBreakIterator& lazyBreak
             if (!nextBreak || nextBreak.value() < i) {
                 // Don't break if positioned at start of primary context and there is no prior context.
                 if (i || priorContextLength) {
-                    TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
+                    UBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
                     if (breakIterator) {
-                        int candidate = textBreakFollowing(breakIterator, i - 1 + priorContextLength);
-                        if (candidate == TextBreakDone)
+                        int candidate = ubrk_following(breakIterator, i - 1 + priorContextLength);
+                        if (candidate == UBRK_DONE)
                             nextBreak = std::nullopt;
                         else {
                             unsigned result = candidate;
@@ -147,11 +147,11 @@ static inline unsigned nextBreakablePositionLoosely(LazyLineBreakIterator& lazyB
         if (!nextBreak || nextBreak.value() < i) {
             // Don't break if positioned at start of primary context and there is no prior context.
             if (i || priorContextLength) {
-                TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
+                UBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
                 if (breakIterator) {
                     ASSERT(i + priorContextLength >= 1);
-                    int candidate = textBreakFollowing(breakIterator, i + priorContextLength - 1);
-                    if (candidate == TextBreakDone)
+                    int candidate = ubrk_following(breakIterator, i + priorContextLength - 1);
+                    if (candidate == UBRK_DONE)
                         nextBreak = std::nullopt;
                     else {
                         unsigned result = candidate;
index 122d17d..c8cf83a 100644 (file)
@@ -68,7 +68,6 @@
 #include "Settings.h"
 #include "ShadowRoot.h"
 #include "ShapeOutsideInfo.h"
-#include <wtf/text/TextBreakIterator.h>
 #include "TransformState.h"
 
 #include <wtf/NeverDestroyed.h>
index a25e40f..3d3fe27 100644 (file)
@@ -153,7 +153,7 @@ void makeCapitalized(String* string, UChar previous)
             stringWithPrevious[i] = stringImpl[i - 1];
     }
 
-    TextBreakIterator* boundary = wordBreakIterator(StringView(stringWithPrevious.characters(), length + 1));
+    UBreakIterator* boundary = wordBreakIterator(StringView(stringWithPrevious.characters(), length + 1));
     if (!boundary)
         return;
 
@@ -161,8 +161,8 @@ void makeCapitalized(String* string, UChar previous)
     result.reserveCapacity(length);
 
     int32_t endOfWord;
-    int32_t startOfWord = textBreakFirst(boundary);
-    for (endOfWord = textBreakNext(boundary); endOfWord != TextBreakDone; startOfWord = endOfWord, endOfWord = textBreakNext(boundary)) {
+    int32_t startOfWord = ubrk_first(boundary);
+    for (endOfWord = ubrk_next(boundary); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(boundary)) {
         if (startOfWord) // Ignore first char of previous string
             result.append(stringImpl[startOfWord - 1] == noBreakSpace ? noBreakSpace : u_totitle(stringWithPrevious[startOfWord]));
         for (int i = startOfWord + 1; i < endOfWord; i++)
@@ -1469,12 +1469,12 @@ int RenderText::previousOffset(int current) const
         return current - 1;
 
     StringImpl* textImpl = m_text.impl();
-    TextBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
+    UBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
     if (!iterator)
         return current - 1;
 
-    long result = textBreakPreceding(iterator, current);
-    if (result == TextBreakDone)
+    long result = ubrk_preceding(iterator, current);
+    if (result == UBRK_DONE)
         result = current - 1;
 
 
@@ -1523,7 +1523,7 @@ int RenderText::previousOffsetForBackwardDeletion(int current) const
     ASSERT(!m_text.isNull());
     StringImpl& text = *m_text.impl();
 
-    // FIXME: Unclear why this has so much handrolled code rather than using TextBreakIterator.
+    // FIXME: Unclear why this has so much handrolled code rather than using UBreakIterator.
     // Also unclear why this is so different from advanceByCombiningCharacterSequence.
 
     // FIXME: Seems like this fancier case could be used on all platforms now, no
@@ -1649,12 +1649,12 @@ int RenderText::nextOffset(int current) const
         return current + 1;
 
     StringImpl* textImpl = m_text.impl();
-    TextBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
+    UBreakIterator* iterator = cursorMovementIterator(StringView(textImpl->characters16(), textImpl->length()));
     if (!iterator)
         return current + 1;
 
-    long result = textBreakFollowing(iterator, current);
-    if (result == TextBreakDone)
+    long result = ubrk_following(iterator, current);
+    if (result == UBRK_DONE)
         result = current + 1;
 
     return result;
index aee75a4..0fbe685 100644 (file)
@@ -28,7 +28,6 @@
 #include "BreakLines.h"
 #include "RenderLineBreak.h"
 #include "SimpleLineLayoutFlowContents.h"
-#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
index bfd9867..0c9d9f8 100644 (file)
@@ -28,7 +28,6 @@
 #include "LineInfo.h"
 #include "LineInlineHeaders.h"
 #include <wtf/Vector.h>
-#include <wtf/text/TextBreakIterator.h>
 
 namespace WebCore {
 
index 5631833..4b773eb 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Stop reinterpret_casting UBreakIterators to the undefined type TextBreakIterator
+        https://bugs.webkit.org/show_bug.cgi?id=165931
+
+        Reviewed by Alex Christensen.
+
+        * Misc/WebUIKitSupport.mm:
+
 2016-11-01  Alex Christensen  <achristensen@webkit.org>
 
         Remove PassRefPtr from DumpRenderTree
index 89eb2a3..c4efc2e 100644 (file)
@@ -40,7 +40,6 @@
 #import <WebCore/WebCoreSystemInterface.h>
 #import <WebCore/WebCoreThreadSystemInterface.h>
 #import <wtf/spi/darwin/dyldSPI.h>
-#import <wtf/text/TextBreakIterator.h>
 
 #import <runtime/InitializeThreading.h>
 
index 8e29425..3df8364 100644 (file)
@@ -135,7 +135,7 @@ void TextChecker::closeSpellDocumentWithTag(int64_t tag)
 static unsigned nextWordOffset(StringView text, unsigned currentOffset)
 {
     // FIXME: avoid creating textIterator object here, it could be passed as a parameter.
-    //        isTextBreak() leaves the iterator pointing to the first boundary position at
+    //        ubrk_isBoundary() leaves the iterator pointing to the first boundary position at
     //        or after "offset" (ubrk_isBoundary side effect).
     //        For many word separators, the method doesn't properly determine the boundaries
     //        without resetting the iterator.
@@ -144,7 +144,7 @@ static unsigned nextWordOffset(StringView text, unsigned currentOffset)
         return currentOffset;
 
     unsigned wordOffset = currentOffset;
-    while (wordOffset < text.length() && isTextBreak(textIterator, wordOffset))
+    while (wordOffset < text.length() && ubrk_isBoundary(textIterator, wordOffset))
         ++wordOffset;
 
     // Do not treat the word's boundary as a separator.
@@ -175,7 +175,7 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
         // involve the client to check spelling for them.
         unsigned offset = nextWordOffset(text, 0);
         unsigned lengthStrip = text.length();
-        while (lengthStrip > 0 && isTextBreak(textIterator, lengthStrip - 1))
+        while (lengthStrip > 0 && ubrk_isBoundary(textIterator, lengthStrip - 1))
             --lengthStrip;
 
         while (offset < lengthStrip) {
index c6dcf13..2513cbd 100644 (file)
@@ -32,6 +32,7 @@
 #include "WebProcessPool.h"
 #include <WebCore/NotImplemented.h>
 #include <WebCore/TextCheckerEnchant.h>
+#include <unicode/ubrk.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/TextBreakIterator.h>
 
@@ -226,16 +227,16 @@ void TextChecker::requestCheckingOfString(PassRefPtr<TextCheckerCompletion> comp
 static unsigned nextWordOffset(StringView text, unsigned currentOffset)
 {
     // FIXME: avoid creating textIterator object here, it could be passed as a parameter.
-    //        isTextBreak() leaves the iterator pointing to the first boundary position at
+    //        ubrk_isBoundary() leaves the iterator pointing to the first boundary position at
     //        or after "offset" (ubrk_isBoundary side effect).
     //        For many word separators, the method doesn't properly determine the boundaries
     //        without resetting the iterator.
-    TextBreakIterator* textIterator = wordBreakIterator(text);
+    UBreakIterator* textIterator = wordBreakIterator(text);
     if (!textIterator)
         return currentOffset;
 
     unsigned wordOffset = currentOffset;
-    while (wordOffset < text.length() && isTextBreak(textIterator, wordOffset))
+    while (wordOffset < text.length() && ubrk_isBoundary(textIterator, wordOffset))
         ++wordOffset;
 
     // Do not treat the word's boundary as a separator.
@@ -258,7 +259,7 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
     if (!(checkingTypes & TextCheckingTypeSpelling))
         return Vector<TextCheckingResult>();
 
-    TextBreakIterator* textIterator = wordBreakIterator(text);
+    UBreakIterator* textIterator = wordBreakIterator(text);
     if (!textIterator)
         return Vector<TextCheckingResult>();
 
@@ -266,7 +267,7 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
     // involve the client to check spelling for them.
     unsigned offset = nextWordOffset(text, 0);
     unsigned lengthStrip = text.length();
-    while (lengthStrip > 0 && isTextBreak(textIterator, lengthStrip - 1))
+    while (lengthStrip > 0 && ubrk_isBoundary(textIterator, lengthStrip - 1))
         --lengthStrip;
 
     Vector<TextCheckingResult> paragraphCheckingResult;