summaryrefslogtreecommitdiff
path: root/Source/WebCore/editing/SmartReplace.cpp
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-08-25 19:20:41 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-02-02 12:30:55 +0000
commit6882a04fb36642862b11efe514251d32070c3d65 (patch)
treeb7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebCore/editing/SmartReplace.cpp
parentab6df191029eeeb0b0f16f127d553265659f739e (diff)
downloadqtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/editing/SmartReplace.cpp')
-rw-r--r--Source/WebCore/editing/SmartReplace.cpp66
1 files changed, 63 insertions, 3 deletions
diff --git a/Source/WebCore/editing/SmartReplace.cpp b/Source/WebCore/editing/SmartReplace.cpp
index 7b8ca4564..0b4764cc0 100644
--- a/Source/WebCore/editing/SmartReplace.cpp
+++ b/Source/WebCore/editing/SmartReplace.cpp
@@ -1,5 +1,6 @@
/*
* 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
@@ -10,7 +11,7 @@
* 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
+ * 3. Neither the name of Apple 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.
*
@@ -29,13 +30,72 @@
#include "config.h"
#include "SmartReplace.h"
-#if !USE(CF) && !USE(ICU_UNICODE)
+#if !USE(CF)
+
+#include <unicode/uset.h>
+#include <wtf/Assertions.h>
+#include <wtf/text/StringView.h>
namespace WebCore {
+static void addAllCodePoints(USet* smartSet, const String& string)
+{
+ for (size_t i = 0; i < string.length(); i++)
+ uset_add(smartSet, string[i]);
+}
+
+// This is mostly a port of the code in WebCore/editing/SmartReplaceCF.cpp
+// except we use ICU instead of CoreFoundation character classes.
+static USet* getSmartSet(bool isPreviousCharacter)
+{
+ static USet* preSmartSet = nullptr;
+ static USet* postSmartSet = nullptr;
+ USet* smartSet = isPreviousCharacter ? preSmartSet : postSmartSet;
+ if (!smartSet) {
+ // Whitespace and newline (kCFCharacterSetWhitespaceAndNewline)
+ UErrorCode ec = U_ZERO_ERROR;
+ String whitespaceAndNewline = ASCIILiteral("[[:WSpace:] [\\u000A\\u000B\\u000C\\u000D\\u0085]]");
+ smartSet = uset_openPattern(StringView(whitespaceAndNewline).upconvertedCharacters(), whitespaceAndNewline.length(), &ec);
+ ASSERT(U_SUCCESS(ec));
+
+ // CJK ranges
+ // FIXME: Looks like all these ranges include one extra character past the end.
+ 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) {
+ // FIXME: Silly to convert this to a WTF::String just to loop through the characters.
+ addAllCodePoints(smartSet, ASCIILiteral("([\"\'#$/-`{"));
+ preSmartSet = smartSet;
+ } else {
+ // FIXME: Silly to convert this to a WTF::String just to loop through the characters.
+ addAllCodePoints(smartSet, ASCIILiteral(")].,;:?\'!\"%*-/}"));
+
+ // Punctuation (kCFCharacterSetPunctuation)
+ UErrorCode ec = U_ZERO_ERROR;
+ String punctuationClass = ASCIILiteral("[:P:]");
+ USet* icuPunct = uset_openPattern(StringView(punctuationClass).upconvertedCharacters(), punctuationClass.length(), &ec);
+ ASSERT(U_SUCCESS(ec));
+ uset_addAll(smartSet, icuPunct);
+ uset_close(icuPunct);
+
+ postSmartSet = smartSet;
+ }
+ }
+ return smartSet;
+}
+
bool isCharacterSmartReplaceExempt(UChar32 c, bool isPreviousCharacter)
{
- return false;
+ return uset_contains(getSmartSet(isPreviousCharacter), c);
}
}