Changeset 161844 in webkit


Ignore:
Timestamp:
Jan 12, 2014 5:28:53 PM (10 years ago)
Author:
weinig@apple.com
Message:

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.
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161843 r161844  
     12014-01-12  Sam Weinig  <sam@webkit.org>
     2
     3        TextBreakIterator's should support Latin-1 for all iterator types (Part 1)
     4        https://bugs.webkit.org/show_bug.cgi?id=126856
     5
     6        Reviewed by Darin Adler.
     7
     8        - Do some initial cleanup before adding complete Latin-1 support.
     9
     10        * platform/text/TextBreakIterator.cpp:
     11        Remove non-ICU acquireLineBreakIterator() implementation.
     12
     13        * platform/text/TextBreakIterator.h:
     14        - Changes acquireLineBreakIterator() to take a StringView.
     15
     16        * platform/text/TextBreakIteratorICU.cpp:
     17        - Refactor iterator initialization and setting of text on the iterator.
     18        - Add support for using a Latin-1 provider (this is not currently used).
     19
     20        * platform/text/icu/UTextProviderLatin1.cpp:
     21        * platform/text/icu/UTextProviderLatin1.h:
     22        - Add back non-context aware Latin-1 provider (from r129662).
     23        - Rename context aware provider.
     24
     25        * platform/text/icu/UTextProviderUTF16.cpp:
     26        * platform/text/icu/UTextProviderUTF16.h:
     27        - Rename context aware provider.
     28
    1292014-01-12  Brent Fulgham  <bfulgham@apple.com>
    230
  • trunk/Source/WebCore/platform/text/TextBreakIterator.cpp

    r147588 r161844  
    6868}
    6969
    70 #if !USE(ICU_UNICODE)
    71 TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
    72 {
    73     Vector<UChar> utf16string(length);
    74     for (int i = 0; i < length; ++i)
    75         utf16string[i] = string[i];
    76     return acquireLineBreakIterator(utf16string.data(), length, locale, priorContext, priorContextLength);
    77 }
    78 #endif
    79 
    8070} // namespace WebCore
  • trunk/Source/WebCore/platform/text/TextBreakIterator.h

    r148791 r161844  
    2424
    2525#include <wtf/text/AtomicString.h>
     26#include <wtf/text/StringView.h>
    2627#include <wtf/unicode/Unicode.h>
    2728
     
    3940
    4041TextBreakIterator* wordBreakIterator(const UChar*, int length);
    41 TextBreakIterator* acquireLineBreakIterator(const LChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
    42 TextBreakIterator* acquireLineBreakIterator(const UChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
     42TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
     43
     44TextBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
    4345void releaseLineBreakIterator(TextBreakIterator*);
    44 TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
    4546
    4647int textBreakFirst(TextBreakIterator*);
     
    131132        const UChar* priorContext = priorContextLength ? &m_priorContext[priorContextCapacity - priorContextLength] : 0;
    132133        if (!m_iterator) {
    133             if (m_string.is8Bit())
    134                 m_iterator = acquireLineBreakIterator(m_string.characters8(), m_string.length(), m_locale, priorContext, priorContextLength);
    135             else
    136                 m_iterator = acquireLineBreakIterator(m_string.characters16(), m_string.length(), m_locale, priorContext, priorContextLength);
     134            m_iterator = acquireLineBreakIterator(m_string, m_locale, priorContext, priorContextLength);
    137135            m_cachedPriorContext = priorContext;
    138136            m_cachedPriorContextLength = priorContextLength;
  • trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp

    r161817 r161844  
    2727#include "UTextProviderUTF16.h"
    2828#include <wtf/Atomics.h>
     29#include <wtf/text/StringView.h>
    2930#include <wtf/text/WTFString.h>
    3031
     
    3334namespace WebCore {
    3435
    35 static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const UChar* string, int length)
    36 {
    37     if (!string)
    38         return 0;
    39 
    40     if (!createdIterator) {
     36// Iterator initialization
     37
     38static TextBreakIterator* initializeIterator(UBreakIteratorType type, const char* locale = currentTextBreakLocaleID())
     39{
     40    UErrorCode openStatus = U_ZERO_ERROR;
     41    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, locale, 0, 0, &openStatus));
     42    ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
     43    return iterator;
     44}
     45
     46#if !PLATFORM(IOS)
     47static TextBreakIterator* initializeIteratorWithRules(const char* breakRules)
     48{
     49    UParseError parseStatus;
     50    UErrorCode openStatus = U_ZERO_ERROR;
     51    String rules(breakRules);
     52    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
     53    ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
     54    return iterator;
     55}
     56#endif // !PLATFORM(IOS)
     57
     58
     59// Iterator text setting
     60
     61static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, StringView string)
     62{
     63    if (string.is8Bit()) {
     64        UTextWithBuffer textLocal;
     65        textLocal.text = UTEXT_INITIALIZER;
     66        textLocal.text.extraSize = sizeof(textLocal.buffer);
     67        textLocal.text.pExtra = textLocal.buffer;
     68
    4169        UErrorCode openStatus = U_ZERO_ERROR;
    42         iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, currentTextBreakLocaleID(), 0, 0, &openStatus));
    43         createdIterator = true;
    44         ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
     70        UText* text = openLatin1UTextProvider(&textLocal, string.characters8(), string.length(), &openStatus);
     71        if (U_FAILURE(openStatus)) {
     72            LOG_ERROR("uTextOpenLatin1 failed with status %d", openStatus);
     73            return nullptr;
     74        }
     75
     76        UErrorCode setTextStatus = U_ZERO_ERROR;
     77        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
     78        if (U_FAILURE(setTextStatus)) {
     79            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
     80            return nullptr;
     81        }
     82
     83        utext_close(text);
     84    } else {
     85        UErrorCode setTextStatus = U_ZERO_ERROR;
     86        ubrk_setText(reinterpret_cast<UBreakIterator*>(&iterator), string.characters16(), string.length(), &setTextStatus);
     87        if (U_FAILURE(setTextStatus))
     88            return nullptr;
    4589    }
    46     if (!iterator)
    47         return 0;
    48 
    49     UErrorCode setTextStatus = U_ZERO_ERROR;
    50     ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
    51     if (U_FAILURE(setTextStatus))
    52         return 0;
    53 
    54     return iterator;
    55 }
    56 
    57 TextBreakIterator* wordBreakIterator(const UChar* string, int length)
    58 {
    59     static bool createdWordBreakIterator = false;
    60     static TextBreakIterator* staticWordBreakIterator;
    61     return setUpIterator(createdWordBreakIterator, staticWordBreakIterator, UBRK_WORD, string, length);
    62 }
    63 
    64 static UText emptyText = UTEXT_INITIALIZER;
    65 
    66 TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
    67 {
    68     UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
    69     if (!iterator)
    70         return 0;
    71 
    72     UTextWithBuffer textLocal;
    73     textLocal.text = emptyText;
    74     textLocal.text.extraSize = sizeof(textLocal.buffer);
    75     textLocal.text.pExtra = textLocal.buffer;
    76 
    77     UErrorCode openStatus = U_ZERO_ERROR;
    78     UText* text = uTextOpenLatin1(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
    79     if (U_FAILURE(openStatus)) {
    80         LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
    81         return 0;
     90
     91    return &iterator;
     92}
     93
     94static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iterator, StringView string, const UChar* priorContext, unsigned priorContextLength)
     95{
     96    if (string.is8Bit()) {
     97        UTextWithBuffer textLocal;
     98        textLocal.text = UTEXT_INITIALIZER;
     99        textLocal.text.extraSize = sizeof(textLocal.buffer);
     100        textLocal.text.pExtra = textLocal.buffer;
     101
     102        UErrorCode openStatus = U_ZERO_ERROR;
     103        UText* text = openLatin1ContextAwareUTextProvider(&textLocal, string.characters8(), string.length(), priorContext, priorContextLength, &openStatus);
     104        if (U_FAILURE(openStatus)) {
     105            LOG_ERROR("openLatin1ContextAwareUTextProvider failed with status %d", openStatus);
     106            return nullptr;
     107        }
     108
     109        UErrorCode setTextStatus = U_ZERO_ERROR;
     110        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
     111        if (U_FAILURE(setTextStatus)) {
     112            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
     113            return nullptr;
     114        }
     115
     116        utext_close(text);
     117    } else {
     118        UText textLocal = UTEXT_INITIALIZER;
     119
     120        UErrorCode openStatus = U_ZERO_ERROR;
     121        UText* text = openUTF16ContextAwareUTextProvider(&textLocal, string.characters16(), string.length(), priorContext, priorContextLength, &openStatus);
     122        if (U_FAILURE(openStatus)) {
     123            LOG_ERROR("openUTF16ContextAwareUTextProvider failed with status %d", openStatus);
     124            return 0;
     125        }
     126
     127        UErrorCode setTextStatus = U_ZERO_ERROR;
     128        ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
     129        if (U_FAILURE(setTextStatus)) {
     130            LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
     131            return nullptr;
     132        }
     133
     134        utext_close(text);
    82135    }
    83136
    84     UErrorCode setTextStatus = U_ZERO_ERROR;
    85     ubrk_setUText(iterator, text, &setTextStatus);
    86     if (U_FAILURE(setTextStatus)) {
    87         LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
    88         return 0;
    89     }
    90 
    91     utext_close(text);
    92 
    93     return reinterpret_cast<TextBreakIterator*>(iterator);
    94 }
    95 
    96 TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
    97 {
    98     UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
    99     if (!iterator)
    100         return 0;
    101 
    102     UText textLocal = UTEXT_INITIALIZER;
    103 
    104     UErrorCode openStatus = U_ZERO_ERROR;
    105     UText* text = uTextOpenUTF16(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
    106     if (U_FAILURE(openStatus)) {
    107         LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
    108         return 0;
    109     }
    110 
    111     UErrorCode setTextStatus = U_ZERO_ERROR;
    112     ubrk_setUText(iterator, text, &setTextStatus);
    113     if (U_FAILURE(setTextStatus)) {
    114         LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
    115         return 0;
    116     }
    117 
    118     utext_close(text);
    119 
    120     return reinterpret_cast<TextBreakIterator*>(iterator);
    121 }
    122 
    123 void releaseLineBreakIterator(TextBreakIterator* iterator)
    124 {
    125     ASSERT_ARG(iterator, iterator);
    126 
    127     LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
    128 }
    129 
    130 static TextBreakIterator* nonSharedCharacterBreakIterator;
    131 
    132 static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
    133 {
    134 #if ENABLE(COMPARE_AND_SWAP)
    135     return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
    136 #else
    137     DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
    138     MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
    139     if (nonSharedCharacterBreakIterator != expected)
    140         return false;
    141     nonSharedCharacterBreakIterator = newValue;
    142     return true;
    143 #endif
    144 }
    145 
    146 NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
    147 {
    148     m_iterator = nonSharedCharacterBreakIterator;
    149     bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
    150     m_iterator = setUpIterator(createdIterator, m_iterator, UBRK_CHARACTER, buffer, length);
    151 }
    152 
    153 NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
    154 {
    155     if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
    156         ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
    157 }
    158 
    159 TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
    160 {
    161     static bool createdSentenceBreakIterator = false;
    162     static TextBreakIterator* staticSentenceBreakIterator;
    163     return setUpIterator(createdSentenceBreakIterator, staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
    164 }
    165 
    166 int textBreakFirst(TextBreakIterator* iterator)
    167 {
    168     return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
    169 }
    170 
    171 int textBreakLast(TextBreakIterator* iterator)
    172 {
    173     return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
    174 }
    175 
    176 int textBreakNext(TextBreakIterator* iterator)
    177 {
    178     return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
    179 }
    180 
    181 int textBreakPrevious(TextBreakIterator* iterator)
    182 {
    183     return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
    184 }
    185 
    186 int textBreakPreceding(TextBreakIterator* iterator, int pos)
    187 {
    188     return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
    189 }
    190 
    191 int textBreakFollowing(TextBreakIterator* iterator, int pos)
    192 {
    193     return ubrk_following(reinterpret_cast<UBreakIterator*>(iterator), pos);
    194 }
    195 
    196 int textBreakCurrent(TextBreakIterator* iterator)
    197 {
    198     return ubrk_current(reinterpret_cast<UBreakIterator*>(iterator));
    199 }
    200 
    201 bool isTextBreak(TextBreakIterator* iterator, int position)
    202 {
    203     return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
    204 }
    205 
    206 bool isWordTextBreak(TextBreakIterator* iterator)
    207 {
    208     int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
    209     return ruleStatus != UBRK_WORD_NONE;
    210 }
    211 
    212 #if !PLATFORM(IOS)
    213 static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator, const char* breakRules, const UChar* string, int length)
    214 {
    215     if (!string)
    216         return 0;
    217 
    218     if (!createdIterator) {
    219         UParseError parseStatus;
    220         UErrorCode openStatus = U_ZERO_ERROR;
    221         String rules(breakRules);
    222         iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
    223         createdIterator = true;
    224         ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
    225     }
    226     if (!iterator)
    227         return 0;
    228 
    229     UErrorCode setTextStatus = U_ZERO_ERROR;
    230     ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
    231     if (U_FAILURE(setTextStatus))
    232         return 0;
    233 
    234     return iterator;
    235 }
    236 #endif // !PLATFORM(IOS)
    237 
    238 TextBreakIterator* cursorMovementIterator(const UChar* string, int length)
     137    return &iterator;
     138}
     139
     140
     141// Static iterators
     142
     143TextBreakIterator* wordBreakIterator(const UChar* buffer, int length)
     144{
     145    static TextBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
     146    if (!staticWordBreakIterator)
     147        return nullptr;
     148
     149    return setTextForIterator(*staticWordBreakIterator, StringView(buffer, length));
     150}
     151
     152TextBreakIterator* sentenceBreakIterator(const UChar* buffer, int length)
     153{
     154    static TextBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
     155    if (!staticSentenceBreakIterator)
     156        return nullptr;
     157
     158    return setTextForIterator(*staticSentenceBreakIterator, StringView(buffer, length));
     159}
     160
     161TextBreakIterator* cursorMovementIterator(const UChar* buffer, int length)
    239162{
    240163#if !PLATFORM(IOS)
     
    321244        "!!safe_reverse;"
    322245        "!!safe_forward;";
    323     static bool createdCursorMovementIterator = false;
    324     static TextBreakIterator* staticCursorMovementIterator;
    325     return setUpIteratorWithRules(createdCursorMovementIterator, staticCursorMovementIterator, kRules, string, length);
     246    static TextBreakIterator* staticCursorMovementIterator = initializeIteratorWithRules(kRules);
    326247#else // PLATFORM(IOS)
    327248    // Use the special Thai character break iterator for all locales
    328     static bool createdCursorBreakIterator;
    329     static TextBreakIterator* staticCursorBreakIterator;
    330 
    331     if (!string)
     249    static TextBreakIterator* staticCursorMovementIterator = createSharedIterator(UBRK_CHARACTER, "th");
     250#endif // !PLATFORM(IOS)
     251
     252    if (!staticCursorMovementIterator)
    332253        return nullptr;
    333254
    334     if (!createdCursorBreakIterator) {
    335         UErrorCode openStatus = U_ZERO_ERROR;
    336         staticCursorBreakIterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(UBRK_CHARACTER, "th", 0, 0, &openStatus));
    337         createdCursorBreakIterator = true;
    338         ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
    339     }
    340     if (!staticCursorBreakIterator)
     255    return setTextForIterator(*staticCursorMovementIterator, StringView(buffer, length));
     256}
     257
     258TextBreakIterator* acquireLineBreakIterator(StringView string, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
     259{
     260    TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(LineBreakIteratorPool::sharedPool().take(locale));
     261    if (!iterator)
    341262        return nullptr;
    342263
    343     UErrorCode setTextStatus = U_ZERO_ERROR;
    344     ubrk_setText(reinterpret_cast<UBreakIterator*>(staticCursorBreakIterator), string, length, &setTextStatus);
    345     if (U_FAILURE(setTextStatus))
    346         return nullptr;
    347 
    348     return staticCursorBreakIterator;
    349 #endif // !PLATFORM(IOS)
    350 }
    351 
    352 }
     264    return setContextAwareTextForIterator(*iterator, string, priorContext, priorContextLength);
     265}
     266
     267void releaseLineBreakIterator(TextBreakIterator* iterator)
     268{
     269    ASSERT_ARG(iterator, iterator);
     270
     271    LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
     272}
     273
     274static TextBreakIterator* nonSharedCharacterBreakIterator;
     275
     276static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
     277{
     278#if ENABLE(COMPARE_AND_SWAP)
     279    return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
     280#else
     281    DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
     282    MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
     283    if (nonSharedCharacterBreakIterator != expected)
     284        return false;
     285    nonSharedCharacterBreakIterator = newValue;
     286    return true;
     287#endif
     288}
     289
     290NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
     291{
     292    m_iterator = nonSharedCharacterBreakIterator;
     293
     294    bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
     295    if (!createdIterator)
     296        m_iterator = initializeIterator(UBRK_CHARACTER);
     297    if (!m_iterator)
     298        return;
     299
     300    m_iterator = setTextForIterator(*m_iterator, StringView(buffer, length));
     301}
     302
     303NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
     304{
     305    if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
     306        ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
     307}
     308
     309
     310// Iterator implemenation.
     311
     312int textBreakFirst(TextBreakIterator* iterator)
     313{
     314    return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
     315}
     316
     317int textBreakLast(TextBreakIterator* iterator)
     318{
     319    return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
     320}
     321
     322int textBreakNext(TextBreakIterator* iterator)
     323{
     324    return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
     325}
     326
     327int textBreakPrevious(TextBreakIterator* iterator)
     328{
     329    return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
     330}
     331
     332int textBreakPreceding(TextBreakIterator* iterator, int pos)
     333{
     334    return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
     335}
     336
     337int textBreakFollowing(TextBreakIterator* iterator, int pos)
     338{
     339    return ubrk_following(reinterpret_cast<UBreakIterator*>(iterator), pos);
     340}
     341
     342int textBreakCurrent(TextBreakIterator* iterator)
     343{
     344    return ubrk_current(reinterpret_cast<UBreakIterator*>(iterator));
     345}
     346
     347bool isTextBreak(TextBreakIterator* iterator, int position)
     348{
     349    return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
     350}
     351
     352bool isWordTextBreak(TextBreakIterator* iterator)
     353{
     354    int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
     355    return ruleStatus != UBRK_WORD_NONE;
     356}
     357
     358}
  • trunk/Source/WebCore/platform/text/icu/UTextProvider.h

    r161817 r161844  
    4747}
    4848
    49 inline void uTextInitialize(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
     49inline void initializeContextAwareUTextProvider(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
    5050{
    5151    text->pFuncs = funcs;
  • trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp

    r161817 r161844  
    3232namespace WebCore {
    3333
    34 static inline UTextProviderContext textLatin1GetCurrentContext(const UText* text)
     34// Latin1 provider
     35
     36static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
     37static int64_t uTextLatin1NativeLength(UText*);
     38static UBool uTextLatin1Access(UText*, int64_t, UBool);
     39static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
     40static int64_t uTextLatin1MapOffsetToNative(const UText*);
     41static int32_t uTextLatin1MapNativeIndexToUTF16(const UText*, int64_t);
     42static void uTextLatin1Close(UText*);
     43
     44static struct UTextFuncs uTextLatin1Funcs = {
     45    sizeof(UTextFuncs),
     46    0,
     47    0,
     48    0,
     49    uTextLatin1Clone,
     50    uTextLatin1NativeLength,
     51    uTextLatin1Access,
     52    uTextLatin1Extract,
     53    nullptr,
     54    nullptr,
     55    uTextLatin1MapOffsetToNative,
     56    uTextLatin1MapNativeIndexToUTF16,
     57    uTextLatin1Close,
     58    nullptr,
     59    nullptr,
     60    nullptr
     61};
     62
     63static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
     64{
     65    ASSERT_UNUSED(deep, !deep);
     66
     67    if (U_FAILURE(*status))
     68        return 0;
     69
     70    UText* result = utext_setup(destination, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1), status);
     71    if (U_FAILURE(*status))
     72        return destination;
     73   
     74    result->providerProperties = source->providerProperties;
     75   
     76    // Point at the same position, but with an empty buffer.
     77    result->chunkNativeStart = source->chunkNativeStart;
     78    result->chunkNativeLimit = source->chunkNativeStart;
     79    result->nativeIndexingLimit = source->chunkNativeStart;
     80    result->chunkOffset = 0;
     81    result->context = source->context;
     82    result->a = source->a;
     83    result->pFuncs = &uTextLatin1Funcs;
     84    result->chunkContents = (UChar*)result->pExtra;
     85    memset(const_cast<UChar*>(result->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
     86
     87    return result;
     88}
     89
     90static int64_t uTextLatin1NativeLength(UText* uText)
     91{
     92    return uText->a;
     93}
     94
     95static UBool uTextLatin1Access(UText* uText, int64_t index, UBool forward)
     96{
     97    int64_t length = uText->a;
     98
     99    if (forward) {
     100        if (index < uText->chunkNativeLimit && index >= uText->chunkNativeStart) {
     101            // Already inside the buffer. Set the new offset.
     102            uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
     103            return TRUE;
     104        }
     105        if (index >= length && uText->chunkNativeLimit == length) {
     106            // Off the end of the buffer, but we can't get it.
     107            uText->chunkOffset = uText->chunkLength;
     108            return FALSE;
     109        }
     110    } else {
     111        if (index <= uText->chunkNativeLimit && index > uText->chunkNativeStart) {
     112            // Already inside the buffer. Set the new offset.
     113            uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
     114            return TRUE;
     115        }
     116        if (!index && !uText->chunkNativeStart) {
     117            // Already at the beginning; can't go any farther.
     118            uText->chunkOffset = 0;
     119            return FALSE;
     120        }
     121    }
     122   
     123    if (forward) {
     124        uText->chunkNativeStart = index;
     125        uText->chunkNativeLimit = uText->chunkNativeStart + UTextWithBufferInlineCapacity;
     126        if (uText->chunkNativeLimit > length)
     127            uText->chunkNativeLimit = length;
     128
     129        uText->chunkOffset = 0;
     130    } else {
     131        uText->chunkNativeLimit = index;
     132        if (uText->chunkNativeLimit > length)
     133            uText->chunkNativeLimit = length;
     134
     135        uText->chunkNativeStart = uText->chunkNativeLimit -  UTextWithBufferInlineCapacity;
     136        if (uText->chunkNativeStart < 0)
     137            uText->chunkNativeStart = 0;
     138
     139        uText->chunkOffset = uText->chunkLength;
     140    }
     141    uText->chunkLength = static_cast<int32_t>(uText->chunkNativeLimit - uText->chunkNativeStart);
     142
     143    StringImpl::copyChars(const_cast<UChar*>(uText->chunkContents), static_cast<const LChar*>(uText->context) + uText->chunkNativeStart, static_cast<unsigned>(uText->chunkLength));
     144
     145    uText->nativeIndexingLimit = uText->chunkLength;
     146
     147    return TRUE;
     148}
     149
     150static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, UChar* dest, int32_t destCapacity, UErrorCode* status)
     151{
     152    int64_t length = uText->a;
     153    if (U_FAILURE(*status))
     154        return 0;
     155
     156    if (destCapacity < 0 || (!dest && destCapacity > 0)) {
     157        *status = U_ILLEGAL_ARGUMENT_ERROR;
     158        return 0;
     159    }
     160
     161    if (start < 0 || start > limit || (limit - start) > INT32_MAX) {
     162        *status = U_INDEX_OUTOFBOUNDS_ERROR;
     163        return 0;
     164    }
     165
     166    if (start > length)
     167        start = length;
     168    if (limit > length)
     169        limit = length;
     170
     171    length = limit - start;
     172   
     173    if (!length)
     174        return 0;
     175
     176    if (destCapacity > 0 && !dest) {
     177        int32_t trimmedLength = length;
     178        if (trimmedLength > destCapacity)
     179            trimmedLength = destCapacity;
     180
     181        StringImpl::copyChars(dest, static_cast<const LChar*>(uText->context) + start, static_cast<unsigned>(trimmedLength));
     182    }
     183
     184    if (length < destCapacity) {
     185        dest[length] = 0;
     186        if (*status == U_STRING_NOT_TERMINATED_WARNING)
     187            *status = U_ZERO_ERROR;
     188    } else if (length == destCapacity)
     189        *status = U_STRING_NOT_TERMINATED_WARNING;
     190    else
     191        *status = U_BUFFER_OVERFLOW_ERROR;
     192
     193    return length;
     194}
     195
     196static int64_t uTextLatin1MapOffsetToNative(const UText* uText)
     197{
     198    return uText->chunkNativeStart + uText->chunkOffset;
     199}
     200
     201static int32_t uTextLatin1MapNativeIndexToUTF16(const UText* uText, int64_t nativeIndex)
     202{
     203    ASSERT_UNUSED(uText, uText->chunkNativeStart >= nativeIndex);
     204    ASSERT_UNUSED(uText, nativeIndex < uText->chunkNativeLimit);
     205    return nativeIndex;
     206}
     207
     208static void uTextLatin1Close(UText* uText)
     209{
     210    uText->context = nullptr;
     211}
     212
     213UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status)
     214{
     215    if (U_FAILURE(*status))
     216        return nullptr;
     217    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
     218        *status = U_ILLEGAL_ARGUMENT_ERROR;
     219        return nullptr;
     220    }
     221    UText* text = utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status);
     222    if (U_FAILURE(*status)) {
     223        ASSERT(!text);
     224        return nullptr;
     225    }
     226
     227    text->context = string;
     228    text->a = length;
     229    text->pFuncs = &uTextLatin1Funcs;
     230    text->chunkContents = (UChar*)text->pExtra;
     231    memset(const_cast<UChar*>(text->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
     232
     233    return text;
     234}
     235
     236
     237// Latin1ContextAware provider
     238
     239static UText* uTextLatin1ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
     240static int64_t uTextLatin1ContextAwareNativeLength(UText*);
     241static UBool uTextLatin1ContextAwareAccess(UText*, int64_t, UBool);
     242static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
     243static void uTextLatin1ContextAwareClose(UText*);
     244
     245static const struct UTextFuncs textLatin1ContextAwareFuncs = {
     246    sizeof(UTextFuncs),
     247    0,
     248    0,
     249    0,
     250    uTextLatin1ContextAwareClone,
     251    uTextLatin1ContextAwareNativeLength,
     252    uTextLatin1ContextAwareAccess,
     253    uTextLatin1ContextAwareExtract,
     254    nullptr,
     255    nullptr,
     256    nullptr,
     257    nullptr,
     258    uTextLatin1ContextAwareClose,
     259    nullptr,
     260    nullptr,
     261    nullptr
     262};
     263
     264static inline UTextProviderContext textLatin1ContextAwareGetCurrentContext(const UText* text)
    35265{
    36266    if (!text->chunkContents)
     
    39269}
    40270
    41 static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     271static void textLatin1ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    42272{
    43273    ASSERT(text->chunkContents == text->pExtra);
     
    64294}
    65295
    66 static void textLatin1SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     296static void textLatin1ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    67297{
    68298    ASSERT(!text->chunkContents || text->chunkContents == text->q);
    69299    text->chunkContents = static_cast<const UChar*>(text->pExtra);
    70     textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
    71 }
    72 
    73 static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     300    textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
     301}
     302
     303static void textLatin1ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    74304{
    75305    ASSERT(text->chunkContents == text->q);
     
    87317}
    88318
    89 static void textLatin1SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     319static void textLatin1ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    90320{
    91321    ASSERT(!text->chunkContents || text->chunkContents == text->pExtra);
    92322    text->chunkContents = static_cast<const UChar*>(text->q);
    93     textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
    94 }
    95 
    96 // -- Begin Latin-1 provider functions --
    97 
    98 static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
    99 static int64_t uTextLatin1NativeLength(UText*);
    100 static UBool uTextLatin1Access(UText*, int64_t, UBool);
    101 static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
    102 static void uTextLatin1Close(UText*);
    103 
    104 static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
     323    textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
     324}
     325
     326static UText* uTextLatin1ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
    105327{
    106328    return uTextCloneImpl(destination, source, deep, status);
    107329}
    108330
    109 static int64_t uTextLatin1NativeLength(UText* text)
     331static int64_t uTextLatin1ContextAwareNativeLength(UText* text)
    110332{
    111333    return text->a + text->b;
    112334}
    113335
    114 static UBool uTextLatin1Access(UText* text, int64_t nativeIndex, UBool forward)
     336static UBool uTextLatin1ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
    115337{
    116338    if (!text->context)
    117339        return FALSE;
    118     int64_t nativeLength = uTextLatin1NativeLength(text);
     340    int64_t nativeLength = uTextLatin1ContextAwareNativeLength(text);
    119341    UBool isAccessible;
    120342    if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
    121343        return isAccessible;
    122344    nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
    123     UTextProviderContext currentContext = textLatin1GetCurrentContext(text);
     345    UTextProviderContext currentContext = textLatin1ContextAwareGetCurrentContext(text);
    124346    UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
    125347    ASSERT(newContext != UTextProviderContext::NoContext);
    126348    if (newContext == currentContext) {
    127349        if (currentContext == UTextProviderContext::PrimaryContext)
    128             textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
     350            textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
    129351        else
    130             textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
     352            textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
    131353    } else if (newContext == UTextProviderContext::PrimaryContext)
    132         textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
     354        textLatin1ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
    133355    else {
    134356        ASSERT(newContext == UTextProviderContext::PriorContext);
    135         textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
     357        textLatin1ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
    136358    }
    137359    return TRUE;
    138360}
    139361
    140 static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
     362static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
    141363{
    142364    // In the present context, this text provider is used only with ICU functions
     
    147369}
    148370
    149 static void uTextLatin1Close(UText* text)
    150 {
    151     text->context = 0;
    152 }
    153 
    154 // -- End Latin-1 provider functions --
    155 
    156 static const struct UTextFuncs textLatin1Funcs = {
    157     sizeof(UTextFuncs),
    158     0, 0, 0,
    159     uTextLatin1Clone,
    160     uTextLatin1NativeLength,
    161     uTextLatin1Access,
    162     uTextLatin1Extract,
    163     0, 0, 0, 0,
    164     uTextLatin1Close,
    165     0, 0, 0,
    166 };
    167 
    168 UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
     371static void uTextLatin1ContextAwareClose(UText* text)
     372{
     373    text->context = nullptr;
     374}
     375
     376UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
    169377{
    170378    if (U_FAILURE(*status))
     
    179387        return 0;
    180388    }
    181     uTextInitialize(text, &textLatin1Funcs, string, length, priorContext, priorContextLength);
     389
     390    initializeContextAwareUTextProvider(text, &textLatin1ContextAwareFuncs, string, length, priorContext, priorContextLength);
    182391    return text;
    183392}
  • trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.h

    r161817 r161844  
    3939};
    4040
    41 UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
     41UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status);
     42UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
    4243
    4344} // namespace WebCore
  • trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp

    r161817 r161844  
    3131namespace WebCore {
    3232
    33 static inline UTextProviderContext textUTF16GetCurrentContext(const UText* text)
     33// UTF16ContextAware provider
     34
     35static UText* uTextUTF16ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
     36static int64_t uTextUTF16ContextAwareNativeLength(UText*);
     37static UBool uTextUTF16ContextAwareAccess(UText*, int64_t, UBool);
     38static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
     39static void uTextUTF16ContextAwareClose(UText*);
     40
     41static const struct UTextFuncs textUTF16ContextAwareFuncs = {
     42    sizeof(UTextFuncs),
     43    0,
     44    0,
     45    0,
     46    uTextUTF16ContextAwareClone,
     47    uTextUTF16ContextAwareNativeLength,
     48    uTextUTF16ContextAwareAccess,
     49    uTextUTF16ContextAwareExtract,
     50    nullptr,
     51    nullptr,
     52    nullptr,
     53    nullptr,
     54    uTextUTF16ContextAwareClose,
     55    nullptr,
     56    nullptr,
     57    nullptr
     58};
     59
     60static inline UTextProviderContext textUTF16ContextAwareGetCurrentContext(const UText* text)
    3461{
    3562    if (!text->chunkContents)
     
    3865}
    3966
    40 static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     67static void textUTF16ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    4168{
    4269    ASSERT(text->chunkContents == text->p);
     
    5683}
    5784
    58 static void textUTF16SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     85static void textUTF16ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    5986{
    6087    ASSERT(!text->chunkContents || text->chunkContents == text->q);
    6188    text->chunkContents = static_cast<const UChar*>(text->p);
    62     textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
     89    textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
    6390}
    6491
    65 static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     92static void textUTF16ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    6693{
    6794    ASSERT(text->chunkContents == text->q);
     
    79106}
    80107
    81 static void textUTF16SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
     108static void textUTF16ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
    82109{
    83110    ASSERT(!text->chunkContents || text->chunkContents == text->p);
    84111    text->chunkContents = static_cast<const UChar*>(text->q);
    85     textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
     112    textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
    86113}
    87114
    88 // -- Begin UTF-16 provider functions --
    89 
    90 static UText* uTextUTF16Clone(UText*, const UText*, UBool, UErrorCode*);
    91 static int64_t uTextUTF16NativeLength(UText*);
    92 static UBool uTextUTF16Access(UText*, int64_t, UBool);
    93 static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
    94 static void uTextUTF16Close(UText*);
    95 
    96 static UText* uTextUTF16Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
     115static UText* uTextUTF16ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
    97116{
    98117    return uTextCloneImpl(destination, source, deep, status);
    99118}
    100119
    101 static inline int64_t uTextUTF16NativeLength(UText* text)
     120static inline int64_t uTextUTF16ContextAwareNativeLength(UText* text)
    102121{
    103122    return text->a + text->b;
    104123}
    105124
    106 static UBool uTextUTF16Access(UText* text, int64_t nativeIndex, UBool forward)
     125static UBool uTextUTF16ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
    107126{
    108127    if (!text->context)
    109128        return FALSE;
    110     int64_t nativeLength = uTextUTF16NativeLength(text);
     129    int64_t nativeLength = uTextUTF16ContextAwareNativeLength(text);
    111130    UBool isAccessible;
    112131    if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
    113132        return isAccessible;
    114133    nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
    115     UTextProviderContext currentContext = textUTF16GetCurrentContext(text);
     134    UTextProviderContext currentContext = textUTF16ContextAwareGetCurrentContext(text);
    116135    UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
    117136    ASSERT(newContext != UTextProviderContext::NoContext);
    118137    if (newContext == currentContext) {
    119138        if (currentContext == UTextProviderContext::PrimaryContext)
    120             textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
     139            textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
    121140        else
    122             textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
     141            textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
    123142    } else if (newContext == UTextProviderContext::PrimaryContext)
    124         textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
     143        textUTF16ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
    125144    else {
    126145        ASSERT(newContext == UTextProviderContext::PriorContext);
    127         textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
     146        textUTF16ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
    128147    }
    129148    return TRUE;
    130149}
    131150
    132 static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
     151static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
    133152{
    134153    // In the present context, this text provider is used only with ICU functions
     
    139158}
    140159
    141 static void uTextUTF16Close(UText* text)
     160static void uTextUTF16ContextAwareClose(UText* text)
    142161{
    143     text->context = 0;
     162    text->context = nullptr;
    144163}
    145164
    146 // -- End UTF-16 provider functions --
    147 
    148 static const struct UTextFuncs textUTF16Funcs = {
    149     sizeof(UTextFuncs),
    150     0, 0, 0,
    151     uTextUTF16Clone,
    152     uTextUTF16NativeLength,
    153     uTextUTF16Access,
    154     uTextUTF16Extract,
    155     0, 0, 0, 0,
    156     uTextUTF16Close,
    157     0, 0, 0,
    158 };
    159 
    160 UText* uTextOpenUTF16(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
     165UText* openUTF16ContextAwareUTextProvider(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
    161166{
    162167    if (U_FAILURE(*status))
     
    171176        return 0;
    172177    }
    173     uTextInitialize(text, &textUTF16Funcs, string, length, priorContext, priorContextLength);
     178
     179    initializeContextAwareUTextProvider(text, &textUTF16ContextAwareFuncs, string, length, priorContext, priorContextLength);
    174180    return text;
    175181}
  • trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.h

    r161817 r161844  
    3232namespace WebCore {
    3333
    34 UText* uTextOpenUTF16(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
     34UText* openUTF16ContextAwareUTextProvider(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
    3535
    3636} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.