Split ICU UText providers out into their own files
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Jan 2014 19:24:29 +0000 (19:24 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Jan 2014 19:24:29 +0000 (19:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126834

Reviewed by Anders Carlsson.

Moves the implementation of our custom UText providers out into
their own files.
- UTextProviderLatin1.h/cpp contains the Latin-1 provider.
- UTextProviderUTF16.h/cpp contains the UTF-16 provider.
- UTextProvider.h/cpp contains code common to all the providers.

* CMakeLists.txt:
* GNUmakefile.list.am:
* PlatformGTK.cmake:
* WebCore.vcxproj/WebCoreCommon.props:
* WebCore.vcxproj/copyForwardingHeaders.cmd:
* WebCore.xcodeproj/project.pbxproj:
* platform/text/TextAllInOne.cpp:
* platform/text/TextBreakIteratorICU.cpp:
(WebCore::setUpIterator):
(WebCore::wordBreakIterator):
(WebCore::acquireLineBreakIterator):
(WebCore::sentenceBreakIterator):
(WebCore::setUpIteratorWithRules):
* platform/text/icu: Added.
* platform/text/icu/UTextProvider.cpp: Added.
(WebCore::fixPointer):
(WebCore::uTextCloneImpl):
* platform/text/icu/UTextProvider.h: Added.
(WebCore::uTextProviderContext):
(WebCore::uTextInitialize):
(WebCore::uTextAccessPinIndex):
(WebCore::uTextAccessInChunkOrOutOfRange):
* platform/text/icu/UTextProviderLatin1.cpp: Added.
* platform/text/icu/UTextProviderLatin1.h: Added.
* platform/text/icu/UTextProviderUTF16.cpp: Added.
* platform/text/icu/UTextProviderUTF16.h: Added.

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

17 files changed:
Source/Platform/GNUmakefile.am
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/GNUmakefile.list.am
Source/WebCore/PlatformGTK.cmake
Source/WebCore/WebCore.vcxproj/WebCoreCommon.props
Source/WebCore/WebCore.vcxproj/copyForwardingHeaders.cmd
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/text/TextAllInOne.cpp
Source/WebCore/platform/text/TextBreakIteratorICU.cpp
Source/WebCore/platform/text/icu/UTextProvider.cpp [new file with mode: 0644]
Source/WebCore/platform/text/icu/UTextProvider.h [new file with mode: 0644]
Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp [new file with mode: 0644]
Source/WebCore/platform/text/icu/UTextProviderLatin1.h [new file with mode: 0644]
Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp [new file with mode: 0644]
Source/WebCore/platform/text/icu/UTextProviderUTF16.h [new file with mode: 0644]

index 78e8c4b..faf3e8c 100644 (file)
@@ -57,6 +57,7 @@ platform_webcore_cppflags += \
        -I$(srcdir)/Source/WebCore/platform/network/gtk \
        -I$(srcdir)/Source/WebCore/platform/network/soup \
        -I$(srcdir)/Source/WebCore/platform/text \
+       -I$(srcdir)/Source/WebCore/platform/text/icu \
        -I$(srcdir)/Source/WebCore/platform/text/transcoder
 
 noinst_LTLIBRARIES += \
index be1c5b9..039f83c 100644 (file)
@@ -77,6 +77,7 @@ set(WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/network"
     "${WEBCORE_DIR}/platform/sql"
     "${WEBCORE_DIR}/platform/text"
+    "${WEBCORE_DIR}/platform/text/icu"
     "${WEBCORE_DIR}/plugins"
     "${WEBCORE_DIR}/rendering"
     "${WEBCORE_DIR}/rendering/line"
@@ -2801,6 +2802,9 @@ endif ()
 
 if (WTF_USE_ICU_UNICODE)
     list(APPEND WebCore_SOURCES
+        platform/text/icu/UTextProvider.cpp
+        platform/text/icu/UTextProviderLatin1.cpp
+        platform/text/icu/UTextProviderUTF16.cpp
         platform/text/TextBreakIteratorICU.cpp
         platform/text/TextCodecICU.cpp
         platform/text/TextEncodingDetectorICU.cpp
index 1ad6454..d161835 100644 (file)
@@ -1,3 +1,43 @@
+2014-01-11  Sam Weinig  <sam@webkit.org>
+
+        Split ICU UText providers out into their own files
+        https://bugs.webkit.org/show_bug.cgi?id=126834
+
+        Reviewed by Anders Carlsson.
+
+        Moves the implementation of our custom UText providers out into
+        their own files.
+        - UTextProviderLatin1.h/cpp contains the Latin-1 provider.
+        - UTextProviderUTF16.h/cpp contains the UTF-16 provider.
+        - UTextProvider.h/cpp contains code common to all the providers.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * PlatformGTK.cmake:
+        * WebCore.vcxproj/WebCoreCommon.props:
+        * WebCore.vcxproj/copyForwardingHeaders.cmd:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/text/TextAllInOne.cpp:
+        * platform/text/TextBreakIteratorICU.cpp:
+        (WebCore::setUpIterator):
+        (WebCore::wordBreakIterator):
+        (WebCore::acquireLineBreakIterator):
+        (WebCore::sentenceBreakIterator):
+        (WebCore::setUpIteratorWithRules):
+        * platform/text/icu: Added.
+        * platform/text/icu/UTextProvider.cpp: Added.
+        (WebCore::fixPointer):
+        (WebCore::uTextCloneImpl):
+        * platform/text/icu/UTextProvider.h: Added.
+        (WebCore::uTextProviderContext):
+        (WebCore::uTextInitialize):
+        (WebCore::uTextAccessPinIndex):
+        (WebCore::uTextAccessInChunkOrOutOfRange):
+        * platform/text/icu/UTextProviderLatin1.cpp: Added.
+        * platform/text/icu/UTextProviderLatin1.h: Added.
+        * platform/text/icu/UTextProviderUTF16.cpp: Added.
+        * platform/text/icu/UTextProviderUTF16.h: Added.
+
 2014-01-12  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix make distcheck.
index 7fd307c..8350424 100644 (file)
@@ -90,6 +90,7 @@ webcore_cppflags += \
        -I$(srcdir)/Source/WebCore/platform/network/gtk \
        -I$(srcdir)/Source/WebCore/platform/sql \
        -I$(srcdir)/Source/WebCore/platform/text \
+       -I$(srcdir)/Source/WebCore/platform/text/icu \
        -I$(srcdir)/Source/WebCore/platform/win \
        -I$(srcdir)/Source/WebCore/plugins \
        -I$(srcdir)/Source/WebCore/plugins/win \
index 034d6b3..b8e3b82 100644 (file)
@@ -5978,6 +5978,12 @@ platform_sources += \
        Source/WebCore/platform/soup/SharedBufferSoup.cpp \
        Source/WebCore/platform/text/enchant/TextCheckerEnchant.h \
        Source/WebCore/platform/text/enchant/TextCheckerEnchant.cpp \
+       Source/WebCore/platform/text/icu/UTextProvider.cpp \
+       Source/WebCore/platform/text/icu/UTextProvider.h \
+       Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp \
+       Source/WebCore/platform/text/icu/UTextProviderLatin1.h \
+       Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp \
+       Source/WebCore/platform/text/icu/UTextProviderUTF16.h \
        Source/WebCore/platform/text/BidiContext.cpp \
        Source/WebCore/platform/text/BidiContext.h \
        Source/WebCore/platform/text/BidiResolver.h \
index d09e69c..f723e54 100644 (file)
@@ -20,6 +20,7 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/network/gtk"
     "${WEBCORE_DIR}/platform/network/soup"
     "${WEBCORE_DIR}/platform/text/gtk"
+    "${WEBCORE_DIR}/platform/text/icu"
     "${WEBCORE_DIR}/plugins/gtk"
 )
 
@@ -128,6 +129,9 @@ list(APPEND WebCore_SOURCES
 
     platform/soup/SharedBufferSoup.cpp
 
+    platform/text/icu/UTextProvider.cpp
+    platform/text/icu/UTextProviderLatin1.cpp
+    platform/text/icu/UTextProviderUTF16.cpp
     platform/text/LocaleICU.cpp
     platform/text/TextBreakIteratorICU.cpp
     platform/text/TextCodecICU.cpp
@@ -255,6 +259,9 @@ list(APPEND WebCorePlatformGTK_SOURCES
 
     platform/soup/SharedBufferSoup.cpp
 
+    platform/text/icu/UTextProvider.cpp
+    platform/text/icu/UTextProviderLatin1.cpp
+    platform/text/icu/UTextProviderUTF16.cpp
     platform/text/LocaleICU.cpp
     platform/text/TextBreakIteratorICU.cpp
     platform/text/TextCodecICU.cpp
index aab4e23..829a087 100644 (file)
@@ -7,7 +7,7 @@
   </PropertyGroup>
   <ItemDefinitionGroup>
     <ClCompile>
-      <AdditionalIncludeDirectories>$(ProjectDir)..;$(ProjectDir)..\Modules\mediacontrols;$(ProjectDir)..\Modules\mediastream;$(ProjectDir)..\Modules\filesystem;$(ProjectDir)..\Modules\geolocation;$(ProjectDir)..\Modules\indexeddb;$(ProjectDir)..\Modules\mediasource;$(ProjectDir)..\Modules\navigatorcontentutils;$(ProjectDir)..\Modules\plugins;$(ProjectDir)..\Modules\speech;$(ProjectDir)..\Modules\proximity;$(ProjectDir)..\Modules\quota;$(ProjectDir)..\Modules\notifications;$(ProjectDir)..\Modules\webdatabase;$(ProjectDir)..\Modules\websockets;$(ProjectDir)..\accessibility;$(ProjectDir)..\accessibility\win;$(ProjectDir)..\bridge;$(ProjectDir)..\bridge\c;$(ProjectDir)..\bridge\jsc;$(ProjectDir)..\css;$(ProjectDir)..\editing;$(ProjectDir)..\fileapi;$(ProjectDir)..\rendering;$(ProjectDir)..\rendering\line;$(ProjectDir)..\rendering\mathml;$(ProjectDir)..\rendering\shapes;$(ProjectDir)..\rendering\style;$(ProjectDir)..\rendering\svg;$(ProjectDir)..\bindings;$(ProjectDir)..\bindings\generic;$(ProjectDir)..\bindings\js;$(ProjectDir)..\bindings\js\specialization;$(ProjectDir)..\dom;$(ProjectDir)..\dom\default;$(ProjectDir)..\history;$(ProjectDir)..\html;$(ProjectDir)..\html\canvas;$(ProjectDir)..\html\forms;$(ProjectDir)..\html\parser;$(ProjectDir)..\html\shadow;$(ProjectDir)..\html\track;$(ProjectDir)..\inspector;$(ProjectDir)..\loader;$(ProjectDir)..\loader\appcache;$(ProjectDir)..\loader\archive;$(ProjectDir)..\loader\archive\cf;$(ProjectDir)..\loader\cache;$(ProjectDir)..\loader\icon;$(ProjectDir)..\mathml;$(ProjectDir)..\page;$(ProjectDir)..\page\animation;$(ProjectDir)..\page\scrolling;$(ProjectDir)..\page\win;$(ProjectDir)..\platform;$(ProjectDir)..\platform\animation;$(ProjectDir)..\platform\audio;$(ProjectDir)..\platform\mock;$(ProjectDir)..\platform\sql;$(ProjectDir)..\platform\win;$(ProjectDir)..\platform\network;$(ProjectDir)..\platform\network\win;$(ProjectDir)..\platform\cf;$(ProjectDir)..\platform\graphics;$(ProjectDir)..\platform\graphics\ca;$(ProjectDir)..\platform\graphics\cpu\arm\filters;$(ProjectDir)..\platform\graphics\filters;$(ProjectDir)..\platform\graphics\filters\arm;$(ProjectDir)..\platform\graphics\opentype;$(ProjectDir)..\platform\graphics\transforms;$(ProjectDir)..\platform\text;$(ProjectDir)..\platform\text\transcoder;$(ProjectDir)..\platform\graphics\win;$(ProjectDir)..\xml;$(ProjectDir)..\xml\parser;$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources;$(ProjectDir)..\plugins;$(ProjectDir)..\plugins\win;$(ProjectDir)..\svg\animation;$(ProjectDir)..\svg\graphics;$(ProjectDir)..\svg\properties;$(ProjectDir)..\svg\graphics\filters;$(ProjectDir)..\svg;$(ProjectDir)..\testing;$(ProjectDir)..\crypto;$(ProjectDir)..\crypto\keys;$(ProjectDir)..\wml;$(ProjectDir)..\storage;$(ProjectDir)..\style;$(ProjectDir)..\websockets;$(ProjectDir)..\workers;$(ConfigurationBuildDir)\include;$(ConfigurationBuildDir)\include\private;$(ConfigurationBuildDir)\include\JavaScriptCore;$(ConfigurationBuildDir)\include\private\JavaScriptCore;$(ProjectDir)..\ForwardingHeaders;$(ProjectDir)..\platform\graphics\gpu;$(ProjectDir)..\platform\graphics\egl;$(ProjectDir)..\platform\graphics\surfaces;$(ProjectDir)..\platform\graphics\surfaces\egl;$(ProjectDir)..\platform\graphics\opengl;$(WebKit_Libraries)\include;$(WebKit_Libraries)\include\private;$(WebKit_Libraries)\include\private\JavaScriptCore;$(WebKit_Libraries)\include\sqlite;$(WebKit_Libraries)\include\JavaScriptCore;$(WebKit_Libraries)\include\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ProjectDir)..;$(ProjectDir)..\Modules\mediacontrols;$(ProjectDir)..\Modules\mediastream;$(ProjectDir)..\Modules\filesystem;$(ProjectDir)..\Modules\geolocation;$(ProjectDir)..\Modules\indexeddb;$(ProjectDir)..\Modules\mediasource;$(ProjectDir)..\Modules\navigatorcontentutils;$(ProjectDir)..\Modules\plugins;$(ProjectDir)..\Modules\speech;$(ProjectDir)..\Modules\proximity;$(ProjectDir)..\Modules\quota;$(ProjectDir)..\Modules\notifications;$(ProjectDir)..\Modules\webdatabase;$(ProjectDir)..\Modules\websockets;$(ProjectDir)..\accessibility;$(ProjectDir)..\accessibility\win;$(ProjectDir)..\bridge;$(ProjectDir)..\bridge\c;$(ProjectDir)..\bridge\jsc;$(ProjectDir)..\css;$(ProjectDir)..\editing;$(ProjectDir)..\fileapi;$(ProjectDir)..\rendering;$(ProjectDir)..\rendering\line;$(ProjectDir)..\rendering\mathml;$(ProjectDir)..\rendering\shapes;$(ProjectDir)..\rendering\style;$(ProjectDir)..\rendering\svg;$(ProjectDir)..\bindings;$(ProjectDir)..\bindings\generic;$(ProjectDir)..\bindings\js;$(ProjectDir)..\bindings\js\specialization;$(ProjectDir)..\dom;$(ProjectDir)..\dom\default;$(ProjectDir)..\history;$(ProjectDir)..\html;$(ProjectDir)..\html\canvas;$(ProjectDir)..\html\forms;$(ProjectDir)..\html\parser;$(ProjectDir)..\html\shadow;$(ProjectDir)..\html\track;$(ProjectDir)..\inspector;$(ProjectDir)..\loader;$(ProjectDir)..\loader\appcache;$(ProjectDir)..\loader\archive;$(ProjectDir)..\loader\archive\cf;$(ProjectDir)..\loader\cache;$(ProjectDir)..\loader\icon;$(ProjectDir)..\mathml;$(ProjectDir)..\page;$(ProjectDir)..\page\animation;$(ProjectDir)..\page\scrolling;$(ProjectDir)..\page\win;$(ProjectDir)..\platform;$(ProjectDir)..\platform\animation;$(ProjectDir)..\platform\audio;$(ProjectDir)..\platform\mock;$(ProjectDir)..\platform\sql;$(ProjectDir)..\platform\win;$(ProjectDir)..\platform\network;$(ProjectDir)..\platform\network\win;$(ProjectDir)..\platform\cf;$(ProjectDir)..\platform\graphics;$(ProjectDir)..\platform\graphics\ca;$(ProjectDir)..\platform\graphics\cpu\arm\filters;$(ProjectDir)..\platform\graphics\filters;$(ProjectDir)..\platform\graphics\filters\arm;$(ProjectDir)..\platform\graphics\opentype;$(ProjectDir)..\platform\graphics\transforms;$(ProjectDir)..\platform\text;$(ProjectDir)..\platform\text\icu;$(ProjectDir)..\platform\text\transcoder;$(ProjectDir)..\platform\graphics\win;$(ProjectDir)..\xml;$(ProjectDir)..\xml\parser;$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources;$(ProjectDir)..\plugins;$(ProjectDir)..\plugins\win;$(ProjectDir)..\svg\animation;$(ProjectDir)..\svg\graphics;$(ProjectDir)..\svg\properties;$(ProjectDir)..\svg\graphics\filters;$(ProjectDir)..\svg;$(ProjectDir)..\testing;$(ProjectDir)..\crypto;$(ProjectDir)..\crypto\keys;$(ProjectDir)..\wml;$(ProjectDir)..\storage;$(ProjectDir)..\style;$(ProjectDir)..\websockets;$(ProjectDir)..\workers;$(ConfigurationBuildDir)\include;$(ConfigurationBuildDir)\include\private;$(ConfigurationBuildDir)\include\JavaScriptCore;$(ConfigurationBuildDir)\include\private\JavaScriptCore;$(ProjectDir)..\ForwardingHeaders;$(ProjectDir)..\platform\graphics\gpu;$(ProjectDir)..\platform\graphics\egl;$(ProjectDir)..\platform\graphics\surfaces;$(ProjectDir)..\platform\graphics\surfaces\egl;$(ProjectDir)..\platform\graphics\opengl;$(WebKit_Libraries)\include;$(WebKit_Libraries)\include\private;$(WebKit_Libraries)\include\private\JavaScriptCore;$(WebKit_Libraries)\include\sqlite;$(WebKit_Libraries)\include\JavaScriptCore;$(WebKit_Libraries)\include\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>DISABLE_3D_RENDERING;WEBCORE_CONTEXT_MENUS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <PrecompiledHeaderFile>WebCorePrefix.h</PrecompiledHeaderFile>
index 17df36c..67d8c2b 100644 (file)
@@ -58,6 +58,7 @@ xcopy /y /d "%ProjectDir%..\platform\graphics\win\%1\*.h" "%CONFIGURATIONBUILDDI
 xcopy /y /d "%ProjectDir%..\platform\graphics\opentype\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\mock\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\text\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
+xcopy /y /d "%ProjectDir%..\platform\text\icu\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\text\transcoder\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\win\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
 xcopy /y /d "%ProjectDir%..\platform\network\*.h" "%CONFIGURATIONBUILDDIR%\include\WebCore"
index cd27eb1..530d34c 100644 (file)
                7C522D4B15B477E8009B7C95 /* InspectorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C522D4915B477E8009B7C95 /* InspectorOverlay.cpp */; };
                7C5343FC17B74B63004232F0 /* JSMediaQueryListListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C5343FA17B74B63004232F0 /* JSMediaQueryListListener.cpp */; };
                7C5343FD17B74B63004232F0 /* JSMediaQueryListListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C5343FB17B74B63004232F0 /* JSMediaQueryListListener.h */; };
+               7C74D43318823A9300E5ED57 /* UTextProviderLatin1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C74D43118823A9300E5ED57 /* UTextProviderLatin1.cpp */; };
+               7C74D43418823A9300E5ED57 /* UTextProviderLatin1.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C74D43218823A9300E5ED57 /* UTextProviderLatin1.h */; };
+               7C74D43718823B1900E5ED57 /* UTextProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C74D43518823B1900E5ED57 /* UTextProvider.cpp */; };
+               7C74D43818823B1900E5ED57 /* UTextProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C74D43618823B1900E5ED57 /* UTextProvider.h */; };
+               7C74D43B1882400400E5ED57 /* UTextProviderUTF16.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C74D4391882400400E5ED57 /* UTextProviderUTF16.cpp */; };
+               7C74D43C1882400400E5ED57 /* UTextProviderUTF16.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C74D43A1882400400E5ED57 /* UTextProviderUTF16.h */; };
                7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; };
                7CE6CBFB187F370700D46BF5 /* FormatConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */; };
                7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */; };
                7C6136F71710C35200FF4A57 /* InFilesCompiler.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = InFilesCompiler.pm; path = scripts/InFilesCompiler.pm; sourceTree = "<group>"; };
                7C6136F81710C35200FF4A57 /* InFilesParser.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = InFilesParser.pm; path = scripts/InFilesParser.pm; sourceTree = "<group>"; };
                7C6136F91710C35200FF4A57 /* StaticString.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = StaticString.pm; path = scripts/StaticString.pm; sourceTree = "<group>"; };
+               7C74D43118823A9300E5ED57 /* UTextProviderLatin1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTextProviderLatin1.cpp; sourceTree = "<group>"; };
+               7C74D43218823A9300E5ED57 /* UTextProviderLatin1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTextProviderLatin1.h; sourceTree = "<group>"; };
+               7C74D43518823B1900E5ED57 /* UTextProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTextProvider.cpp; sourceTree = "<group>"; };
+               7C74D43618823B1900E5ED57 /* UTextProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTextProvider.h; sourceTree = "<group>"; };
+               7C74D4391882400400E5ED57 /* UTextProviderUTF16.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTextProviderUTF16.cpp; sourceTree = "<group>"; };
+               7C74D43A1882400400E5ED57 /* UTextProviderUTF16.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTextProviderUTF16.h; sourceTree = "<group>"; };
                7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = "<group>"; };
                7CE6CBFA187F370700D46BF5 /* FormatConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatConverter.h; sourceTree = "<group>"; };
                7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatConverter.cpp; sourceTree = "<group>"; };
                        tabWidth = 4;
                        usesTabs = 0;
                };
+               7C74D43018823A4200E5ED57 /* icu */ = {
+                       isa = PBXGroup;
+                       children = (
+                               7C74D43118823A9300E5ED57 /* UTextProviderLatin1.cpp */,
+                               7C74D43218823A9300E5ED57 /* UTextProviderLatin1.h */,
+                               7C74D4391882400400E5ED57 /* UTextProviderUTF16.cpp */,
+                               7C74D43A1882400400E5ED57 /* UTextProviderUTF16.h */,
+                               7C74D43518823B1900E5ED57 /* UTextProvider.cpp */,
+                               7C74D43618823B1900E5ED57 /* UTextProvider.h */,
+                       );
+                       path = icu;
+                       sourceTree = "<group>";
+               };
                7E474E1912494DA900235364 /* ios */ = {
                        isa = PBXGroup;
                        children = (
                                B2B264590D00A77E000ACC1D /* cf */,
                                A516E8B2136E04C00076C3C0 /* ios */,
                                B2C3D9F90D006C1D00EF6F26 /* mac */,
+                               7C74D43018823A4200E5ED57 /* icu */,
                                37C61F0012095C87007A3C67 /* AtomicStringKeyedMRUCache.h */,
                                B2C3D9F20D006C1D00EF6F26 /* BidiContext.cpp */,
                                B2C3D9F30D006C1D00EF6F26 /* BidiContext.h */,
                                D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
                                51AF503616F100F60095B2E8 /* ResourceLoaderTypes.h in Headers */,
                                973E325710883B7C005BC493 /* ResourceLoadNotifier.h in Headers */,
+                               7C74D43418823A9300E5ED57 /* UTextProviderLatin1.h in Headers */,
                                E4295FA412B0614E00D1ACE0 /* ResourceLoadPriority.h in Headers */,
                                D0CE58F9125E4CC200F3F199 /* ResourceLoadScheduler.h in Headers */,
                                07C59B7617F7D0DB000FBCBB /* CapabilityRange.h in Headers */,
                                8A81BF8511DCFD9000DA2B98 /* ResourceLoadTiming.h in Headers */,
+                               7C74D43818823B1900E5ED57 /* UTextProvider.h in Headers */,
                                7EE6846D12D26E3800E79415 /* ResourceRequest.h in Headers */,
                                514C767D0CE923A1007EF3CD /* ResourceRequestBase.h in Headers */,
                                07969DB817D14151007FF842 /* JSRTCIceCandidateEvent.h in Headers */,
                                BCEF444A0E6745E0001C1287 /* StyleGeneratedImage.h in Headers */,
                                A10DC76B14747BAB005E2471 /* StyleGridData.h in Headers */,
                                A110DB9B14F5DF7700A03B93 /* StyleGridItemData.h in Headers */,
+                               7C74D43C1882400400E5ED57 /* UTextProviderUTF16.h in Headers */,
                                BCEF43CF0E673DA1001C1287 /* StyleImage.h in Headers */,
                                BC2273040E82F1E600E7F975 /* StyleInheritedData.h in Headers */,
                                E47127CB163438AE00ED6F5A /* StyleInvalidationAnalysis.h in Headers */,
                                FE16CFD5169D1DED00D3A0C7 /* DatabaseBackendSync.cpp in Sources */,
                                FEBC5F3116BD0CC300659BD3 /* DatabaseBase.cpp in Sources */,
                                97BC6A271505F081001B74AC /* DatabaseContext.cpp in Sources */,
+                               7C74D43318823A9300E5ED57 /* UTextProviderLatin1.cpp in Sources */,
                                FE456F181677D74E005EDDF9 /* DatabaseManager.cpp in Sources */,
                                FEB26D28167A8F2A00FDD26B /* DatabaseServer.cpp in Sources */,
                                FEDEF84116797108000E444A /* DatabaseStrategy.cpp in Sources */,
                                0783228418013ED800999E0C /* MediaStreamAudioSource.cpp in Sources */,
                                2D9A247315B9C2D100D34527 /* DOMDOMSecurityPolicy.mm in Sources */,
                                7694565C1214DB630007CBAE /* DOMDOMTokenList.mm in Sources */,
+                               7C74D43B1882400400E5ED57 /* UTextProviderUTF16.cpp in Sources */,
                                7AABA25914BC613300AA9A11 /* DOMEditor.cpp in Sources */,
                                85ACA9C10A9B5FA500671E90 /* DOMElement.mm in Sources */,
                                85CA96B90A9621A600690CCF /* DOMEntity.mm in Sources */,
                                078E090A17D14CEE00420AA1 /* RTCIceCandidateEvent.cpp in Sources */,
                                A14832C8187F673F00DA63A6 /* WebCoreThread.mm in Sources */,
                                B2227AC40D00BF220071B782 /* SVGTests.cpp in Sources */,
+                               7C74D43718823B1900E5ED57 /* UTextProvider.cpp in Sources */,
                                B2227AC70D00BF220071B782 /* SVGTextContentElement.cpp in Sources */,
                                07969DBB17D14151007FF842 /* JSRTCSessionDescription.cpp in Sources */,
                                B2227ACA0D00BF220071B782 /* SVGTextElement.cpp in Sources */,
index 31c37f7..3c916d6 100644 (file)
@@ -38,3 +38,6 @@
 #include "TextEncodingDetectorICU.cpp"
 #include "TextEncodingRegistry.cpp"
 #include "TextStream.cpp"
+#include "UTextProvider.cpp"
+#include "UTextProviderLatin1.cpp"
+#include "UTextProviderUTF16.cpp"
index 7e0e2d8..7893ef1 100644 (file)
@@ -23,6 +23,8 @@
 #include "TextBreakIterator.h"
 
 #include "LineBreakIteratorPoolICU.h"
+#include "UTextProviderLatin1.h"
+#include "UTextProviderUTF16.h"
 #include <wtf/Atomics.h>
 #include <wtf/text/WTFString.h>
 
@@ -30,8 +32,7 @@ using namespace WTF;
 
 namespace WebCore {
 
-static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator,
-    UBreakIteratorType type, const UChar* string, int length)
+static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator, UBreakIteratorType type, const UChar* string, int length)
 {
     if (!string)
         return 0;
@@ -53,373 +54,11 @@ static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator
     return iterator;
 }
 
-enum TextContext { NoContext, PriorContext, PrimaryContext };
-
-const int textBufferCapacity = 16;
-
-typedef struct {
-    UText text;
-    UChar buffer[textBufferCapacity];
-} UTextWithBuffer;
-
-static inline int64_t textPinIndex(int64_t& index, int64_t limit)
-{
-    if (index < 0)
-        index = 0;
-    else if (index > limit)
-        index = limit;
-    return index;
-}
-
-static inline int64_t textNativeLength(UText* text)
-{
-    return text->a + text->b;
-}
-
-// Relocate pointer from source into destination as required.
-static void textFixPointer(const UText* source, UText* destination, const void*& pointer)
-{
-    if (pointer >= source->pExtra && pointer < static_cast<char*>(source->pExtra) + source->extraSize) {
-        // Pointer references source extra buffer.
-        pointer = static_cast<char*>(destination->pExtra) + (static_cast<const char*>(pointer) - static_cast<const char*>(source->pExtra));
-    } else if (pointer >= source && pointer < reinterpret_cast<const char*>(source) + source->sizeOfStruct) {
-        // Pointer references source text structure, but not source extra buffer.
-        pointer = reinterpret_cast<char*>(destination) + (static_cast<const char*>(pointer) - reinterpret_cast<const char*>(source));
-    }
-}
-
-static UText* textClone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
-{
-    ASSERT_UNUSED(deep, !deep);
-    if (U_FAILURE(*status))
-        return 0;
-    int32_t extraSize = source->extraSize;
-    destination = utext_setup(destination, extraSize, status);
-    if (U_FAILURE(*status))
-        return destination;
-    void* extraNew = destination->pExtra;
-    int32_t flags = destination->flags;
-    int sizeToCopy = std::min(source->sizeOfStruct, destination->sizeOfStruct);
-    memcpy(destination, source, sizeToCopy);
-    destination->pExtra = extraNew;
-    destination->flags = flags;
-    memcpy(destination->pExtra, source->pExtra, extraSize);
-    textFixPointer(source, destination, destination->context);
-    textFixPointer(source, destination, destination->p);
-    textFixPointer(source, destination, destination->q);
-    ASSERT(!destination->r);
-    const void * chunkContents = static_cast<const void*>(destination->chunkContents);
-    textFixPointer(source, destination, chunkContents);
-    destination->chunkContents = static_cast<const UChar*>(chunkContents);
-    return destination;
-}
-
-static int32_t textExtract(UText* text, int64_t start, int64_t limit, UChar* destination, int32_t destinationCapacity, UErrorCode* errorCode)
-{
-    UNUSED_PARAM(text);
-    UNUSED_PARAM(start);
-    UNUSED_PARAM(limit);
-    UNUSED_PARAM(destination);
-    UNUSED_PARAM(destinationCapacity);
-    // In the present context, this text provider is used only with ICU functions
-    // that do not perform an extract operation.
-    ASSERT_NOT_REACHED();
-    *errorCode = U_UNSUPPORTED_ERROR;
-    return 0;
-}
-
-static void textClose(UText* text)
-{
-    text->context = 0;
-}
-
-static inline TextContext textGetContext(const UText* text, int64_t nativeIndex, UBool forward)
-{
-    if (!text->b || nativeIndex > text->b)
-        return PrimaryContext;
-    if (nativeIndex == text->b)
-        return forward ? PrimaryContext : PriorContext;
-    return PriorContext;
-}
-
-static inline TextContext textLatin1GetCurrentContext(const UText* text)
-{
-    if (!text->chunkContents)
-        return NoContext;
-    return text->chunkContents == text->pExtra ? PrimaryContext : PriorContext;
-}
-
-static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(text->chunkContents == text->pExtra);
-    if (forward) {
-        ASSERT(nativeIndex >= text->b && nativeIndex < nativeLength);
-        text->chunkNativeStart = nativeIndex;
-        text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(UChar);
-        if (text->chunkNativeLimit > nativeLength)
-            text->chunkNativeLimit = nativeLength;
-    } else {
-        ASSERT(nativeIndex > text->b && nativeIndex <= nativeLength);
-        text->chunkNativeLimit = nativeIndex;
-        text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(UChar);
-        if (text->chunkNativeStart < text->b)
-            text->chunkNativeStart = text->b;
-    }
-    int64_t length = text->chunkNativeLimit - text->chunkNativeStart;
-    // Ensure chunk length is well defined if computed length exceeds int32_t range.
-    ASSERT(length < std::numeric_limits<int32_t>::max());
-    text->chunkLength = length < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(length) : 0;
-    text->nativeIndexingLimit = text->chunkLength;
-    text->chunkOffset = forward ? 0 : text->chunkLength;
-    StringImpl::copyChars(const_cast<UChar*>(text->chunkContents), static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), static_cast<unsigned>(text->chunkLength));
-}
-
-static void textLatin1SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(!text->chunkContents || text->chunkContents == text->q);
-    text->chunkContents = static_cast<const UChar*>(text->pExtra);
-    textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
-}
-
-static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(text->chunkContents == text->q);
-    ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
-    ASSERT_UNUSED(nativeLength, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
-    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
-    text->chunkNativeStart = 0;
-    text->chunkNativeLimit = text->b;
-    text->chunkLength = text->b;
-    text->nativeIndexingLimit = text->chunkLength;
-    int64_t offset = nativeIndex - text->chunkNativeStart;
-    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
-    ASSERT(offset < std::numeric_limits<int32_t>::max());
-    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
-}
-
-static void textLatin1SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(!text->chunkContents || text->chunkContents == text->pExtra);
-    text->chunkContents = static_cast<const UChar*>(text->q);
-    textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
-}
-
-static inline bool textInChunkOrOutOfRange(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward, UBool& isAccessible)
-{
-    if (forward) {
-        if (nativeIndex >= text->chunkNativeStart && nativeIndex < text->chunkNativeLimit) {
-            int64_t offset = nativeIndex - text->chunkNativeStart;
-            // Ensure chunk offset is well formed if computed offset exceeds int32_t range.
-            ASSERT(offset < std::numeric_limits<int32_t>::max());
-            text->chunkOffset = offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0;
-            isAccessible = TRUE;
-            return true;
-        }
-        if (nativeIndex >= nativeLength && text->chunkNativeLimit == nativeLength) {
-            text->chunkOffset = text->chunkLength;
-            isAccessible = FALSE;
-            return true;
-        }
-    } else {
-        if (nativeIndex > text->chunkNativeStart && nativeIndex <= text->chunkNativeLimit) {
-            int64_t offset = nativeIndex - text->chunkNativeStart;
-            // Ensure chunk offset is well formed if computed offset exceeds int32_t range.
-            ASSERT(offset < std::numeric_limits<int32_t>::max());
-            text->chunkOffset = offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0;
-            isAccessible = TRUE;
-            return true;
-        }
-        if (nativeIndex <= 0 && !text->chunkNativeStart) {
-            text->chunkOffset = 0;
-            isAccessible = FALSE;
-            return true;
-        }
-    }
-    return false;
-}
-
-static UBool textLatin1Access(UText* text, int64_t nativeIndex, UBool forward)
-{
-    if (!text->context)
-        return FALSE;
-    int64_t nativeLength = textNativeLength(text);
-    UBool isAccessible;
-    if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
-        return isAccessible;
-    nativeIndex = textPinIndex(nativeIndex, nativeLength);
-    TextContext currentContext = textLatin1GetCurrentContext(text);
-    TextContext newContext = textGetContext(text, nativeIndex, forward);
-    ASSERT(newContext != NoContext);
-    if (newContext == currentContext) {
-        if (currentContext == PrimaryContext)
-            textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
-        else
-            textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
-    } else if (newContext == PrimaryContext)
-        textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
-    else {
-        ASSERT(newContext == PriorContext);
-        textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
-    }
-    return TRUE;
-}
-
-static const struct UTextFuncs textLatin1Funcs = {
-    sizeof(UTextFuncs),
-    0, 0, 0,
-    textClone,
-    textNativeLength,
-    textLatin1Access,
-    textExtract,
-    0, 0, 0, 0,
-    textClose,
-    0, 0, 0,
-};
-
-static void textInit(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
-{
-    text->pFuncs = funcs;
-    text->providerProperties = 1 << UTEXT_PROVIDER_STABLE_CHUNKS;
-    text->context = string;
-    text->p = string;
-    text->a = length;
-    text->q = priorContext;
-    text->b = priorContextLength;
-}
-
-static UText* textOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
-{
-    if (U_FAILURE(*status))
-        return 0;
-    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
-        *status = U_ILLEGAL_ARGUMENT_ERROR;
-        return 0;
-    }
-    UText* text = utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status);
-    if (U_FAILURE(*status)) {
-        ASSERT(!text);
-        return 0;
-    }
-    textInit(text, &textLatin1Funcs, string, length, priorContext, priorContextLength);
-    return text;
-}
-
-static inline TextContext textUTF16GetCurrentContext(const UText* text)
-{
-    if (!text->chunkContents)
-        return NoContext;
-    return text->chunkContents == text->p ? PrimaryContext : PriorContext;
-}
-
-static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(text->chunkContents == text->p);
-    ASSERT_UNUSED(forward, forward ? nativeIndex >= text->b : nativeIndex > text->b);
-    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
-    text->chunkNativeStart = text->b;
-    text->chunkNativeLimit = nativeLength;
-    int64_t length = text->chunkNativeLimit - text->chunkNativeStart;
-    // Ensure chunk length is well defined if computed length exceeds int32_t range.
-    ASSERT(length < std::numeric_limits<int32_t>::max());
-    text->chunkLength = length < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(length) : 0;
-    text->nativeIndexingLimit = text->chunkLength;
-    int64_t offset = nativeIndex - text->chunkNativeStart;
-    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
-    ASSERT(offset < std::numeric_limits<int32_t>::max());
-    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
-}
-
-static void textUTF16SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(!text->chunkContents || text->chunkContents == text->q);
-    text->chunkContents = static_cast<const UChar*>(text->p);
-    textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
-}
-
-static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(text->chunkContents == text->q);
-    ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
-    ASSERT_UNUSED(nativeLength, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
-    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
-    text->chunkNativeStart = 0;
-    text->chunkNativeLimit = text->b;
-    text->chunkLength = text->b;
-    text->nativeIndexingLimit = text->chunkLength;
-    int64_t offset = nativeIndex - text->chunkNativeStart;
-    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
-    ASSERT(offset < std::numeric_limits<int32_t>::max());
-    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
-}
-
-static void textUTF16SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
-{
-    ASSERT(!text->chunkContents || text->chunkContents == text->p);
-    text->chunkContents = static_cast<const UChar*>(text->q);
-    textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
-}
-
-static UBool textUTF16Access(UText* text, int64_t nativeIndex, UBool forward)
-{
-    if (!text->context)
-        return FALSE;
-    int64_t nativeLength = textNativeLength(text);
-    UBool isAccessible;
-    if (textInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
-        return isAccessible;
-    nativeIndex = textPinIndex(nativeIndex, nativeLength);
-    TextContext currentContext = textUTF16GetCurrentContext(text);
-    TextContext newContext = textGetContext(text, nativeIndex, forward);
-    ASSERT(newContext != NoContext);
-    if (newContext == currentContext) {
-        if (currentContext == PrimaryContext)
-            textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
-        else
-            textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
-    } else if (newContext == PrimaryContext)
-        textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
-    else {
-        ASSERT(newContext == PriorContext);
-        textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
-    }
-    return TRUE;
-}
-
-static const struct UTextFuncs textUTF16Funcs = {
-    sizeof(UTextFuncs),
-    0, 0, 0,
-    textClone,
-    textNativeLength,
-    textUTF16Access,
-    textExtract,
-    0, 0, 0, 0,
-    textClose,
-    0, 0, 0,
-};
-
-static UText* textOpenUTF16(UText* text, const UChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status)
-{
-    if (U_FAILURE(*status))
-        return 0;
-    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
-        *status = U_ILLEGAL_ARGUMENT_ERROR;
-        return 0;
-    }
-    text = utext_setup(text, 0, status);
-    if (U_FAILURE(*status)) {
-        ASSERT(!text);
-        return 0;
-    }
-    textInit(text, &textUTF16Funcs, string, length, priorContext, priorContextLength);
-    return text;
-}
-
 TextBreakIterator* wordBreakIterator(const UChar* string, int length)
 {
     static bool createdWordBreakIterator = false;
     static TextBreakIterator* staticWordBreakIterator;
-    return setUpIterator(createdWordBreakIterator,
-        staticWordBreakIterator, UBRK_WORD, string, length);
+    return setUpIterator(createdWordBreakIterator, staticWordBreakIterator, UBRK_WORD, string, length);
 }
 
 static UText emptyText = UTEXT_INITIALIZER;
@@ -436,7 +75,7 @@ TextBreakIterator* acquireLineBreakIterator(const LChar* string, int length, con
     textLocal.text.pExtra = textLocal.buffer;
 
     UErrorCode openStatus = U_ZERO_ERROR;
-    UText* text = textOpenLatin1(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
+    UText* text = uTextOpenLatin1(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
     if (U_FAILURE(openStatus)) {
         LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
         return 0;
@@ -463,7 +102,7 @@ TextBreakIterator* acquireLineBreakIterator(const UChar* string, int length, con
     UText textLocal = UTEXT_INITIALIZER;
 
     UErrorCode openStatus = U_ZERO_ERROR;
-    UText* text = textOpenUTF16(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
+    UText* text = uTextOpenUTF16(&textLocal, string, length, priorContext, priorContextLength, &openStatus);
     if (U_FAILURE(openStatus)) {
         LOG_ERROR("textOpenUTF16 failed with status %d", openStatus);
         return 0;
@@ -521,8 +160,7 @@ TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
 {
     static bool createdSentenceBreakIterator = false;
     static TextBreakIterator* staticSentenceBreakIterator;
-    return setUpIterator(createdSentenceBreakIterator,
-        staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
+    return setUpIterator(createdSentenceBreakIterator, staticSentenceBreakIterator, UBRK_SENTENCE, string, length);
 }
 
 int textBreakFirst(TextBreakIterator* iterator)
@@ -572,8 +210,7 @@ bool isWordTextBreak(TextBreakIterator* iterator)
 }
 
 #if !PLATFORM(IOS)
-static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator,
-    const char* breakRules, const UChar* string, int length)
+static TextBreakIterator* setUpIteratorWithRules(bool& createdIterator, TextBreakIterator*& iterator, const char* breakRules, const UChar* string, int length)
 {
     if (!string)
         return 0;
diff --git a/Source/WebCore/platform/text/icu/UTextProvider.cpp b/Source/WebCore/platform/text/icu/UTextProvider.cpp
new file mode 100644 (file)
index 0000000..fdaee81
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UTextProvider.h"
+
+#include <string.h>
+
+namespace WebCore {
+
+// Relocate pointer from source into destination as required.
+static inline void fixPointer(const UText* source, UText* destination, const void*& pointer)
+{
+    if (pointer >= source->pExtra && pointer < static_cast<char*>(source->pExtra) + source->extraSize) {
+        // Pointer references source extra buffer.
+        pointer = static_cast<char*>(destination->pExtra) + (static_cast<const char*>(pointer) - static_cast<const char*>(source->pExtra));
+    } else if (pointer >= source && pointer < reinterpret_cast<const char*>(source) + source->sizeOfStruct) {
+        // Pointer references source text structure, but not source extra buffer.
+        pointer = reinterpret_cast<char*>(destination) + (static_cast<const char*>(pointer) - reinterpret_cast<const char*>(source));
+    }
+}
+
+UText* uTextCloneImpl(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+{
+    ASSERT_UNUSED(deep, !deep);
+    if (U_FAILURE(*status))
+        return nullptr;
+    int32_t extraSize = source->extraSize;
+    destination = utext_setup(destination, extraSize, status);
+    if (U_FAILURE(*status))
+        return destination;
+    void* extraNew = destination->pExtra;
+    int32_t flags = destination->flags;
+    int sizeToCopy = std::min(source->sizeOfStruct, destination->sizeOfStruct);
+    memcpy(destination, source, sizeToCopy);
+    destination->pExtra = extraNew;
+    destination->flags = flags;
+    memcpy(destination->pExtra, source->pExtra, extraSize);
+    fixPointer(source, destination, destination->context);
+    fixPointer(source, destination, destination->p);
+    fixPointer(source, destination, destination->q);
+    ASSERT(!destination->r);
+    const void* chunkContents = static_cast<const void*>(destination->chunkContents);
+    fixPointer(source, destination, chunkContents);
+    destination->chunkContents = static_cast<const UChar*>(chunkContents);
+    return destination;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/text/icu/UTextProvider.h b/Source/WebCore/platform/text/icu/UTextProvider.h
new file mode 100644 (file)
index 0000000..d7a74a6
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UTextProvider_h
+#define UTextProvider_h
+
+#include <unicode/utext.h>
+#include <wtf/unicode/Unicode.h>
+
+namespace WebCore {
+
+enum class UTextProviderContext {
+    NoContext,
+    PriorContext,
+    PrimaryContext
+};
+
+inline UTextProviderContext uTextProviderContext(const UText* text, int64_t nativeIndex, UBool forward)
+{
+    if (!text->b || nativeIndex > text->b)
+        return UTextProviderContext::PrimaryContext;
+    if (nativeIndex == text->b)
+        return forward ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
+    return UTextProviderContext::PriorContext;
+}
+
+inline void uTextInitialize(UText* text, const UTextFuncs* funcs, const void* string, unsigned length, const UChar* priorContext, int priorContextLength)
+{
+    text->pFuncs = funcs;
+    text->providerProperties = 1 << UTEXT_PROVIDER_STABLE_CHUNKS;
+    text->context = string;
+    text->p = string;
+    text->a = length;
+    text->q = priorContext;
+    text->b = priorContextLength;
+}
+
+// Shared implementation for the UTextClone function on UTextFuncs.
+
+UText* uTextCloneImpl(UText* destination, const UText* source, UBool deep, UErrorCode* status);
+
+
+// Helpers for the UTextAccess function on UTextFuncs.
+
+inline int64_t uTextAccessPinIndex(int64_t& index, int64_t limit)
+{
+    if (index < 0)
+        index = 0;
+    else if (index > limit)
+        index = limit;
+    return index;
+}
+
+inline bool uTextAccessInChunkOrOutOfRange(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward, UBool& isAccessible)
+{
+    if (forward) {
+        if (nativeIndex >= text->chunkNativeStart && nativeIndex < text->chunkNativeLimit) {
+            int64_t offset = nativeIndex - text->chunkNativeStart;
+            // Ensure chunk offset is well formed if computed offset exceeds int32_t range.
+            ASSERT(offset < std::numeric_limits<int32_t>::max());
+            text->chunkOffset = offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0;
+            isAccessible = TRUE;
+            return true;
+        }
+        if (nativeIndex >= nativeLength && text->chunkNativeLimit == nativeLength) {
+            text->chunkOffset = text->chunkLength;
+            isAccessible = FALSE;
+            return true;
+        }
+    } else {
+        if (nativeIndex > text->chunkNativeStart && nativeIndex <= text->chunkNativeLimit) {
+            int64_t offset = nativeIndex - text->chunkNativeStart;
+            // Ensure chunk offset is well formed if computed offset exceeds int32_t range.
+            ASSERT(offset < std::numeric_limits<int32_t>::max());
+            text->chunkOffset = offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0;
+            isAccessible = TRUE;
+            return true;
+        }
+        if (nativeIndex <= 0 && !text->chunkNativeStart) {
+            text->chunkOffset = 0;
+            isAccessible = FALSE;
+            return true;
+        }
+    }
+    return false;
+}
+
+} // namespace WebCore
+
+#endif // UTextProvider_h
diff --git a/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp b/Source/WebCore/platform/text/icu/UTextProviderLatin1.cpp
new file mode 100644 (file)
index 0000000..13a5056
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UTextProviderLatin1.h"
+
+#include "UTextProvider.h"
+#include <wtf/text/StringImpl.h>
+
+namespace WebCore {
+
+static inline UTextProviderContext textLatin1GetCurrentContext(const UText* text)
+{
+    if (!text->chunkContents)
+        return UTextProviderContext::NoContext;
+    return text->chunkContents == text->pExtra ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
+}
+
+static void textLatin1MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(text->chunkContents == text->pExtra);
+    if (forward) {
+        ASSERT(nativeIndex >= text->b && nativeIndex < nativeLength);
+        text->chunkNativeStart = nativeIndex;
+        text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(UChar);
+        if (text->chunkNativeLimit > nativeLength)
+            text->chunkNativeLimit = nativeLength;
+    } else {
+        ASSERT(nativeIndex > text->b && nativeIndex <= nativeLength);
+        text->chunkNativeLimit = nativeIndex;
+        text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(UChar);
+        if (text->chunkNativeStart < text->b)
+            text->chunkNativeStart = text->b;
+    }
+    int64_t length = text->chunkNativeLimit - text->chunkNativeStart;
+    // Ensure chunk length is well defined if computed length exceeds int32_t range.
+    ASSERT(length < std::numeric_limits<int32_t>::max());
+    text->chunkLength = length < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(length) : 0;
+    text->nativeIndexingLimit = text->chunkLength;
+    text->chunkOffset = forward ? 0 : text->chunkLength;
+    StringImpl::copyChars(const_cast<UChar*>(text->chunkContents), static_cast<const LChar*>(text->p) + (text->chunkNativeStart - text->b), static_cast<unsigned>(text->chunkLength));
+}
+
+static void textLatin1SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(!text->chunkContents || text->chunkContents == text->q);
+    text->chunkContents = static_cast<const UChar*>(text->pExtra);
+    textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+}
+
+static void textLatin1MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(text->chunkContents == text->q);
+    ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
+    ASSERT_UNUSED(nativeLength, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
+    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
+    text->chunkNativeStart = 0;
+    text->chunkNativeLimit = text->b;
+    text->chunkLength = text->b;
+    text->nativeIndexingLimit = text->chunkLength;
+    int64_t offset = nativeIndex - text->chunkNativeStart;
+    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
+    ASSERT(offset < std::numeric_limits<int32_t>::max());
+    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
+}
+
+static void textLatin1SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(!text->chunkContents || text->chunkContents == text->pExtra);
+    text->chunkContents = static_cast<const UChar*>(text->q);
+    textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+}
+
+// -- Begin Latin-1 provider functions --
+
+static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextLatin1NativeLength(UText*); 
+static UBool uTextLatin1Access(UText*, int64_t, UBool); 
+static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*); 
+static void uTextLatin1Close(UText*);
+
+static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+{
+    return uTextCloneImpl(destination, source, deep, status);
+}
+
+static int64_t uTextLatin1NativeLength(UText* text)
+{
+    return text->a + text->b;
+}
+
+static UBool uTextLatin1Access(UText* text, int64_t nativeIndex, UBool forward)
+{
+    if (!text->context)
+        return FALSE;
+    int64_t nativeLength = uTextLatin1NativeLength(text);
+    UBool isAccessible;
+    if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
+        return isAccessible;
+    nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
+    UTextProviderContext currentContext = textLatin1GetCurrentContext(text);
+    UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
+    ASSERT(newContext != UTextProviderContext::NoContext);
+    if (newContext == currentContext) {
+        if (currentContext == UTextProviderContext::PrimaryContext)
+            textLatin1MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+        else
+            textLatin1MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+    } else if (newContext == UTextProviderContext::PrimaryContext)
+        textLatin1SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
+    else {
+        ASSERT(newContext == UTextProviderContext::PriorContext);
+        textLatin1SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
+    }
+    return TRUE;
+}
+
+static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
+{
+    // In the present context, this text provider is used only with ICU functions
+    // that do not perform an extract operation.
+    ASSERT_NOT_REACHED();
+    *errorCode = U_UNSUPPORTED_ERROR;
+    return 0;
+}
+
+static void uTextLatin1Close(UText* text)
+{
+    text->context = 0;
+}
+
+// -- 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)
+{
+    if (U_FAILURE(*status))
+        return 0;
+    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
+        *status = U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+    UText* text = utext_setup(&utWithBuffer->text, sizeof(utWithBuffer->buffer), status);
+    if (U_FAILURE(*status)) {
+        ASSERT(!text);
+        return 0;
+    }
+    uTextInitialize(text, &textLatin1Funcs, string, length, priorContext, priorContextLength);
+    return text;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/text/icu/UTextProviderLatin1.h b/Source/WebCore/platform/text/icu/UTextProviderLatin1.h
new file mode 100644 (file)
index 0000000..6f18240
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UTextProviderLatin1_h
+#define UTextProviderLatin1_h
+
+#include <unicode/utext.h>
+#include <wtf/unicode/Unicode.h>
+
+namespace WebCore {
+
+const int UTextWithBufferInlineCapacity = 16;
+
+struct UTextWithBuffer {
+    UText text;
+    UChar buffer[UTextWithBufferInlineCapacity];
+};
+
+UText* uTextOpenLatin1(UTextWithBuffer* utWithBuffer, const LChar* string, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode* status);
+
+} // namespace WebCore
+
+#endif // UTextProviderLatin1_h
diff --git a/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp b/Source/WebCore/platform/text/icu/UTextProviderUTF16.cpp
new file mode 100644 (file)
index 0000000..06fa866
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UTextProviderUTF16.h"
+
+#include "UTextProvider.h"
+
+namespace WebCore {
+
+static inline UTextProviderContext textUTF16GetCurrentContext(const UText* text)
+{
+    if (!text->chunkContents)
+        return UTextProviderContext::NoContext;
+    return text->chunkContents == text->p ? UTextProviderContext::PrimaryContext : UTextProviderContext::PriorContext;
+}
+
+static void textUTF16MoveInPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(text->chunkContents == text->p);
+    ASSERT_UNUSED(forward, forward ? nativeIndex >= text->b : nativeIndex > text->b);
+    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
+    text->chunkNativeStart = text->b;
+    text->chunkNativeLimit = nativeLength;
+    int64_t length = text->chunkNativeLimit - text->chunkNativeStart;
+    // Ensure chunk length is well defined if computed length exceeds int32_t range.
+    ASSERT(length < std::numeric_limits<int32_t>::max());
+    text->chunkLength = length < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(length) : 0;
+    text->nativeIndexingLimit = text->chunkLength;
+    int64_t offset = nativeIndex - text->chunkNativeStart;
+    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
+    ASSERT(offset < std::numeric_limits<int32_t>::max());
+    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
+}
+
+static void textUTF16SwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(!text->chunkContents || text->chunkContents == text->q);
+    text->chunkContents = static_cast<const UChar*>(text->p);
+    textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+}
+
+static void textUTF16MoveInPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(text->chunkContents == text->q);
+    ASSERT(forward ? nativeIndex < text->b : nativeIndex <= text->b);
+    ASSERT_UNUSED(nativeLength, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
+    ASSERT_UNUSED(forward, forward ? nativeIndex < nativeLength : nativeIndex <= nativeLength);
+    text->chunkNativeStart = 0;
+    text->chunkNativeLimit = text->b;
+    text->chunkLength = text->b;
+    text->nativeIndexingLimit = text->chunkLength;
+    int64_t offset = nativeIndex - text->chunkNativeStart;
+    // Ensure chunk offset is well defined if computed offset exceeds int32_t range or chunk length.
+    ASSERT(offset < std::numeric_limits<int32_t>::max());
+    text->chunkOffset = std::min(offset < std::numeric_limits<int32_t>::max() ? static_cast<int32_t>(offset) : 0, text->chunkLength);
+}
+
+static void textUTF16SwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward)
+{
+    ASSERT(!text->chunkContents || text->chunkContents == text->p);
+    text->chunkContents = static_cast<const UChar*>(text->q);
+    textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+}
+
+// -- Begin UTF-16 provider functions --
+
+static UText* uTextUTF16Clone(UText*, const UText*, UBool, UErrorCode*);
+static int64_t uTextUTF16NativeLength(UText*);
+static UBool uTextUTF16Access(UText*, int64_t, UBool);
+static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*);
+static void uTextUTF16Close(UText*);
+
+static UText* uTextUTF16Clone(UText* destination, const UText* source, UBool deep, UErrorCode* status)
+{
+    return uTextCloneImpl(destination, source, deep, status);
+}
+
+static inline int64_t uTextUTF16NativeLength(UText* text)
+{
+    return text->a + text->b;
+}
+
+static UBool uTextUTF16Access(UText* text, int64_t nativeIndex, UBool forward)
+{
+    if (!text->context)
+        return FALSE;
+    int64_t nativeLength = uTextUTF16NativeLength(text);
+    UBool isAccessible;
+    if (uTextAccessInChunkOrOutOfRange(text, nativeIndex, nativeLength, forward, isAccessible))
+        return isAccessible;
+    nativeIndex = uTextAccessPinIndex(nativeIndex, nativeLength);
+    UTextProviderContext currentContext = textUTF16GetCurrentContext(text);
+    UTextProviderContext newContext = uTextProviderContext(text, nativeIndex, forward);
+    ASSERT(newContext != UTextProviderContext::NoContext);
+    if (newContext == currentContext) {
+        if (currentContext == UTextProviderContext::PrimaryContext)
+            textUTF16MoveInPrimaryContext(text, nativeIndex, nativeLength, forward);
+        else
+            textUTF16MoveInPriorContext(text, nativeIndex, nativeLength, forward);
+    } else if (newContext == UTextProviderContext::PrimaryContext)
+        textUTF16SwitchToPrimaryContext(text, nativeIndex, nativeLength, forward);
+    else {
+        ASSERT(newContext == UTextProviderContext::PriorContext);
+        textUTF16SwitchToPriorContext(text, nativeIndex, nativeLength, forward);
+    }
+    return TRUE;
+}
+
+static int32_t uTextUTF16Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode)
+{
+    // In the present context, this text provider is used only with ICU functions
+    // that do not perform an extract operation.
+    ASSERT_NOT_REACHED();
+    *errorCode = U_UNSUPPORTED_ERROR;
+    return 0;
+}
+
+static void uTextUTF16Close(UText* text)
+{
+    text->context = 0;
+}
+
+// -- 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)
+{
+    if (U_FAILURE(*status))
+        return 0;
+    if (!string || length > static_cast<unsigned>(std::numeric_limits<int32_t>::max())) {
+        *status = U_ILLEGAL_ARGUMENT_ERROR;
+        return 0;
+    }
+    text = utext_setup(text, 0, status);
+    if (U_FAILURE(*status)) {
+        ASSERT(!text);
+        return 0;
+    }
+    uTextInitialize(text, &textUTF16Funcs, string, length, priorContext, priorContextLength);
+    return text;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/text/icu/UTextProviderUTF16.h b/Source/WebCore/platform/text/icu/UTextProviderUTF16.h
new file mode 100644 (file)
index 0000000..9d3c92e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UTextProviderUTF16_h
+#define UTextProviderUTF16_h
+
+#include <unicode/utext.h>
+#include <wtf/unicode/Unicode.h>
+
+namespace WebCore {
+
+UText* uTextOpenUTF16(UText*, const UChar*, unsigned length, const UChar* priorContext, int priorContextLength, UErrorCode*);
+
+} // namespace WebCore
+
+#endif // UTextProviderUTF16_h