diff options
author | Ben Murdoch <benm@google.com> | 2010-08-11 14:44:44 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-12 19:15:41 +0100 |
commit | dd8bb3de4f353a81954234999f1fea748aee2ea9 (patch) | |
tree | 729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /WebCore/platform/text | |
parent | f3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff) | |
download | external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2 |
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'WebCore/platform/text')
25 files changed, 285 insertions, 161 deletions
diff --git a/WebCore/platform/text/AtomicStringHash.h b/WebCore/platform/text/AtomicStringHash.h index 67a45de..d13332b 100644 --- a/WebCore/platform/text/AtomicStringHash.h +++ b/WebCore/platform/text/AtomicStringHash.h @@ -53,10 +53,10 @@ namespace WebCore { namespace WTF { // WebCore::AtomicStringHash is the default hash for AtomicString - template<> struct HashTraits<WebCore::AtomicString> : GenericHashTraits<WebCore::AtomicString> { + template<> struct HashTraits<WTF::AtomicString> : GenericHashTraits<WTF::AtomicString> { static const bool emptyValueIsZero = true; - static void constructDeletedValue(WebCore::AtomicString& slot) { new (&slot) WebCore::AtomicString(HashTableDeletedValue); } - static bool isDeletedValue(const WebCore::AtomicString& slot) { return slot.isHashTableDeletedValue(); } + static void constructDeletedValue(WTF::AtomicString& slot) { new (&slot) WTF::AtomicString(HashTableDeletedValue); } + static bool isDeletedValue(const WTF::AtomicString& slot) { return slot.isHashTableDeletedValue(); } }; } diff --git a/WebCore/platform/text/AtomicStringKeyedMRUCache.h b/WebCore/platform/text/AtomicStringKeyedMRUCache.h new file mode 100644 index 0000000..a47585a --- /dev/null +++ b/WebCore/platform/text/AtomicStringKeyedMRUCache.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 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 AtomicStringKeyedMRUCache_h +#define AtomicStringKeyedMRUCache_h + +namespace WebCore { + +template<typename T, size_t capacity = 4> +class AtomicStringKeyedMRUCache { +public: + T get(const AtomicString& key) + { + if (key.isNull()) { + DEFINE_STATIC_LOCAL(T, valueForNull, (createValueForNullKey())); + return valueForNull; + } + + for (size_t i = 0; i < m_cache.size(); ++i) { + if (m_cache[i].first == key) { + size_t foundIndex = i; + if (foundIndex + 1 < m_cache.size()) { + Entry entry = m_cache[foundIndex]; + m_cache.remove(foundIndex); + foundIndex = m_cache.size(); + m_cache.append(entry); + } + return m_cache[foundIndex].second; + } + } + if (m_cache.size() == capacity) + m_cache.remove(0); + + m_cache.append(std::make_pair(key, createValueForKey(key))); + return m_cache.last().second; + } + +private: + T createValueForNullKey(); + T createValueForKey(const AtomicString&); + + typedef pair<AtomicString, T> Entry; + typedef Vector<Entry, capacity> Cache; + Cache m_cache; +}; + +} + +#endif // AtomicStringKeyedMRUCache_h diff --git a/WebCore/platform/text/Hyphenation.cpp b/WebCore/platform/text/Hyphenation.cpp index 8ef5a25..89f6438 100644 --- a/WebCore/platform/text/Hyphenation.cpp +++ b/WebCore/platform/text/Hyphenation.cpp @@ -30,9 +30,14 @@ namespace WebCore { -size_t lastHyphenLocation(const UChar* /* characters */, size_t /* length */, size_t /* beforeIndex */) +bool canHyphenate(const AtomicString& /* localeIdentifier */) { - notImplemented(); + return false; +} + +size_t lastHyphenLocation(const UChar* /* characters */, size_t /* length */, size_t /* beforeIndex */, const AtomicString& /* localeIdentifier */) +{ + ASSERT_NOT_REACHED(); return 0; } diff --git a/WebCore/platform/text/Hyphenation.h b/WebCore/platform/text/Hyphenation.h index dbcbe69..a99bff0 100644 --- a/WebCore/platform/text/Hyphenation.h +++ b/WebCore/platform/text/Hyphenation.h @@ -26,11 +26,13 @@ #ifndef Hyphenation_h #define Hyphenation_h +#include <wtf/Forward.h> #include <wtf/unicode/Unicode.h> namespace WebCore { -size_t lastHyphenLocation(const UChar*, size_t length, size_t beforeIndex); +bool canHyphenate(const AtomicString& localeIdentifier); +size_t lastHyphenLocation(const UChar*, size_t length, size_t beforeIndex, const AtomicString& localeIdentifier); } // namespace WebCore diff --git a/WebCore/platform/text/LineEnding.h b/WebCore/platform/text/LineEnding.h index 9c3e2aa..ab8d6ee 100644 --- a/WebCore/platform/text/LineEnding.h +++ b/WebCore/platform/text/LineEnding.h @@ -32,6 +32,8 @@ #ifndef LineEnding_h #define LineEnding_h +#include <wtf/Forward.h> + namespace WTF { class CString; } diff --git a/WebCore/platform/text/SegmentedString.h b/WebCore/platform/text/SegmentedString.h index 747d426..1d3098d 100644 --- a/WebCore/platform/text/SegmentedString.h +++ b/WebCore/platform/text/SegmentedString.h @@ -38,8 +38,6 @@ public: { } - SegmentedSubstring(const UChar* str, int length) : m_length(length), m_current(length == 0 ? 0 : str), m_doNotExcludeLineNumbers(true) {} - void clear() { m_length = 0; m_current = 0; } bool excludeLineNumbers() const { return !m_doNotExcludeLineNumbers; } @@ -72,8 +70,6 @@ class SegmentedString { public: SegmentedString() : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false), m_closed(false) {} - SegmentedString(const UChar* str, int length) : m_pushedChar1(0), m_pushedChar2(0) - , m_currentString(str, length), m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {} SegmentedString(const String& str) : m_pushedChar1(0), m_pushedChar2(0), m_currentString(str) , m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {} diff --git a/WebCore/platform/text/StringBuffer.h b/WebCore/platform/text/StringBuffer.h index 353a44a..3a753b4 100644 --- a/WebCore/platform/text/StringBuffer.h +++ b/WebCore/platform/text/StringBuffer.h @@ -26,52 +26,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef StringBuffer_h -#define StringBuffer_h +#ifndef WebCoreStringBuffer_h +#define WebCoreStringBuffer_h -#include <wtf/Assertions.h> -#include <wtf/Noncopyable.h> -#include <wtf/unicode/Unicode.h> +// FIXME: remove this header, use the forward from wtf directly. +#include <wtf/text/StringBuffer.h> -namespace WebCore { - -class StringBuffer : public Noncopyable { -public: - explicit StringBuffer(unsigned length) - : m_length(length) - , m_data(static_cast<UChar*>(fastMalloc(length * sizeof(UChar)))) - { - } - ~StringBuffer() - { - fastFree(m_data); - } - - void shrink(unsigned newLength) - { - ASSERT(newLength <= m_length); - m_length = newLength; - } - - void resize(unsigned newLength) - { - if (newLength > m_length) - m_data = static_cast<UChar*>(fastRealloc(m_data, newLength * sizeof(UChar))); - m_length = newLength; - } - - unsigned length() const { return m_length; } - UChar* characters() { return m_data; } - - UChar& operator[](unsigned i) { ASSERT(i < m_length); return m_data[i]; } - - UChar* release() { UChar* data = m_data; m_data = 0; return data; } - -private: - unsigned m_length; - UChar* m_data; -}; - -} - -#endif +#endif // StringBuffer_h diff --git a/WebCore/platform/text/StringBuilder.cpp b/WebCore/platform/text/StringBuilder.cpp index 3e34981..213daab 100644 --- a/WebCore/platform/text/StringBuilder.cpp +++ b/WebCore/platform/text/StringBuilder.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -67,7 +68,7 @@ void StringBuilder::append(char c) m_strings.append(String(&c, 1)); } -String StringBuilder::toString() const +String StringBuilder::toString(ConcatMode mode) const { if (isNull()) return String(); @@ -80,17 +81,37 @@ String StringBuilder::toString() const return m_strings[0]; UChar* buffer; - String result = String::createUninitialized(m_totalLength, buffer); + unsigned totalLength = m_totalLength; + if (mode == ConcatAddingSpacesBetweenIndividualStrings) + totalLength += count - 1; + String result = String::createUninitialized(totalLength, buffer); UChar* p = buffer; - for (unsigned i = 0; i < count; ++i) { - StringImpl* string = m_strings[i].impl(); - unsigned length = string->length(); - memcpy(p, string->characters(), length * 2); - p += length; - } - ASSERT(p == m_totalLength + buffer); + // We could handle both Concat modes in a single for loop, not doing that for performance reasons. + if (mode == ConcatUnaltered) { + for (unsigned i = 0; i < count; ++i) { + StringImpl* string = m_strings[i].impl(); + unsigned length = string->length(); + memcpy(p, string->characters(), length * 2); + p += length; + } + } else { + ASSERT(mode == ConcatAddingSpacesBetweenIndividualStrings); + for (unsigned i = 0; i < count; ++i) { + StringImpl* string = m_strings[i].impl(); + unsigned length = string->length(); + memcpy(p, string->characters(), length * 2); + p += length; + + // Add space after string before the start of the next string, if we're not processing the last string. + if (i < count - 1) { + *p = ' '; + ++p; + } + } + } + ASSERT(p == totalLength + buffer); return result; } diff --git a/WebCore/platform/text/StringBuilder.h b/WebCore/platform/text/StringBuilder.h index 7f72fbf..72adfa7 100644 --- a/WebCore/platform/text/StringBuilder.h +++ b/WebCore/platform/text/StringBuilder.h @@ -33,27 +33,36 @@ namespace WebCore { - class StringBuilder { - public: - StringBuilder() : m_totalLength(UINT_MAX) {} +enum ConcatMode { + ConcatUnaltered, + ConcatAddingSpacesBetweenIndividualStrings +}; - void setNonNull() { if (m_totalLength == UINT_MAX) m_totalLength = 0; } +class StringBuilder { +public: + StringBuilder() : m_totalLength(UINT_MAX) {} - void append(const String&); - void append(UChar); - void append(char); - - void clear(); - unsigned length() const; + void setNonNull() + { + if (m_totalLength == UINT_MAX) + m_totalLength = 0; + } - String toString() const; + void append(const String&); + void append(UChar); + void append(char); + + void clear(); + unsigned length() const; - private: - bool isNull() const { return m_totalLength == UINT_MAX; } + String toString(ConcatMode mode = ConcatUnaltered) const; - unsigned m_totalLength; - Vector<String, 16> m_strings; - }; +private: + bool isNull() const { return m_totalLength == UINT_MAX; } + + unsigned m_totalLength; + Vector<String, 16> m_strings; +}; } diff --git a/WebCore/platform/text/TextCodec.h b/WebCore/platform/text/TextCodec.h index 591e3a6..c6af38a 100644 --- a/WebCore/platform/text/TextCodec.h +++ b/WebCore/platform/text/TextCodec.h @@ -28,6 +28,7 @@ #define TextCodec_h #include <memory> +#include <wtf/Forward.h> #include <wtf/Noncopyable.h> #include <wtf/PassOwnPtr.h> #include <wtf/Vector.h> @@ -67,7 +68,7 @@ namespace WebCore { } virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError) = 0; - virtual WTF::CString encode(const UChar*, size_t length, UnencodableHandling) = 0; + virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0; // Fills a null-terminated string representation of the given // unencodable character into the given replacement buffer. diff --git a/WebCore/platform/text/TextCodecICU.cpp b/WebCore/platform/text/TextCodecICU.cpp index 56a4393..6a579f9 100644 --- a/WebCore/platform/text/TextCodecICU.cpp +++ b/WebCore/platform/text/TextCodecICU.cpp @@ -70,10 +70,6 @@ void TextCodecICU::registerBaseCodecs(TextCodecRegistrar registrar) registrar("UTF-8", newTextCodecICU, 0); } -// FIXME: Registering all the encodings we get from ucnv_getAvailableName -// includes encodings we don't want or need. For example, all -// the encodings with commas and version numbers. - void TextCodecICU::registerExtendedEncodingNames(EncodingNameRegistrar registrar) { // We register Hebrew with logical ordering using a separate name. @@ -136,41 +132,62 @@ void TextCodecICU::registerExtendedEncodingNames(EncodingNameRegistrar registrar // table in WebKit on Macintosh that don't seem to be present in ICU. // Perhaps we can prove these are not used on the web and remove them. // Or perhaps we can get them added to ICU. - registrar("xmacroman", "macintosh"); - registrar("xmacukrainian", "x-mac-cyrillic"); - registrar("cnbig5", "Big5"); - registrar("xxbig5", "Big5"); - registrar("cngb", "GBK"); + registrar("x-mac-roman", "macintosh"); + registrar("x-mac-ukrainian", "x-mac-cyrillic"); + registrar("cn-big5", "Big5"); + registrar("x-x-big5", "Big5"); + registrar("cn-gb", "GBK"); registrar("csgb231280", "GBK"); - registrar("xeuccn", "GBK"); - registrar("xgbk", "GBK"); - registrar("csISO88598I", "ISO_8859-8-I"); + registrar("x-euc-cn", "GBK"); + registrar("x-gbk", "GBK"); + registrar("csISO88598I", "ISO-8859-8-I"); registrar("koi", "KOI8-R"); registrar("logical", "ISO-8859-8-I"); registrar("unicode11utf8", "UTF-8"); registrar("unicode20utf8", "UTF-8"); - registrar("xunicode20utf8", "UTF-8"); + registrar("x-unicode20utf8", "UTF-8"); registrar("visual", "ISO-8859-8"); registrar("winarabic", "windows-1256"); registrar("winbaltic", "windows-1257"); registrar("wincyrillic", "windows-1251"); - registrar("iso885911", "windows-874"); - registrar("dos874", "windows-874"); + registrar("iso-8859-11", "windows-874"); + registrar("iso8859-11", "windows-874"); + registrar("dos-874", "windows-874"); registrar("wingreek", "windows-1253"); registrar("winhebrew", "windows-1255"); registrar("winlatin2", "windows-1250"); registrar("winturkish", "windows-1254"); registrar("winvietnamese", "windows-1258"); - registrar("xcp1250", "windows-1250"); - registrar("xcp1251", "windows-1251"); - registrar("xeuc", "EUC-JP"); - registrar("xwindows949", "windows-949"); - registrar("xuhc", "windows-949"); + registrar("x-cp1250", "windows-1250"); + registrar("x-cp1251", "windows-1251"); + registrar("x-euc", "EUC-JP"); + registrar("x-windows-949", "windows-949"); + registrar("x-uhc", "windows-949"); + registrar("utf8", "UTF-8"); + registrar("shift-jis", "Shift_JIS"); // These aliases are present in modern versions of ICU, but use different codecs, and have no standard names. // They are not present in ICU 3.2. - registrar("dos720", "cp864"); + registrar("dos-720", "cp864"); registrar("jis7", "ISO-2022-JP"); + + // Alternative spelling of ISO encoding names. + registrar("ISO8859-1", "ISO-8859-1"); + registrar("ISO8859-2", "ISO-8859-2"); + registrar("ISO8859-3", "ISO-8859-3"); + registrar("ISO8859-4", "ISO-8859-4"); + registrar("ISO8859-5", "ISO-8859-5"); + registrar("ISO8859-6", "ISO-8859-6"); + registrar("ISO8859-7", "ISO-8859-7"); + registrar("ISO8859-8", "ISO-8859-8"); + registrar("ISO8859-8-I", "ISO-8859-8-I"); + registrar("ISO8859-9", "ISO-8859-9"); + registrar("ISO8859-10", "ISO-8859-10"); + registrar("ISO8859-13", "ISO-8859-13"); + registrar("ISO8859-14", "ISO-8859-14"); + registrar("ISO8859-15", "ISO-8859-15"); + // Not registering ISO8859-16, because Firefox (as of version 3.6.6) doesn't know this particular alias, + // and because older versions of ICU don't support ISO-8859-16 encoding at all. } void TextCodecICU::registerExtendedCodecs(TextCodecRegistrar registrar) diff --git a/WebCore/platform/text/TextCodecLatin1.cpp b/WebCore/platform/text/TextCodecLatin1.cpp index 55b20e8..1e9385d 100644 --- a/WebCore/platform/text/TextCodecLatin1.cpp +++ b/WebCore/platform/text/TextCodecLatin1.cpp @@ -79,7 +79,6 @@ void TextCodecLatin1::registerEncodingNames(EncodingNameRegistrar registrar) registrar("ibm-1252", "windows-1252"); registrar("ibm-1252_P100-2000", "windows-1252"); - registrar("8859-1", "ISO-8859-1"); registrar("CP819", "ISO-8859-1"); registrar("IBM819", "ISO-8859-1"); registrar("csISOLatin1", "ISO-8859-1"); diff --git a/WebCore/platform/text/TextEncoding.cpp b/WebCore/platform/text/TextEncoding.cpp index 0a997a2..29ae170 100644 --- a/WebCore/platform/text/TextEncoding.cpp +++ b/WebCore/platform/text/TextEncoding.cpp @@ -248,7 +248,7 @@ const TextEncoding& ASCIIEncoding() const TextEncoding& Latin1Encoding() { - static TextEncoding globalLatin1Encoding("Latin-1"); + static TextEncoding globalLatin1Encoding("latin1"); return globalLatin1Encoding; } diff --git a/WebCore/platform/text/TextEncoding.h b/WebCore/platform/text/TextEncoding.h index 3429bb5..675625b 100644 --- a/WebCore/platform/text/TextEncoding.h +++ b/WebCore/platform/text/TextEncoding.h @@ -27,17 +27,11 @@ #define TextEncoding_h #include "TextCodec.h" +#include <wtf/Forward.h> #include <wtf/unicode/Unicode.h> -namespace WTF { -class CString; -} -using WTF::CString; - namespace WebCore { - class String; - class TextEncoding { public: TextEncoding() : m_name(0) { } @@ -75,7 +69,7 @@ namespace WebCore { return decode(str, length, false, ignored); } String decode(const char*, size_t length, bool stopOnError, bool& sawError) const; - WTF::CString encode(const UChar*, size_t length, UnencodableHandling) const; + CString encode(const UChar*, size_t length, UnencodableHandling) const; UChar backslashAsCurrencySymbol() const; diff --git a/WebCore/platform/text/TextEncodingRegistry.cpp b/WebCore/platform/text/TextEncodingRegistry.cpp index 6ecc36f..40fcdc5 100644 --- a/WebCore/platform/text/TextEncodingRegistry.cpp +++ b/WebCore/platform/text/TextEncodingRegistry.cpp @@ -61,10 +61,7 @@ namespace WebCore { const size_t maxEncodingNameLength = 63; -// Hash for all-ASCII strings that does case folding and skips any characters -// that are not alphanumeric. If passed any non-ASCII characters, depends on -// the behavior of isalnum -- if that returns false as it does on OS X, then -// it will properly skip those characters too. +// Hash for all-ASCII strings that does case folding. struct TextEncodingNameHash { static bool equal(const char* s1, const char* s2) @@ -72,12 +69,8 @@ struct TextEncodingNameHash { char c1; char c2; do { - do - c1 = *s1++; - while (c1 && !isASCIIAlphanumeric(c1)); - do - c2 = *s2++; - while (c2 && !isASCIIAlphanumeric(c2)); + c1 = *s1++; + c2 = *s2++; if (toASCIILower(c1) != toASCIILower(c2)) return false; } while (c1 && c2); @@ -91,16 +84,13 @@ struct TextEncodingNameHash { { unsigned h = WTF::stringHashingStartValue; for (;;) { - char c; - do { - c = *s++; - if (!c) { - h += (h << 3); - h ^= (h >> 11); - h += (h << 15); - return h; - } - } while (!isASCIIAlphanumeric(c)); + char c = *s++; + if (!c) { + h += (h << 3); + h ^= (h >> 11); + h += (h << 15); + return h; + } h += toASCIILower(c); h += (h << 10); h ^= (h >> 6); @@ -154,15 +144,30 @@ static void checkExistingName(const char* alias, const char* atomicName) && strcmp(oldAtomicName, "ISO-8859-8-I") == 0 && strcasecmp(atomicName, "iso-8859-8") == 0) return; - LOG_ERROR("alias %s maps to %s already, but someone is trying to make it map to %s", - alias, oldAtomicName, atomicName); + LOG_ERROR("alias %s maps to %s already, but someone is trying to make it map to %s", alias, oldAtomicName, atomicName); } #endif +static bool isUndesiredAlias(const char* alias) +{ + // Reject aliases with version numbers that are supported by some back-ends (such as "ISO_2022,locale=ja,version=0" in ICU). + for (const char* p = alias; *p; ++p) { + if (*p == ',') + return true; + } + // 8859_1 is known to (at least) ICU, but other browsers don't support this name - and having it caused a compatibility + // problem, see bug 43554. + if (0 == strcmp(alias, "8859_1")) + return true; + return false; +} + static void addToTextEncodingNameMap(const char* alias, const char* name) { ASSERT(strlen(alias) <= maxEncodingNameLength); + if (isUndesiredAlias(alias)) + return; const char* atomicName = textEncodingNameMap->get(name); ASSERT(strcmp(alias, name) == 0 || atomicName); if (!atomicName) @@ -300,11 +305,9 @@ const char* atomicCanonicalTextEncodingName(const UChar* characters, size_t leng size_t j = 0; for (size_t i = 0; i < length; ++i) { UChar c = characters[i]; - if (isASCIIAlphanumeric(c)) { - if (j == maxEncodingNameLength) - return 0; - buffer[j++] = c; - } + if (j == maxEncodingNameLength) + return 0; + buffer[j++] = c; } buffer[j] = 0; return atomicCanonicalTextEncodingName(buffer); diff --git a/WebCore/platform/text/TextStream.h b/WebCore/platform/text/TextStream.h index f5e512c..e7e4cc0 100644 --- a/WebCore/platform/text/TextStream.h +++ b/WebCore/platform/text/TextStream.h @@ -26,13 +26,12 @@ #ifndef TextStream_h #define TextStream_h +#include <wtf/Forward.h> #include <wtf/Vector.h> #include <wtf/unicode/Unicode.h> namespace WebCore { -class String; - class TextStream { public: TextStream& operator<<(bool); diff --git a/WebCore/platform/text/android/HyphenationAndroid.cpp b/WebCore/platform/text/android/HyphenationAndroid.cpp index 00ebd46..e8ba5ef 100644 --- a/WebCore/platform/text/android/HyphenationAndroid.cpp +++ b/WebCore/platform/text/android/HyphenationAndroid.cpp @@ -57,7 +57,13 @@ static HyphenDict* loadHyphenationDictionary() return dict; } -size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex) +bool canHyphenate(const AtomicString& /* localeIdentifier */) +{ + // FIXME: Check that the locale identifier matches the available dictionary. + return true; +} + +size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex, const AtomicString& /* localeIdentifier */) { static const size_t minWordLen = 5; static const size_t maxWordLen = 100; diff --git a/WebCore/platform/text/cf/HyphenationCF.cpp b/WebCore/platform/text/cf/HyphenationCF.cpp index 50ba4c8..b983979 100644 --- a/WebCore/platform/text/cf/HyphenationCF.cpp +++ b/WebCore/platform/text/cf/HyphenationCF.cpp @@ -28,24 +28,43 @@ #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) +#include "AtomicString.h" +#include "AtomicStringKeyedMRUCache.h" #include "TextBreakIteratorInternalICU.h" +#include <wtf/ListHashSet.h> #include <wtf/RetainPtr.h> namespace WebCore { -static CFLocaleRef createCurrentSearchLocale() +template<> +RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::createValueForNullKey() { - RetainPtr<CFStringRef> localeIdentifier(AdoptCF, CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, (const UInt8*)currentSearchLocaleID(), strlen(currentSearchLocaleID()), kCFStringEncodingASCII, false, kCFAllocatorNull)); - return CFLocaleCreate(kCFAllocatorDefault, localeIdentifier.get()); + RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(currentSearchLocaleID()), strlen(currentSearchLocaleID()), kCFStringEncodingASCII, false, kCFAllocatorNull)); + RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCreate(kCFAllocatorDefault, cfLocaleIdentifier.get())); + return locale; } -size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex) +template<> +RetainPtr<CFLocaleRef> AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >::createValueForKey(const AtomicString& localeIdentifier) +{ + RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, localeIdentifier.createCFString()); + RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCreate(kCFAllocatorDefault, cfLocaleIdentifier.get())); + return locale; +} + +bool canHyphenate(const AtomicString& /* localeIdentifer */) +{ + return true; +} + +size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex, const AtomicString& localeIdentifier) { RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, characters, length, kCFAllocatorNull)); - static CFLocaleRef locale = createCurrentSearchLocale(); + DEFINE_STATIC_LOCAL(AtomicStringKeyedMRUCache<RetainPtr<CFLocaleRef> >, cfLocaleCache, ()); + RetainPtr<CFLocaleRef> locale = cfLocaleCache.get(localeIdentifier); - CFIndex result = CFStringGetHyphenationLocationBeforeIndex(string.get(), beforeIndex, CFRangeMake(0, length), 0, locale, 0); + CFIndex result = CFStringGetHyphenationLocationBeforeIndex(string.get(), beforeIndex, CFRangeMake(0, length), 0, locale.get(), 0); return result == kCFNotFound ? 0 : result; } diff --git a/WebCore/platform/text/cf/StringCF.cpp b/WebCore/platform/text/cf/StringCF.cpp index 97691e5..dcaf8fb 100644 --- a/WebCore/platform/text/cf/StringCF.cpp +++ b/WebCore/platform/text/cf/StringCF.cpp @@ -25,7 +25,7 @@ #include <CoreFoundation/CoreFoundation.h> -namespace WebCore { +namespace WTF { String::String(CFStringRef str) { diff --git a/WebCore/platform/text/cf/StringImplCF.cpp b/WebCore/platform/text/cf/StringImplCF.cpp index aff45b3..18e137f 100644 --- a/WebCore/platform/text/cf/StringImplCF.cpp +++ b/WebCore/platform/text/cf/StringImplCF.cpp @@ -32,7 +32,7 @@ #include <objc/objc-auto.h> #endif -namespace WebCore { +namespace WTF { namespace StringWrapperCFAllocator { @@ -50,7 +50,7 @@ namespace StringWrapperCFAllocator { static CFStringRef copyDescription(const void*) { - return CFSTR("WebCore::String-based allocator"); + return CFSTR("WTF::String-based allocator"); } static void* allocate(CFIndex size, CFOptionFlags, void*) diff --git a/WebCore/platform/text/haiku/StringHaiku.cpp b/WebCore/platform/text/haiku/StringHaiku.cpp index 7436ce2..96d6676 100644 --- a/WebCore/platform/text/haiku/StringHaiku.cpp +++ b/WebCore/platform/text/haiku/StringHaiku.cpp @@ -29,7 +29,7 @@ #include <String.h> -namespace WebCore { +namespace WTF { // String conversions String::String(const BString& string) diff --git a/WebCore/platform/text/mac/HyphenationMac.mm b/WebCore/platform/text/mac/HyphenationMac.mm index e64477f..56122df 100644 --- a/WebCore/platform/text/mac/HyphenationMac.mm +++ b/WebCore/platform/text/mac/HyphenationMac.mm @@ -28,17 +28,39 @@ #if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD) +#import "AtomicString.h" +#import "AtomicStringKeyedMRUCache.h" #import "TextBreakIteratorInternalICU.h" #import "WebCoreSystemInterface.h" #import <wtf/RetainPtr.h> namespace WebCore { -size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex) +template<> +bool AtomicStringKeyedMRUCache<bool>::createValueForNullKey() { - static bool localeIsEnglish = !strcmp("en", currentSearchLocaleID()); - if (!localeIsEnglish) - return 0; + return !strcmp(currentSearchLocaleID(), "en"); +} + +template<> +bool AtomicStringKeyedMRUCache<bool>::createValueForKey(const AtomicString& localeIdentifier) +{ + RetainPtr<CFStringRef> cfLocaleIdentifier(AdoptCF, localeIdentifier.createCFString()); + RetainPtr<CFDictionaryRef> components(AdoptCF, CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorDefault, cfLocaleIdentifier.get())); + CFStringRef language = reinterpret_cast<CFStringRef>(CFDictionaryGetValue(components.get(), kCFLocaleLanguageCode)); + static CFStringRef englishLanguage = CFSTR("en"); + return language && CFEqual(language, englishLanguage); +} + +bool canHyphenate(const AtomicString& localeIdentifier) +{ + DEFINE_STATIC_LOCAL(AtomicStringKeyedMRUCache<bool>, isEnglishCache, ()); + return isEnglishCache.get(localeIdentifier); +} + +size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex, const AtomicString& localeIdentifier) +{ + ASSERT_UNUSED(localeIdentifier, canHyphenate(localeIdentifier)); RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, characters, length, kCFAllocatorNull)); return wkGetHyphenationLocationBeforeIndex(string.get(), beforeIndex); diff --git a/WebCore/platform/text/mac/StringImplMac.mm b/WebCore/platform/text/mac/StringImplMac.mm index d14c6d8..843f396 100644 --- a/WebCore/platform/text/mac/StringImplMac.mm +++ b/WebCore/platform/text/mac/StringImplMac.mm @@ -23,7 +23,7 @@ #include "FoundationExtras.h" -namespace WebCore { +namespace WTF { StringImpl::operator NSString *() { diff --git a/WebCore/platform/text/mac/StringMac.mm b/WebCore/platform/text/mac/StringMac.mm index 758ae1d..7e98b2b 100644 --- a/WebCore/platform/text/mac/StringMac.mm +++ b/WebCore/platform/text/mac/StringMac.mm @@ -22,7 +22,7 @@ #include "PlatformString.h" #include <CoreFoundation/CFString.h> -namespace WebCore { +namespace WTF { String::String(NSString* str) { diff --git a/WebCore/platform/text/wx/StringWx.cpp b/WebCore/platform/text/wx/StringWx.cpp index 5302a85..7302edc 100644 --- a/WebCore/platform/text/wx/StringWx.cpp +++ b/WebCore/platform/text/wx/StringWx.cpp @@ -32,7 +32,7 @@ #include <wx/defs.h> #include <wx/string.h> -namespace WebCore { +namespace WTF { // String conversions String::String(const wxString& wxstr) |