2008-02-04 Tony Chang <idealisms@gmail.com>
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2008 05:47:30 +0000 (05:47 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2008 05:47:30 +0000 (05:47 +0000)
        Reviewed by Darin Adler.

        Port the CoreFoundation version of WebCore::isCharacterSmartReplaceExempt
        for other platforms by using ICU directly.

        * GNUmakefile.am: Add SmartReplaceICU.cpp.
        * WebCore.pro: Ditto.
        * WebCoreSources.bkl: Ditto.
        * editing/SmartReplace.cpp: Don't use this empty implementation when ICU is available.
        * editing/SmartReplaceICU.cpp:
        (getSmartSet):
        (WebCore::isCharacterSmartReplaceExempt):

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

WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.pro
WebCore/WebCoreSources.bkl
WebCore/editing/SmartReplace.cpp
WebCore/editing/SmartReplaceICU.cpp [new file with mode: 0644]

index ccba48d47744bbe470bf33482713be2236e058fb..5744a37144dc588ef6383826bb154a39b370d2e3 100644 (file)
@@ -1,3 +1,18 @@
+2008-02-04  Tony Chang  <idealisms@gmail.com>
+
+        Reviewed by Darin Adler.
+
+        Port the CoreFoundation version of WebCore::isCharacterSmartReplaceExempt
+        for other platforms by using ICU directly.
+
+        * GNUmakefile.am: Add SmartReplaceICU.cpp.
+        * WebCore.pro: Ditto.
+        * WebCoreSources.bkl: Ditto.
+        * editing/SmartReplace.cpp: Don't use this empty implementation when ICU is available.
+        * editing/SmartReplaceICU.cpp:
+        (getSmartSet):
+        (WebCore::isCharacterSmartReplaceExempt):
+
 2008-02-04  Robert Sesek  <rsesek@bluestatic.org>
 
         Reviewed by Darin Adler.
index ace46365e7a7efc65b8ae9c1a25af2619a489a5d..450e9ebe3de02f13644a90ca85719f1467ba4195 100644 (file)
@@ -647,6 +647,7 @@ webcore_sources += \
        WebCore/editing/Selection.cpp \
        WebCore/editing/SetNodeAttributeCommand.cpp \
        WebCore/editing/SmartReplace.cpp \
+       WebCore/editing/SmartReplaceICU.cpp \
        WebCore/editing/SplitElementCommand.cpp \
        WebCore/editing/SplitTextNodeCommand.cpp \
        WebCore/editing/SplitTextNodeContainingElementCommand.cpp \
index a3e133ee87935bb6a6d906ae24b8f23af56847c8..1dfc1584720e0a407f9d624baa1958d942e43582 100644 (file)
@@ -579,6 +579,7 @@ SOURCES += \
     editing/Selection.cpp \
     editing/SetNodeAttributeCommand.cpp \
     editing/SmartReplace.cpp \
+    editing/SmartReplaceICU.cpp \
     editing/SplitElementCommand.cpp \
     editing/SplitTextNodeCommand.cpp \
     editing/SplitTextNodeContainingElementCommand.cpp \
index 27e06b7b1ccbf0792e33b5f41102ee6e4e8189d6..750e3ac7ababccb5b2cad26c4ad01576e235813d 100644 (file)
@@ -391,6 +391,7 @@ This file contains the list of files needed to build WebCore.
         editing/Selection.cpp
         editing/SelectionController.cpp
         editing/SmartReplace.cpp
+        editing/SmartReplaceICU.cpp
         editing/SetNodeAttributeCommand.cpp
         editing/SplitElementCommand.cpp
         editing/SplitTextNodeCommand.cpp
index bf2a4762133ac7616d51f5b9a2e9f0b0572018b2..c5f52403a2286bdcfd4fb3ae3f074090c6d9fa61 100644 (file)
@@ -29,7 +29,7 @@
 #include "config.h"
 #include "SmartReplace.h"
 
-#if !PLATFORM(CF)
+#if !PLATFORM(CF) && !USE(ICU_UNICODE)
 
 namespace WebCore {
 
diff --git a/WebCore/editing/SmartReplaceICU.cpp b/WebCore/editing/SmartReplaceICU.cpp
new file mode 100644 (file)
index 0000000..01194a5
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2008 Tony Chang <idealisms@gmail.com>
+ *
+ * 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. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "SmartReplace.h"
+
+#include "Logging.h"
+#if !PLATFORM(CF) && USE(ICU_UNICODE)
+#include <unicode/uset.h>
+
+// This is mostly a port of the code in WebCore/editing/SmartReplaceCF.cpp
+// except we use icu in place of CoreFoundations character classes.
+static USet* getSmartSet(bool isPreviousCharacter)
+{
+    static USet* preSmartSet = NULL; 
+    static USet* postSmartSet = NULL;
+    USet* smartSet = isPreviousCharacter ? preSmartSet : postSmartSet;
+    if (!smartSet) {
+        // Whitespace and newline (kCFCharacterSetWhitespaceAndNewline)
+        UErrorCode ec = U_ZERO_ERROR;
+        smartSet = uset_openPattern(L"[[:WSpace:] [\\u000A\\u000B\\u000C\\u000D\\u0085]]", -1, &ec);
+        ASSERT(U_SUCCESS(ec));
+
+        // CJK ranges
+        uset_addRange(smartSet, 0x1100, 0x1100 + 256); // Hangul Jamo (0x1100 - 0x11FF)
+        uset_addRange(smartSet, 0x2E80, 0x2E80 + 352); // CJK & Kangxi Radicals (0x2E80 - 0x2FDF)
+        uset_addRange(smartSet, 0x2FF0, 0x2FF0 + 464); // Ideograph Descriptions, CJK Symbols, Hiragana, Katakana, Bopomofo, Hangul Compatibility Jamo, Kanbun, & Bopomofo Ext (0x2FF0 - 0x31BF)
+        uset_addRange(smartSet, 0x3200, 0x3200 + 29392); // Enclosed CJK, CJK Ideographs (Uni Han & Ext A), & Yi (0x3200 - 0xA4CF)
+        uset_addRange(smartSet, 0xAC00, 0xAC00 + 11183); // Hangul Syllables (0xAC00 - 0xD7AF)
+        uset_addRange(smartSet, 0xF900, 0xF900 + 352); // CJK Compatibility Ideographs (0xF900 - 0xFA5F)
+        uset_addRange(smartSet, 0xFE30, 0xFE30 + 32); // CJK Compatibility From (0xFE30 - 0xFE4F)
+        uset_addRange(smartSet, 0xFF00, 0xFF00 + 240); // Half/Full Width Form (0xFF00 - 0xFFEF)
+        uset_addRange(smartSet, 0x20000, 0x20000 + 0xA6D7); // CJK Ideograph Exntension B
+        uset_addRange(smartSet, 0x2F800, 0x2F800 + 0x021E); // CJK Compatibility Ideographs (0x2F800 - 0x2FA1D)
+
+        if (isPreviousCharacter) {
+            uset_addAllCodePoints(smartSet, L"([\"\'#$/-`{", -1);
+
+            preSmartSet = smartSet;
+        } else {
+            uset_addAllCodePoints(smartSet, L")].,;:?\'!\"%*-/}", -1);
+
+            // Punctuation (kCFCharacterSetPunctuation)
+            UErrorCode ec = U_ZERO_ERROR;
+            USet* icuPunct = uset_openPattern(L"[:P:]", -1, &ec);
+            ASSERT(U_SUCCESS(ec));
+            uset_addAll(smartSet, icuPunct);
+            uset_close(icuPunct);
+
+            postSmartSet = smartSet;
+        }
+    }
+    return smartSet;
+}
+
+namespace WebCore {
+
+bool isCharacterSmartReplaceExempt(UChar32 c, bool isPreviousCharacter)
+{
+    return uset_contains(getSmartSet(isPreviousCharacter), c);
+}
+
+}
+
+#endif // !PLATFORM(CF) && USE(ICU_UNICODE)