<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[161844] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/161844">161844</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2014-01-12 17:28:53 -0800 (Sun, 12 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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 <a href="http://trac.webkit.org/projects/webkit/changeset/129662">r129662</a>).
- Rename context aware provider.
* platform/text/icu/UTextProviderUTF16.cpp:
* platform/text/icu/UTextProviderUTF16.h:
- Rename context aware provider.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformtextTextBreakIteratorcpp">trunk/Source/WebCore/platform/text/TextBreakIterator.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformtextTextBreakIteratorh">trunk/Source/WebCore/platform/text/TextBreakIterator.h</a></li>
<li><a href="#trunkSourceWebCoreplatformtextTextBreakIteratorICUcpp">trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformtexticuUTextProviderh">trunk/Source/WebCore/platform/text/icu/UTextProvider.h</a></li>
<li><a href="#trunkSourceWebCoreplatformtexticuUTextProviderLatin1cpp">trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformtexticuUTextProviderLatin1h">trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.h</a></li>
<li><a href="#trunkSourceWebCoreplatformtexticuUTextProviderUTF16cpp">trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformtexticuUTextProviderUTF16h">trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/ChangeLog        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2014-01-12 Sam Weinig <sam@webkit.org>
+
+ TextBreakIterator's should support Latin-1 for all iterator types (Part 1)
+ https://bugs.webkit.org/show_bug.cgi?id=126856
+
+ Reviewed by Darin Adler.
+
+ - Do some initial cleanup before adding complete Latin-1 support.
+
+ * platform/text/TextBreakIterator.cpp:
+ Remove non-ICU acquireLineBreakIterator() implementation.
+
+ * platform/text/TextBreakIterator.h:
+ - Changes acquireLineBreakIterator() to take a StringView.
+
+ * platform/text/TextBreakIteratorICU.cpp:
+ - Refactor iterator initialization and setting of text on the iterator.
+ - Add support for using a Latin-1 provider (this is not currently used).
+
+ * platform/text/icu/UTextProviderLatin1.cpp:
+ * platform/text/icu/UTextProviderLatin1.h:
+ - Add back non-context aware Latin-1 provider (from r129662).
+ - Rename context aware provider.
+
+ * platform/text/icu/UTextProviderUTF16.cpp:
+ * platform/text/icu/UTextProviderUTF16.h:
+ - Rename context aware provider.
+
</ins><span class="cx"> 2014-01-12 Brent Fulgham <bfulgham@apple.com>
</span><span class="cx">
</span><span class="cx"> [WebGL] Error messages should use source code labels, not internal mangled symbols.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtextTextBreakIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/TextBreakIterator.cpp (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/TextBreakIterator.cpp        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/TextBreakIterator.cpp        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -67,14 +67,4 @@
</span><span class="cx"> return textBreakCurrent(it);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if !USE(ICU_UNICODE)
-TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
-{
- Vector<UChar> utf16string(length);
- for (int i = 0; i < length; ++i)
- utf16string[i] = string[i];
- return acquireLineBreakIterator(utf16string.data(), length, locale, priorContext, priorContextLength);
-}
-#endif
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtextTextBreakIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/TextBreakIterator.h (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/TextBreakIterator.h        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/TextBreakIterator.h        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -23,6 +23,7 @@
</span><span class="cx"> #define TextBreakIterator_h
</span><span class="cx">
</span><span class="cx"> #include <wtf/text/AtomicString.h>
</span><ins>+#include <wtf/text/StringView.h>
</ins><span class="cx"> #include <wtf/unicode/Unicode.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -38,11 +39,11 @@
</span><span class="cx"> TextBreakIterator* cursorMovementIterator(const UChar*, int length);
</span><span class="cx">
</span><span class="cx"> TextBreakIterator* wordBreakIterator(const UChar*, int length);
</span><del>-TextBreakIterator* acquireLineBreakIterator(const LChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
-TextBreakIterator* acquireLineBreakIterator(const UChar*, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
-void releaseLineBreakIterator(TextBreakIterator*);
</del><span class="cx"> TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
</span><span class="cx">
</span><ins>+TextBreakIterator* acquireLineBreakIterator(StringView, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength);
+void releaseLineBreakIterator(TextBreakIterator*);
+
</ins><span class="cx"> int textBreakFirst(TextBreakIterator*);
</span><span class="cx"> int textBreakLast(TextBreakIterator*);
</span><span class="cx"> int textBreakNext(TextBreakIterator*);
</span><span class="lines">@@ -130,10 +131,7 @@
</span><span class="cx"> ASSERT(priorContextLength <= priorContextCapacity);
</span><span class="cx"> const UChar* priorContext = priorContextLength ? &m_priorContext[priorContextCapacity - priorContextLength] : 0;
</span><span class="cx"> if (!m_iterator) {
</span><del>- if (m_string.is8Bit())
- m_iterator = acquireLineBreakIterator(m_string.characters8(), m_string.length(), m_locale, priorContext, priorContextLength);
- else
- m_iterator = acquireLineBreakIterator(m_string.characters16(), m_string.length(), m_locale, priorContext, priorContextLength);
</del><ins>+ m_iterator = acquireLineBreakIterator(m_string, m_locale, priorContext, priorContextLength);
</ins><span class="cx"> m_cachedPriorContext = priorContext;
</span><span class="cx"> m_cachedPriorContextLength = priorContextLength;
</span><span class="cx"> } else if (priorContext != m_cachedPriorContext || priorContextLength != m_cachedPriorContextLength) {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtextTextBreakIteratorICUcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -26,218 +26,141 @@
</span><span class="cx"> #include "UTextProviderLatin1.h"
</span><span class="cx"> #include "UTextProviderUTF16.h"
</span><span class="cx"> #include <wtf/Atomics.h>
</span><ins>+#include <wtf/text/StringView.h>
</ins><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="cx">
</span><span class="cx"> using namespace WTF;
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const UChar* string, int length)
</del><ins>+// Iterator initialization
+
+static TextBreakIterator* initializeIterator(UBreakIteratorType type, const char* locale = currentTextBreakLocaleID())
</ins><span class="cx"> {
</span><del>- if (!string)
- return 0;
-
- if (!createdIterator) {
- UErrorCode openStatus = U_ZERO_ERROR;
- iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, currentTextBreakLocaleID(), 0, 0, &openStatus));
- createdIterator = true;
- ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
- }
- if (!iterator)
- return 0;
-
- UErrorCode setTextStatus = U_ZERO_ERROR;
- ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
- if (U_FAILURE(setTextStatus))
- return 0;
-
</del><ins>+ UErrorCode openStatus = U_ZERO_ERROR;
+ TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(type, locale, 0, 0, &openStatus));
+ ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
</ins><span class="cx"> return iterator;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-TextBreakIterator* wordBreakIterator(const UChar* string, int length)
</del><ins>+#if !PLATFORM(IOS)
+static TextBreakIterator* initializeIteratorWithRules(const char* breakRules)
</ins><span class="cx"> {
</span><del>- static bool createdWordBreakIterator = false;
- static TextBreakIterator* staticWordBreakIterator;
- return setUpIterator(createdWordBreakIterator, staticWordBreakIterator, UBRK_WORD, string, length);
</del><ins>+ UParseError parseStatus;
+ UErrorCode openStatus = U_ZERO_ERROR;
+ String rules(breakRules);
+ TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
+ ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
+ return iterator;
</ins><span class="cx"> }
</span><ins>+#endif // !PLATFORM(IOS)
</ins><span class="cx">
</span><del>-static UText emptyText = UTEXT_INITIALIZER;
</del><span class="cx">
</span><del>-TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
-{
- UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
- if (!iterator)
- return 0;
</del><ins>+// Iterator text setting
</ins><span class="cx">
</span><del>- UTextWithBuffer textLocal;
- textLocal.text = emptyText;
- textLocal.text.extraSize = sizeof(textLocal.buffer);
- textLocal.text.pExtra = textLocal.buffer;
-
- UErrorCode openStatus = U_ZERO_ERROR;
- UText* text = uTextOpenLatin1(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
- if (U_FAILURE(openStatus)) {
- LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
- return 0;
- }
-
- UErrorCode setTextStatus = U_ZERO_ERROR;
- ubrk_setUText(iterator, text, &setTextStatus);
- if (U_FAILURE(setTextStatus)) {
- LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
- return 0;
- }
-
- utext_close(text);
-
- return reinterpret_cast<TextBreakIterator*>(iterator);
-}
-
-TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
</del><ins>+static TextBreakIterator* setTextForIterator(TextBreakIterator& iterator, StringView string)
</ins><span class="cx"> {
</span><del>- UBreakIterator* iterator = LineBreakIteratorPool::sharedPool().take(locale);
- if (!iterator)
- return 0;
</del><ins>+ if (string.is8Bit()) {
+ UTextWithBuffer textLocal;
+ textLocal.text = UTEXT_INITIALIZER;
+ textLocal.text.extraSize = sizeof(textLocal.buffer);
+ textLocal.text.pExtra = textLocal.buffer;
</ins><span class="cx">
</span><del>- UText textLocal = UTEXT_INITIALIZER;
</del><ins>+ UErrorCode openStatus = U_ZERO_ERROR;
+ UText* text = openLatin1UTextProvider(&textLocal, string.characters8(), string.length(), &openStatus);
+ if (U_FAILURE(openStatus)) {
+ LOG_ERROR("uTextOpenLatin1 failed with status %d", openStatus);
+ return nullptr;
+ }
</ins><span class="cx">
</span><del>- UErrorCode openStatus = U_ZERO_ERROR;
- UText* text = uTextOpenUTF16(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
- if (U_FAILURE(openStatus)) {
- LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
- return 0;
- }
</del><ins>+ UErrorCode setTextStatus = U_ZERO_ERROR;
+ ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+ if (U_FAILURE(setTextStatus)) {
+ LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+ return nullptr;
+ }
</ins><span class="cx">
</span><del>- UErrorCode setTextStatus = U_ZERO_ERROR;
- ubrk_setUText(iterator, text, &setTextStatus);
- if (U_FAILURE(setTextStatus)) {
- LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
- return 0;
</del><ins>+ utext_close(text);
+ } else {
+ UErrorCode setTextStatus = U_ZERO_ERROR;
+ ubrk_setText(reinterpret_cast<UBreakIterator*>(&iterator), string.characters16(), string.length(), &setTextStatus);
+ if (U_FAILURE(setTextStatus))
+ return nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- utext_close(text);
-
- return reinterpret_cast<TextBreakIterator*>(iterator);
</del><ins>+ return &iterator;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void releaseLineBreakIterator(TextBreakIterator* iterator)
</del><ins>+static TextBreakIterator* setContextAwareTextForIterator(TextBreakIterator& iterator, StringView string, const UChar* priorContext, unsigned priorContextLength)
</ins><span class="cx"> {
</span><del>- ASSERT_ARG(iterator, iterator);
</del><ins>+ if (string.is8Bit()) {
+ UTextWithBuffer textLocal;
+ textLocal.text = UTEXT_INITIALIZER;
+ textLocal.text.extraSize = sizeof(textLocal.buffer);
+ textLocal.text.pExtra = textLocal.buffer;
</ins><span class="cx">
</span><del>- LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
-}
</del><ins>+ UErrorCode openStatus = U_ZERO_ERROR;
+ UText* text = openLatin1ContextAwareUTextProvider(&textLocal, string.characters8(), string.length(), priorContext, priorContextLength, &openStatus);
+ if (U_FAILURE(openStatus)) {
+ LOG_ERROR("openLatin1ContextAwareUTextProvider failed with status %d", openStatus);
+ return nullptr;
+ }
</ins><span class="cx">
</span><del>-static TextBreakIterator* nonSharedCharacterBreakIterator;
</del><ins>+ UErrorCode setTextStatus = U_ZERO_ERROR;
+ ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+ if (U_FAILURE(setTextStatus)) {
+ LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+ return nullptr;
+ }
</ins><span class="cx">
</span><del>-static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
-{
-#if ENABLE(COMPARE_AND_SWAP)
- return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
-#else
- DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
- MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
- if (nonSharedCharacterBreakIterator != expected)
- return false;
- nonSharedCharacterBreakIterator = newValue;
- return true;
-#endif
-}
</del><ins>+ utext_close(text);
+ } else {
+ UText textLocal = UTEXT_INITIALIZER;
</ins><span class="cx">
</span><del>-NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
-{
- m_iterator = nonSharedCharacterBreakIterator;
- bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
- m_iterator = setUpIterator(createdIterator, m_iterator, UBRK_CHARACTER, buffer, length);
-}
</del><ins>+ UErrorCode openStatus = U_ZERO_ERROR;
+ UText* text = openUTF16ContextAwareUTextProvider(&textLocal, string.characters16(), string.length(), priorContext, priorContextLength, &openStatus);
+ if (U_FAILURE(openStatus)) {
+ LOG_ERROR("openUTF16ContextAwareUTextProvider failed with status %d", openStatus);
+ return 0;
+ }
</ins><span class="cx">
</span><del>-NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
-{
- if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
- ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
-}
</del><ins>+ UErrorCode setTextStatus = U_ZERO_ERROR;
+ ubrk_setUText(reinterpret_cast<UBreakIterator*>(&iterator), text, &setTextStatus);
+ if (U_FAILURE(setTextStatus)) {
+ LOG_ERROR("ubrk_setUText failed with status %d", setTextStatus);
+ return nullptr;
+ }
</ins><span class="cx">
</span><del>-TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
-{
- static bool createdSentenceBreakIterator = false;
- static TextBreakIterator* staticSentenceBreakIterator;
- return setUpIterator(createdSentenceBreakIterator, staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
-}
</del><ins>+ utext_close(text);
+ }
</ins><span class="cx">
</span><del>-int textBreakFirst(TextBreakIterator* iterator)
-{
- return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
</del><ins>+ return &iterator;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-int textBreakLast(TextBreakIterator* iterator)
-{
- return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
-}
</del><span class="cx">
</span><del>-int textBreakNext(TextBreakIterator* iterator)
-{
- return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
-}
</del><ins>+// Static iterators
</ins><span class="cx">
</span><del>-int textBreakPrevious(TextBreakIterator* iterator)
</del><ins>+TextBreakIterator* wordBreakIterator(const UChar* buffer, int length)
</ins><span class="cx"> {
</span><del>- return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
-}
</del><ins>+ static TextBreakIterator* staticWordBreakIterator = initializeIterator(UBRK_WORD);
+ if (!staticWordBreakIterator)
+ return nullptr;
</ins><span class="cx">
</span><del>-int textBreakPreceding(TextBreakIterator* iterator, int pos)
-{
- return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
</del><ins>+ return setTextForIterator(*staticWordBreakIterator, StringView(buffer, length));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-int textBreakFollowing(TextBreakIterator* iterator, int pos)
</del><ins>+TextBreakIterator* sentenceBreakIterator(const UChar* buffer, int length)
</ins><span class="cx"> {
</span><del>- return ubrk_following(reinterpret_cast<UBreakIterator*>(iterator), pos);
-}
</del><ins>+ static TextBreakIterator* staticSentenceBreakIterator = initializeIterator(UBRK_SENTENCE);
+ if (!staticSentenceBreakIterator)
+ return nullptr;
</ins><span class="cx">
</span><del>-int textBreakCurrent(TextBreakIterator* iterator)
-{
- return ubrk_current(reinterpret_cast<UBreakIterator*>(iterator));
</del><ins>+ return setTextForIterator(*staticSentenceBreakIterator, StringView(buffer, length));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool isTextBreak(TextBreakIterator* iterator, int position)
</del><ins>+TextBreakIterator* cursorMovementIterator(const UChar* buffer, int length)
</ins><span class="cx"> {
</span><del>- return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
-}
-
-bool isWordTextBreak(TextBreakIterator* iterator)
-{
- int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
- return ruleStatus != UBRK_WORD_NONE;
-}
-
</del><span class="cx"> #if !PLATFORM(IOS)
</span><del>-static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator, const char* breakRules, const UChar* string, int length)
-{
- if (!string)
- return 0;
-
- if (!createdIterator) {
- UParseError parseStatus;
- UErrorCode openStatus = U_ZERO_ERROR;
- String rules(breakRules);
- iterator = reinterpret_cast<TextBreakIterator*>(ubrk_openRules(rules.characters(), rules.length(), 0, 0, &parseStatus, &openStatus));
- createdIterator = true;
- ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
- }
- if (!iterator)
- return 0;
-
- UErrorCode setTextStatus = U_ZERO_ERROR;
- ubrk_setText(reinterpret_cast<UBreakIterator*>(iterator), string, length, &setTextStatus);
- if (U_FAILURE(setTextStatus))
- return 0;
-
- return iterator;
-}
-#endif // !PLATFORM(IOS)
-
-TextBreakIterator* cursorMovementIterator(const UChar* string, int length)
-{
-#if !PLATFORM(IOS)
</del><span class="cx"> // This rule set is based on character-break iterator rules of ICU 4.0
</span><span class="cx"> // <http://source.icu-project.org/repos/icu/icu/tags/release-4-0/source/data/brkitr/char.txt>.
</span><span class="cx"> // The major differences from the original ones are listed below:
</span><span class="lines">@@ -320,33 +243,116 @@
</span><span class="cx"> "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward)
</span><span class="cx"> "!!safe_reverse;"
</span><span class="cx"> "!!safe_forward;";
</span><del>- static bool createdCursorMovementIterator = false;
- static TextBreakIterator* staticCursorMovementIterator;
- return setUpIteratorWithRules(createdCursorMovementIterator, staticCursorMovementIterator, kRules, string, length);
</del><ins>+ static TextBreakIterator* staticCursorMovementIterator = initializeIteratorWithRules(kRules);
</ins><span class="cx"> #else // PLATFORM(IOS)
</span><span class="cx"> // Use the special Thai character break iterator for all locales
</span><del>- static bool createdCursorBreakIterator;
- static TextBreakIterator* staticCursorBreakIterator;
</del><ins>+ static TextBreakIterator* staticCursorMovementIterator = createSharedIterator(UBRK_CHARACTER, "th");
+#endif // !PLATFORM(IOS)
</ins><span class="cx">
</span><del>- if (!string)
</del><ins>+ if (!staticCursorMovementIterator)
</ins><span class="cx"> return nullptr;
</span><span class="cx">
</span><del>- if (!createdCursorBreakIterator) {
- UErrorCode openStatus = U_ZERO_ERROR;
- staticCursorBreakIterator = reinterpret_cast<TextBreakIterator*>(ubrk_open(UBRK_CHARACTER, "th", 0, 0, &openStatus));
- createdCursorBreakIterator = true;
- ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break iterator: %s (%d)", u_errorName(openStatus), openStatus);
- }
- if (!staticCursorBreakIterator)
- return nullptr;
</del><ins>+ return setTextForIterator(*staticCursorMovementIterator, StringView(buffer, length));
+}
</ins><span class="cx">
</span><del>- UErrorCode setTextStatus = U_ZERO_ERROR;
- ubrk_setText(reinterpret_cast<UBreakIterator*>(staticCursorBreakIterator), string, length, &setTextStatus);
- if (U_FAILURE(setTextStatus))
</del><ins>+TextBreakIterator* acquireLineBreakIterator(StringView string, const AtomicString& locale, const UChar* priorContext, unsigned priorContextLength)
+{
+ TextBreakIterator* iterator = reinterpret_cast<TextBreakIterator*>(LineBreakIteratorPool::sharedPool().take(locale));
+ if (!iterator)
</ins><span class="cx"> return nullptr;
</span><span class="cx">
</span><del>- return staticCursorBreakIterator;
-#endif // !PLATFORM(IOS)
</del><ins>+ return setContextAwareTextForIterator(*iterator, string, priorContext, priorContextLength);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void releaseLineBreakIterator(TextBreakIterator* iterator)
+{
+ ASSERT_ARG(iterator, iterator);
+
+ LineBreakIteratorPool::sharedPool().put(reinterpret_cast<UBreakIterator*>(iterator));
</ins><span class="cx"> }
</span><ins>+
+static TextBreakIterator* nonSharedCharacterBreakIterator;
+
+static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
+{
+#if ENABLE(COMPARE_AND_SWAP)
+ return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
+#else
+ DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
+ MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
+ if (nonSharedCharacterBreakIterator != expected)
+ return false;
+ nonSharedCharacterBreakIterator = newValue;
+ return true;
+#endif
+}
+
+NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
+{
+ m_iterator = nonSharedCharacterBreakIterator;
+
+ bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
+ if (!createdIterator)
+ m_iterator = initializeIterator(UBRK_CHARACTER);
+ if (!m_iterator)
+ return;
+
+ m_iterator = setTextForIterator(*m_iterator, StringView(buffer, length));
+}
+
+NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
+{
+ if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
+ ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
+}
+
+
+// Iterator implemenation.
+
+int textBreakFirst(TextBreakIterator* iterator)
+{
+ return ubrk_first(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+int textBreakLast(TextBreakIterator* iterator)
+{
+ return ubrk_last(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+int textBreakNext(TextBreakIterator* iterator)
+{
+ return ubrk_next(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+int textBreakPrevious(TextBreakIterator* iterator)
+{
+ return ubrk_previous(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+int textBreakPreceding(TextBreakIterator* iterator, int pos)
+{
+ return ubrk_preceding(reinterpret_cast<UBreakIterator*>(iterator), pos);
+}
+
+int textBreakFollowing(TextBreakIterator* iterator, int pos)
+{
+ return ubrk_following(reinterpret_cast<UBreakIterator*>(iterator), pos);
+}
+
+int textBreakCurrent(TextBreakIterator* iterator)
+{
+ return ubrk_current(reinterpret_cast<UBreakIterator*>(iterator));
+}
+
+bool isTextBreak(TextBreakIterator* iterator, int position)
+{
+ return ubrk_isBoundary(reinterpret_cast<UBreakIterator*>(iterator), position);
+}
+
+bool isWordTextBreak(TextBreakIterator* iterator)
+{
+ int ruleStatus = ubrk_getRuleStatus(reinterpret_cast<UBreakIterator*>(iterator));
+ return ruleStatus != UBRK_WORD_NONE;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformtexticuUTextProviderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/icu/UTextProvider.h (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/icu/UTextProvider.h        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/icu/UTextProvider.h        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> return UTextProviderContext::PriorContext;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-inline void uTextInitialize(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
</del><ins>+inline void initializeContextAwareUTextProvider(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
</ins><span class="cx"> {
</span><span class="cx"> text->pFuncs = funcs;
</span><span class="cx"> text->providerProperties = 1 << UTEXT_PROVIDER_STABLE_CHUNKS;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtexticuUTextProviderLatin1cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -31,14 +31,244 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-static inline UTextProviderContext textLatin1GetCurrentContext(const UText* text)
</del><ins>+// Latin1 provider
+
+static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextLatin1NativeLength(UText*);
+static UBool uTextLatin1Access(UText*, int64_t, UBool);
+static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static int64_t uTextLatin1MapOffsetToNative(const UText*);
+static int32_t uTextLatin1MapNativeIndexToUTF16(const UText*, int64_t);
+static void uTextLatin1Close(UText*);
+
+static struct UTextFuncs uTextLatin1Funcs = {
+ sizeof(UTextFuncs),
+ 0,
+ 0,
+ 0,
+ uTextLatin1Clone,
+ uTextLatin1NativeLength,
+ uTextLatin1Access,
+ uTextLatin1Extract,
+ nullptr,
+ nullptr,
+ uTextLatin1MapOffsetToNative,
+ uTextLatin1MapNativeIndexToUTF16,
+ uTextLatin1Close,
+ nullptr,
+ nullptr,
+ nullptr
+};
+
+static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
</ins><span class="cx"> {
</span><ins>+ ASSERT_UNUSED(deep, !deep);
+
+ if (U_FAILURE(*status))
+ return 0;
+
+ UText* result = utext_setup(destination, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1), status);
+ if (U_FAILURE(*status))
+ return destination;
+
+ result->providerProperties = source->providerProperties;
+
+ // Point at the same position, but with an empty buffer.
+ result->chunkNativeStart = source->chunkNativeStart;
+ result->chunkNativeLimit = source->chunkNativeStart;
+ result->nativeIndexingLimit = source->chunkNativeStart;
+ result->chunkOffset = 0;
+ result->context = source->context;
+ result->a = source->a;
+ result->pFuncs = &uTextLatin1Funcs;
+ result->chunkContents = (UChar*)result->pExtra;
+ memset(const_cast<UChar*>(result->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
+
+ return result;
+}
+
+static int64_t uTextLatin1NativeLength(UText* uText)
+{
+ return uText->a;
+}
+
+static UBool uTextLatin1Access(UText* uText, int64_t index, UBool forward)
+{
+ int64_t length = uText->a;
+
+ if (forward) {
+ if (index < uText->chunkNativeLimit && index >= uText->chunkNativeStart) {
+ // Already inside the buffer. Set the new offset.
+ uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
+ return TRUE;
+ }
+ if (index >= length && uText->chunkNativeLimit == length) {
+ // Off the end of the buffer, but we can't get it.
+ uText->chunkOffset = uText->chunkLength;
+ return FALSE;
+ }
+ } else {
+ if (index <= uText->chunkNativeLimit && index > uText->chunkNativeStart) {
+ // Already inside the buffer. Set the new offset.
+ uText->chunkOffset = static_cast<int32_t>(index - uText->chunkNativeStart);
+ return TRUE;
+ }
+ if (!index && !uText->chunkNativeStart) {
+ // Already at the beginning; can't go any farther.
+ uText->chunkOffset = 0;
+ return FALSE;
+ }
+ }
+
+ if (forward) {
+ uText->chunkNativeStart = index;
+ uText->chunkNativeLimit = uText->chunkNativeStart + UTextWithBufferInlineCapacity;
+ if (uText->chunkNativeLimit > length)
+ uText->chunkNativeLimit = length;
+
+ uText->chunkOffset = 0;
+ } else {
+ uText->chunkNativeLimit = index;
+ if (uText->chunkNativeLimit > length)
+ uText->chunkNativeLimit = length;
+
+ uText->chunkNativeStart = uText->chunkNativeLimit - UTextWithBufferInlineCapacity;
+ if (uText->chunkNativeStart < 0)
+ uText->chunkNativeStart = 0;
+
+ uText->chunkOffset = uText->chunkLength;
+ }
+ uText->chunkLength = static_cast<int32_t>(uText->chunkNativeLimit - uText->chunkNativeStart);
+
+ StringImpl::copyChars(const_cast<UChar*>(uText->chunkContents), static_cast<const LChar*>(uText->context) + uText->chunkNativeStart, static_cast<unsigned>(uText->chunkLength));
+
+ uText->nativeIndexingLimit = uText->chunkLength;
+
+ return TRUE;
+}
+
+static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, UChar* dest, int32_t destCapacity, UErrorCode* status)
+{
+ int64_t length = uText->a;
+ if (U_FAILURE(*status))
+ return 0;
+
+ if (destCapacity < 0 || (!dest && destCapacity > 0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ if (start < 0 || start > limit || (limit - start) > INT32_MAX) {
+ *status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+ if (start > length)
+ start = length;
+ if (limit > length)
+ limit = length;
+
+ length = limit - start;
+
+ if (!length)
+ return 0;
+
+ if (destCapacity > 0 && !dest) {
+ int32_t trimmedLength = length;
+ if (trimmedLength > destCapacity)
+ trimmedLength = destCapacity;
+
+ StringImpl::copyChars(dest, static_cast<const LChar*>(uText->context) + start, static_cast<unsigned>(trimmedLength));
+ }
+
+ if (length < destCapacity) {
+ dest[length] = 0;
+ if (*status == U_STRING_NOT_TERMINATED_WARNING)
+ *status = U_ZERO_ERROR;
+ } else if (length == destCapacity)
+ *status = U_STRING_NOT_TERMINATED_WARNING;
+ else
+ *status = U_BUFFER_OVERFLOW_ERROR;
+
+ return length;
+}
+
+static int64_t uTextLatin1MapOffsetToNative(const UText* uText)
+{
+ return uText->chunkNativeStart + uText->chunkOffset;
+}
+
+static int32_t uTextLatin1MapNativeIndexToUTF16(const UText* uText, int64_t nativeIndex)
+{
+ ASSERT_UNUSED(uText, uText->chunkNativeStart >= nativeIndex);
+ ASSERT_UNUSED(uText, nativeIndex < uText->chunkNativeLimit);
+ return nativeIndex;
+}
+
+static void uTextLatin1Close(UText* uText)
+{
+ uText->context = nullptr;
+}
+
+UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status)
+{
+ if (U_FAILURE(*status))
+ return nullptr;
+ if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ UText* text = utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status);
+ if (U_FAILURE(*status)) {
+ ASSERT(!text);
+ return nullptr;
+ }
+
+ text->context = string;
+ text->a = length;
+ text->pFuncs = &uTextLatin1Funcs;
+ text->chunkContents = (UChar*)text->pExtra;
+ memset(const_cast<UChar*>(text->chunkContents), 0, sizeof(UChar) * (UTextWithBufferInlineCapacity + 1));
+
+ return text;
+}
+
+
+// Latin1ContextAware provider
+
+static UText* uTextLatin1ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextLatin1ContextAwareNativeLength(UText*);
+static UBool uTextLatin1ContextAwareAccess(UText*, int64_t, UBool);
+static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static void uTextLatin1ContextAwareClose(UText*);
+
+static const struct UTextFuncs textLatin1ContextAwareFuncs = {
+ sizeof(UTextFuncs),
+ 0,
+ 0,
+ 0,
+ uTextLatin1ContextAwareClone,
+ uTextLatin1ContextAwareNativeLength,
+ uTextLatin1ContextAwareAccess,
+ uTextLatin1ContextAwareExtract,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ uTextLatin1ContextAwareClose,
+ nullptr,
+ nullptr,
+ nullptr
+};
+
+static inline UTextProviderContext textLatin1ContextAwareGetCurrentContext(const UText* text)
+{
</ins><span class="cx"> if (!text->chunkContents)
</span><span class="cx"> return UTextProviderContext::NoContext;
</span><span class="cx"> return text->chunkContents == text->pExtra ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textLatin1ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(text->chunkContents == text->pExtra);
</span><span class="cx"> if (forward) {
</span><span class="lines">@@ -63,14 +293,14 @@
</span><span class="cx"> StringImpl::copyChars(const_cast<UChar*>(text->chunkContents), static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), static_cast<unsigned>(text->chunkLength));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textLatin1SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textLatin1ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!text->chunkContents || text->chunkContents == text->q);
</span><span class="cx"> text->chunkContents = static_cast<const UChar*>(text->pExtra);
</span><del>- textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textLatin1ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(text->chunkContents == text->q);
</span><span class="cx"> ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
</span><span class="lines">@@ -86,58 +316,50 @@
</span><span class="cx"> text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textLatin1SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textLatin1ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!text->chunkContents || text->chunkContents == text->pExtra);
</span><span class="cx"> text->chunkContents = static_cast<const UChar*>(text->q);
</span><del>- textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// -- Begin Latin-1 provider functions --
-
-static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
-static int64_t uTextLatin1NativeLength(UText*);
-static UBool uTextLatin1Access(UText*, int64_t, UBool);
-static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
-static void uTextLatin1Close(UText*);
-
-static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
</del><ins>+static UText* uTextLatin1ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
</ins><span class="cx"> {
</span><span class="cx"> return uTextCloneImpl(destination, source, deep, status);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static int64_t uTextLatin1NativeLength(UText* text)
</del><ins>+static int64_t uTextLatin1ContextAwareNativeLength(UText* text)
</ins><span class="cx"> {
</span><span class="cx"> return text->a + text->b;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static UBool uTextLatin1Access(UText* text, int64_t nativeIndex, UBool forward)
</del><ins>+static UBool uTextLatin1ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> if (!text->context)
</span><span class="cx"> return FALSE;
</span><del>- int64_t nativeLength = uTextLatin1NativeLength(text);
</del><ins>+ int64_t nativeLength = uTextLatin1ContextAwareNativeLength(text);
</ins><span class="cx"> UBool isAccessible;
</span><span class="cx"> if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
</span><span class="cx"> return isAccessible;
</span><span class="cx"> nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
</span><del>- UTextProviderContext currentContext = textLatin1GetCurrentContext(text);
</del><ins>+ UTextProviderContext currentContext = textLatin1ContextAwareGetCurrentContext(text);
</ins><span class="cx"> UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
</span><span class="cx"> ASSERT(newContext != UTextProviderContext::NoContext);
</span><span class="cx"> if (newContext == currentContext) {
</span><span class="cx"> if (currentContext == UTextProviderContext::PrimaryContext)
</span><del>- textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> else
</span><del>- textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> } else if (newContext == UTextProviderContext::PrimaryContext)
</span><del>- textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> else {
</span><span class="cx"> ASSERT(newContext == UTextProviderContext::PriorContext);
</span><del>- textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textLatin1ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx"> return TRUE;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
</del><ins>+static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
</ins><span class="cx"> {
</span><span class="cx"> // In the present context, this text provider is used only with ICU functions
</span><span class="cx"> // that do not perform an extract operation.
</span><span class="lines">@@ -146,26 +368,12 @@
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void uTextLatin1Close(UText* text)
</del><ins>+static void uTextLatin1ContextAwareClose(UText* text)
</ins><span class="cx"> {
</span><del>- text->context = 0;
</del><ins>+ text->context = nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// -- End Latin-1 provider functions --
-
-static const struct UTextFuncs textLatin1Funcs = {
- sizeof(UTextFuncs),
- 0, 0, 0,
- uTextLatin1Clone,
- uTextLatin1NativeLength,
- uTextLatin1Access,
- uTextLatin1Extract,
- 0, 0, 0, 0,
- uTextLatin1Close,
- 0, 0, 0,
-};
-
-UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
</del><ins>+UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
</ins><span class="cx"> {
</span><span class="cx"> if (U_FAILURE(*status))
</span><span class="cx"> return 0;
</span><span class="lines">@@ -178,7 +386,8 @@
</span><span class="cx"> ASSERT(!text);
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><del>- uTextInitialize(text, &textLatin1Funcs, string, length, priorContext, priorContextLength);
</del><ins>+
+ initializeContextAwareUTextProvider(text, &textLatin1ContextAwareFuncs, string, length, priorContext, priorContextLength);
</ins><span class="cx"> return text;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtexticuUTextProviderLatin1h"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.h (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.h        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/icu/UTextProviderLatin1.h        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -38,7 +38,8 @@
</span><span class="cx"> UChar buffer[UTextWithBufferInlineCapacity];
</span><span class="cx"> };
</span><span class="cx">
</span><del>-UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
</del><ins>+UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, UErrorCode* status);
+UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
</ins><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtexticuUTextProviderUTF16cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -30,14 +30,41 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-static inline UTextProviderContext textUTF16GetCurrentContext(const UText* text)
</del><ins>+// UTF16ContextAware provider
+
+static UText* uTextUTF16ContextAwareClone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextUTF16ContextAwareNativeLength(UText*);
+static UBool uTextUTF16ContextAwareAccess(UText*, int64_t, UBool);
+static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static void uTextUTF16ContextAwareClose(UText*);
+
+static const struct UTextFuncs textUTF16ContextAwareFuncs = {
+ sizeof(UTextFuncs),
+ 0,
+ 0,
+ 0,
+ uTextUTF16ContextAwareClone,
+ uTextUTF16ContextAwareNativeLength,
+ uTextUTF16ContextAwareAccess,
+ uTextUTF16ContextAwareExtract,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ uTextUTF16ContextAwareClose,
+ nullptr,
+ nullptr,
+ nullptr
+};
+
+static inline UTextProviderContext textUTF16ContextAwareGetCurrentContext(const UText* text)
</ins><span class="cx"> {
</span><span class="cx"> if (!text->chunkContents)
</span><span class="cx"> return UTextProviderContext::NoContext;
</span><span class="cx"> return text->chunkContents == text->p ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textUTF16ContextAwareMoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(text->chunkContents == text->p);
</span><span class="cx"> ASSERT_UNUSED(forward, forward ? nativeIndex >= text->b : nativeIndex > text->b);
</span><span class="lines">@@ -55,14 +82,14 @@
</span><span class="cx"> text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textUTF16SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textUTF16ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!text->chunkContents || text->chunkContents == text->q);
</span><span class="cx"> text->chunkContents = static_cast<const UChar*>(text->p);
</span><del>- textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textUTF16ContextAwareMoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(text->chunkContents == text->q);
</span><span class="cx"> ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
</span><span class="lines">@@ -78,58 +105,50 @@
</span><span class="cx"> text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void textUTF16SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</del><ins>+static void textUTF16ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!text->chunkContents || text->chunkContents == text->p);
</span><span class="cx"> text->chunkContents = static_cast<const UChar*>(text->q);
</span><del>- textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// -- Begin UTF-16 provider functions --
-
-static UText* uTextUTF16Clone(UText*, const UText*, UBool, UErrorCode*);
-static int64_t uTextUTF16NativeLength(UText*);
-static UBool uTextUTF16Access(UText*, int64_t, UBool);
-static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
-static void uTextUTF16Close(UText*);
-
-static UText* uTextUTF16Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
</del><ins>+static UText* uTextUTF16ContextAwareClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
</ins><span class="cx"> {
</span><span class="cx"> return uTextCloneImpl(destination, source, deep, status);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline int64_t uTextUTF16NativeLength(UText* text)
</del><ins>+static inline int64_t uTextUTF16ContextAwareNativeLength(UText* text)
</ins><span class="cx"> {
</span><span class="cx"> return text->a + text->b;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static UBool uTextUTF16Access(UText* text, int64_t nativeIndex, UBool forward)
</del><ins>+static UBool uTextUTF16ContextAwareAccess(UText* text, int64_t nativeIndex, UBool forward)
</ins><span class="cx"> {
</span><span class="cx"> if (!text->context)
</span><span class="cx"> return FALSE;
</span><del>- int64_t nativeLength = uTextUTF16NativeLength(text);
</del><ins>+ int64_t nativeLength = uTextUTF16ContextAwareNativeLength(text);
</ins><span class="cx"> UBool isAccessible;
</span><span class="cx"> if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
</span><span class="cx"> return isAccessible;
</span><span class="cx"> nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
</span><del>- UTextProviderContext currentContext = textUTF16GetCurrentContext(text);
</del><ins>+ UTextProviderContext currentContext = textUTF16ContextAwareGetCurrentContext(text);
</ins><span class="cx"> UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
</span><span class="cx"> ASSERT(newContext != UTextProviderContext::NoContext);
</span><span class="cx"> if (newContext == currentContext) {
</span><span class="cx"> if (currentContext == UTextProviderContext::PrimaryContext)
</span><del>- textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> else
</span><del>- textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> } else if (newContext == UTextProviderContext::PrimaryContext)
</span><del>- textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareSwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> else {
</span><span class="cx"> ASSERT(newContext == UTextProviderContext::PriorContext);
</span><del>- textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
</del><ins>+ textUTF16ContextAwareSwitchToPriorContext(text, nativeIndex, nativeLength, forward);
</ins><span class="cx"> }
</span><span class="cx"> return TRUE;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
</del><ins>+static int32_t uTextUTF16ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
</ins><span class="cx"> {
</span><span class="cx"> // In the present context, this text provider is used only with ICU functions
</span><span class="cx"> // that do not perform an extract operation.
</span><span class="lines">@@ -138,26 +157,12 @@
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void uTextUTF16Close(UText* text)
</del><ins>+static void uTextUTF16ContextAwareClose(UText* text)
</ins><span class="cx"> {
</span><del>- text->context = 0;
</del><ins>+ text->context = nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// -- End UTF-16 provider functions --
-
-static const struct UTextFuncs textUTF16Funcs = {
- sizeof(UTextFuncs),
- 0, 0, 0,
- uTextUTF16Clone,
- uTextUTF16NativeLength,
- uTextUTF16Access,
- uTextUTF16Extract,
- 0, 0, 0, 0,
- uTextUTF16Close,
- 0, 0, 0,
-};
-
-UText* uTextOpenUTF16(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
</del><ins>+UText* openUTF16ContextAwareUTextProvider(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
</ins><span class="cx"> {
</span><span class="cx"> if (U_FAILURE(*status))
</span><span class="cx"> return 0;
</span><span class="lines">@@ -170,7 +175,8 @@
</span><span class="cx"> ASSERT(!text);
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><del>- uTextInitialize(text, &textUTF16Funcs, string, length, priorContext, priorContextLength);
</del><ins>+
+ initializeContextAwareUTextProvider(text, &textUTF16ContextAwareFuncs, string, length, priorContext, priorContextLength);
</ins><span class="cx"> return text;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformtexticuUTextProviderUTF16h"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.h (161843 => 161844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.h        2014-01-13 01:26:11 UTC (rev 161843)
+++ trunk/Source/WebCore/platform/text/icu/UTextProviderUTF16.h        2014-01-13 01:28:53 UTC (rev 161844)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-UText* uTextOpenUTF16(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
</del><ins>+UText* openUTF16ContextAwareUTextProvider(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
</ins><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>