diff options
author | Feng Qian <fqian@google.com> | 2009-06-17 12:12:20 -0700 |
---|---|---|
committer | Feng Qian <fqian@google.com> | 2009-06-17 12:12:20 -0700 |
commit | 5f1ab04193ad0130ca8204aadaceae083aca9881 (patch) | |
tree | 5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/platform/text | |
parent | 194315e5a908cc8ed67d597010544803eef1ac59 (diff) | |
download | external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2 |
Get WebKit r44544.
Diffstat (limited to 'WebCore/platform/text')
30 files changed, 336 insertions, 189 deletions
diff --git a/WebCore/platform/text/AtomicString.cpp b/WebCore/platform/text/AtomicString.cpp index d85f5ee..409439e 100644 --- a/WebCore/platform/text/AtomicString.cpp +++ b/WebCore/platform/text/AtomicString.cpp @@ -206,7 +206,7 @@ PassRefPtr<StringImpl> AtomicString::add(const UChar* s) PassRefPtr<StringImpl> AtomicString::add(StringImpl* r) { - if (!r || r->m_inTable) + if (!r || r->inTable()) return r; if (r->length() == 0) @@ -214,7 +214,7 @@ PassRefPtr<StringImpl> AtomicString::add(StringImpl* r) StringImpl* result = *stringTable().add(r).first; if (result == r) - r->m_inTable = true; + r->setInTable(); return result; } diff --git a/WebCore/platform/text/AtomicString.h b/WebCore/platform/text/AtomicString.h index f4efab9..3307a2d 100644 --- a/WebCore/platform/text/AtomicString.h +++ b/WebCore/platform/text/AtomicString.h @@ -67,17 +67,21 @@ public: UChar operator[](unsigned int i) const { return m_string[i]; } bool contains(UChar c) const { return m_string.contains(c); } - bool contains(const AtomicString& s, bool caseSensitive = true) const - { return m_string.contains(s.string(), caseSensitive); } + bool contains(const char* s, bool caseSensitive = true) const + { return m_string.contains(s, caseSensitive); } + bool contains(const String& s, bool caseSensitive = true) const + { return m_string.contains(s, caseSensitive); } int find(UChar c, int start = 0) const { return m_string.find(c, start); } - int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const - { return m_string.find(s.string(), start, caseSentitive); } + int find(const char* s, int start = 0, bool caseSentitive = true) const + { return m_string.find(s, start, caseSentitive); } + int find(const String& s, int start = 0, bool caseSentitive = true) const + { return m_string.find(s, start, caseSentitive); } - bool startsWith(const AtomicString& s, bool caseSensitive = true) const - { return m_string.startsWith(s.string(), caseSensitive); } - bool endsWith(const AtomicString& s, bool caseSensitive = true) const - { return m_string.endsWith(s.string(), caseSensitive); } + bool startsWith(const String& s, bool caseSensitive = true) const + { return m_string.startsWith(s, caseSensitive); } + bool endsWith(const String& s, bool caseSensitive = true) const + { return m_string.endsWith(s, caseSensitive); } int toInt(bool* ok = 0) const { return m_string.toInt(ok); } double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } diff --git a/WebCore/platform/text/BidiContext.cpp b/WebCore/platform/text/BidiContext.cpp index ef3c225..546571e 100644 --- a/WebCore/platform/text/BidiContext.cpp +++ b/WebCore/platform/text/BidiContext.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2000 Lars Knoll (knoll@kde.org) - * Copyright (C) 2003, 2004, 2006, 2007 Apple Inc. All right reserved. + * Copyright (C) 2003, 2004, 2006, 2007, 2009 Apple Inc. All right reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,8 +22,37 @@ #include "config.h" #include "BidiContext.h" +#include <wtf/StdLibExtras.h> + namespace WebCore { +using namespace WTF::Unicode; + +PassRefPtr<BidiContext> BidiContext::create(unsigned char level, Direction direction, bool override, BidiContext* parent) +{ + ASSERT(direction == level % 2 ? RightToLeft : LeftToRight); + + if (parent) + return adoptRef(new BidiContext(level, direction, override, parent)); + + ASSERT(level <= 1); + if (!level) { + DEFINE_STATIC_LOCAL(BidiContext, ltrContext, (0, LeftToRight, false, 0)); + if (!override) + return <rContext; + + DEFINE_STATIC_LOCAL(BidiContext, ltrOverrideContext, (0, LeftToRight, true, 0)); + return <rOverrideContext; + } + + DEFINE_STATIC_LOCAL(BidiContext, rtlContext, (1, RightToLeft, false, 0)); + if (!override) + return &rtlContext; + + DEFINE_STATIC_LOCAL(BidiContext, rtlOverrideContext, (1, RightToLeft, true, 0)); + return &rtlOverrideContext; +} + bool operator==(const BidiContext& c1, const BidiContext& c2) { if (&c1 == &c2) diff --git a/WebCore/platform/text/BidiContext.h b/WebCore/platform/text/BidiContext.h index 89123c8..8791605 100644 --- a/WebCore/platform/text/BidiContext.h +++ b/WebCore/platform/text/BidiContext.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2000 Lars Knoll (knoll@kde.org) - * Copyright (C) 2003, 2004, 2006, 2007 Apple Inc. All right reserved. + * Copyright (C) 2003, 2004, 2006, 2007, 2009 Apple Inc. All right reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,31 +23,17 @@ #define BidiContext_h #include <wtf/Assertions.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> #include <wtf/RefPtr.h> #include <wtf/unicode/Unicode.h> namespace WebCore { // Used to keep track of explicit embeddings. -class BidiContext { +class BidiContext : public RefCounted<BidiContext> { public: - BidiContext(unsigned char level, WTF::Unicode::Direction direction, bool override = false, BidiContext* parent = 0) - : m_level(level) - , m_direction(direction) - , m_override(override) - , m_parent(parent) - , m_refCount(0) - { - ASSERT(direction == WTF::Unicode::LeftToRight || direction == WTF::Unicode::RightToLeft); - } - - void ref() const { m_refCount++; } - void deref() const - { - m_refCount--; - if (m_refCount <= 0) - delete this; - } + static PassRefPtr<BidiContext> create(unsigned char level, WTF::Unicode::Direction direction, bool override = false, BidiContext* parent = 0); BidiContext* parent() const { return m_parent.get(); } unsigned char level() const { return m_level; } @@ -55,11 +41,18 @@ public: bool override() const { return m_override; } private: + BidiContext(unsigned char level, WTF::Unicode::Direction direction, bool override, BidiContext* parent) + : m_level(level) + , m_direction(direction) + , m_override(override) + , m_parent(parent) + { + } + unsigned char m_level; unsigned m_direction : 5; // Direction bool m_override : 1; RefPtr<BidiContext> m_parent; - mutable int m_refCount; }; bool operator==(const BidiContext&, const BidiContext&); diff --git a/WebCore/platform/text/BidiResolver.h b/WebCore/platform/text/BidiResolver.h index 8288be4..b6c2e88 100644 --- a/WebCore/platform/text/BidiResolver.h +++ b/WebCore/platform/text/BidiResolver.h @@ -402,7 +402,7 @@ void BidiResolver<Iterator, Run>::commitExplicitEmbedding() level &= ~1; } if (level < 61) - toContext = new BidiContext(level, direction, override, toContext.get()); + toContext = BidiContext::create(level, direction, override, toContext.get()); } } diff --git a/WebCore/platform/text/CharacterNames.h b/WebCore/platform/text/CharacterNames.h index f589a6c..5b1a337 100644 --- a/WebCore/platform/text/CharacterNames.h +++ b/WebCore/platform/text/CharacterNames.h @@ -37,6 +37,7 @@ namespace WebCore { const UChar blackSquare = 0x25A0; const UChar bullet = 0x2022; + const UChar hebrewPunctuationGershayim = 0x05F4; const UChar horizontalEllipsis = 0x2026; const UChar ideographicSpace = 0x3000; const UChar ideographicComma = 0x3001; @@ -49,6 +50,7 @@ namespace WebCore { const UChar objectReplacementCharacter = 0xFFFC; const UChar popDirectionalFormatting = 0x202C; const UChar replacementCharacter = 0xFFFD; + const UChar rightSingleQuotationMark = 0x2019; const UChar rightToLeftMark = 0x200F; const UChar rightToLeftEmbed = 0x202B; const UChar rightToLeftOverride = 0x202E; diff --git a/WebCore/platform/text/PlatformString.h b/WebCore/platform/text/PlatformString.h index a1541d2..1cc60b2 100644 --- a/WebCore/platform/text/PlatformString.h +++ b/WebCore/platform/text/PlatformString.h @@ -162,6 +162,11 @@ public: static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2); + // Returns an uninitialized string. The characters needs to be written + // into the buffer returned in data before the returned string is used. + // Failure to do this will have unpredictable results. + static String createUninitialized(unsigned length, UChar*& data) { return StringImpl::createUninitialized(length, data); } + void split(const String& separator, Vector<String>& result) const; void split(const String& separator, bool allowEmptyEntries, Vector<String>& result) const; void split(UChar separator, Vector<String>& result) const; diff --git a/WebCore/platform/text/String.cpp b/WebCore/platform/text/String.cpp index 733b661..cd87e2c 100644 --- a/WebCore/platform/text/String.cpp +++ b/WebCore/platform/text/String.cpp @@ -85,10 +85,12 @@ void String::append(const String& str) // call to fastMalloc every single time. if (str.m_impl) { if (m_impl) { - StringBuffer buffer(m_impl->length() + str.length()); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - memcpy(buffer.characters() + m_impl->length(), str.characters(), str.length() * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(m_impl->length() + str.length(), data); + memcpy(data, m_impl->characters(), m_impl->length() * sizeof(UChar)); + memcpy(data + m_impl->length(), str.characters(), str.length() * sizeof(UChar)); + m_impl = newImpl.release(); } else m_impl = str.m_impl; } @@ -101,10 +103,12 @@ void String::append(char c) // one String is pointing at this StringImpl, but even then it's going to require a // call to fastMalloc every single time. if (m_impl) { - StringBuffer buffer(m_impl->length() + 1); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - buffer[m_impl->length()] = c; - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(m_impl->length() + 1, data); + memcpy(data, m_impl->characters(), m_impl->length() * sizeof(UChar)); + data[m_impl->length()] = c; + m_impl = newImpl.release(); } else m_impl = StringImpl::create(&c, 1); } @@ -116,10 +120,12 @@ void String::append(UChar c) // one String is pointing at this StringImpl, but even then it's going to require a // call to fastMalloc every single time. if (m_impl) { - StringBuffer buffer(m_impl->length() + 1); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - buffer[m_impl->length()] = c; - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(m_impl->length() + 1, data); + memcpy(data, m_impl->characters(), m_impl->length() * sizeof(UChar)); + data[m_impl->length()] = c; + m_impl = newImpl.release(); } else m_impl = StringImpl::create(&c, 1); } @@ -170,10 +176,12 @@ void String::append(const UChar* charactersToAppend, unsigned lengthToAppend) return; ASSERT(charactersToAppend); - StringBuffer buffer(length() + lengthToAppend); - memcpy(buffer.characters(), characters(), length() * sizeof(UChar)); - memcpy(buffer.characters() + length(), charactersToAppend, lengthToAppend * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(length() + lengthToAppend, data); + memcpy(data, characters(), length() * sizeof(UChar)); + memcpy(data + length(), charactersToAppend, lengthToAppend * sizeof(UChar)); + m_impl = newImpl.release(); } void String::insert(const UChar* charactersToInsert, unsigned lengthToInsert, unsigned position) @@ -189,11 +197,13 @@ void String::insert(const UChar* charactersToInsert, unsigned lengthToInsert, un return; ASSERT(charactersToInsert); - StringBuffer buffer(length() + lengthToInsert); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - memcpy(buffer.characters() + position, charactersToInsert, lengthToInsert * sizeof(UChar)); - memcpy(buffer.characters() + position + lengthToInsert, characters() + position, (length() - position) * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(length() + lengthToInsert, data); + memcpy(data, characters(), position * sizeof(UChar)); + memcpy(data + position, charactersToInsert, lengthToInsert * sizeof(UChar)); + memcpy(data + position + lengthToInsert, characters() + position, (length() - position) * sizeof(UChar)); + m_impl = newImpl.release(); } UChar String::operator[](unsigned i) const @@ -221,9 +231,10 @@ void String::truncate(unsigned position) { if (position >= length()) return; - StringBuffer buffer(position); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); + UChar* data; + RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, data); + memcpy(data, characters(), position * sizeof(UChar)); + m_impl = newImpl.release(); } void String::remove(unsigned position, int lengthToRemove) @@ -234,11 +245,13 @@ void String::remove(unsigned position, int lengthToRemove) return; if (static_cast<unsigned>(lengthToRemove) > length() - position) lengthToRemove = length() - position; - StringBuffer buffer(length() - lengthToRemove); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - memcpy(buffer.characters() + position, characters() + position + lengthToRemove, + UChar* data; + RefPtr<StringImpl> newImpl = + StringImpl::createUninitialized(length() - lengthToRemove, data); + memcpy(data, characters(), position * sizeof(UChar)); + memcpy(data + position, characters() + position + lengthToRemove, (length() - lengthToRemove - position) * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); + m_impl = newImpl.release(); } String String::substring(unsigned pos, unsigned len) const @@ -637,21 +650,21 @@ String::String(const Identifier& str) { if (str.isNull()) return; - m_impl = StringImpl::create(str.data(), str.size()); + m_impl = StringImpl::create(str.ustring()); } String::String(const UString& str) { if (str.isNull()) return; - m_impl = StringImpl::create(str.data(), str.size()); + m_impl = StringImpl::create(str); } String::operator UString() const { if (!m_impl) return UString(); - return UString(m_impl->characters(), m_impl->length()); + return m_impl->ustring(); } #endif diff --git a/WebCore/platform/text/StringBuilder.cpp b/WebCore/platform/text/StringBuilder.cpp index 0e9555c..c21e366 100644 --- a/WebCore/platform/text/StringBuilder.cpp +++ b/WebCore/platform/text/StringBuilder.cpp @@ -79,9 +79,10 @@ String StringBuilder::toString() const if (count == 1) return m_strings[0]; - StringBuffer buffer(m_totalLength); + UChar* buffer; + String result = String::createUninitialized(m_totalLength, buffer); - UChar* p = buffer.characters(); + UChar* p = buffer; for (unsigned i = 0; i < count; ++i) { StringImpl* string = m_strings[i].impl(); unsigned length = string->length(); @@ -89,9 +90,9 @@ String StringBuilder::toString() const p += length; } - ASSERT(p == m_totalLength + buffer.characters()); + ASSERT(p == m_totalLength + buffer); - return String::adopt(buffer); + return result; } } diff --git a/WebCore/platform/text/StringImpl.cpp b/WebCore/platform/text/StringImpl.cpp index 6bba990..8bc4dde 100644 --- a/WebCore/platform/text/StringImpl.cpp +++ b/WebCore/platform/text/StringImpl.cpp @@ -44,6 +44,8 @@ using namespace Unicode; namespace WebCore { +static const unsigned minLengthToShare = 20; + static inline UChar* newUCharVector(unsigned n) { return static_cast<UChar*>(fastMalloc(sizeof(UChar) * n)); @@ -80,8 +82,6 @@ StringImpl::StringImpl() : m_length(0) , m_data(0) , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { // Ensure that the hash is computed so that AtomicStringHash can call existingHash() @@ -96,8 +96,6 @@ StringImpl::StringImpl() inline StringImpl::StringImpl(const UChar* characters, unsigned length) : m_length(length) , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { UChar* data = newUCharVector(length); @@ -108,10 +106,9 @@ inline StringImpl::StringImpl(const UChar* characters, unsigned length) inline StringImpl::StringImpl(const StringImpl& str, WithTerminatingNullCharacter) : m_length(str.m_length) , m_hash(str.m_hash) - , m_inTable(false) - , m_hasTerminatingNullCharacter(true) , m_bufferIsInternal(false) { + m_sharedBufferAndFlags.setFlag(HasTerminatingNullCharacter); UChar* data = newUCharVector(str.m_length + 1); memcpy(data, str.m_data, str.m_length * sizeof(UChar)); data[str.m_length] = 0; @@ -121,8 +118,6 @@ inline StringImpl::StringImpl(const StringImpl& str, WithTerminatingNullCharacte inline StringImpl::StringImpl(const char* characters, unsigned length) : m_length(length) , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { ASSERT(characters); @@ -140,8 +135,6 @@ inline StringImpl::StringImpl(UChar* characters, unsigned length, AdoptBuffer) : m_length(length) , m_data(characters) , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { ASSERT(characters); @@ -152,14 +145,13 @@ inline StringImpl::StringImpl(UChar* characters, unsigned length, AdoptBuffer) StringImpl::StringImpl(const UChar* characters, unsigned length, unsigned hash) : m_length(length) , m_hash(hash) - , m_inTable(true) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { ASSERT(hash); ASSERT(characters); ASSERT(length); + setInTable(); UChar* data = newUCharVector(length); memcpy(data, characters, length * sizeof(UChar)); m_data = data; @@ -169,14 +161,13 @@ StringImpl::StringImpl(const UChar* characters, unsigned length, unsigned hash) StringImpl::StringImpl(const char* characters, unsigned length, unsigned hash) : m_length(length) , m_hash(hash) - , m_inTable(true) - , m_hasTerminatingNullCharacter(false) , m_bufferIsInternal(false) { ASSERT(hash); ASSERT(characters); ASSERT(length); + setInTable(); UChar* data = newUCharVector(length); for (unsigned i = 0; i != length; ++i) { unsigned char c = characters[i]; @@ -187,10 +178,15 @@ StringImpl::StringImpl(const char* characters, unsigned length, unsigned hash) StringImpl::~StringImpl() { - if (m_inTable) + if (inTable()) AtomicString::remove(this); - if (!m_bufferIsInternal) - deleteUCharVector(m_data); + if (!m_bufferIsInternal) { + SharedUChar* sharedBuffer = m_sharedBufferAndFlags.get(); + if (sharedBuffer) + sharedBuffer->deref(); + else + deleteUCharVector(m_data); + } } StringImpl* StringImpl::empty() @@ -264,7 +260,8 @@ bool StringImpl::isLower() PassRefPtr<StringImpl> StringImpl::lower() { - StringBuffer data(m_length); + UChar* data; + PassRefPtr<StringImpl> newImpl = createUninitialized(m_length, data); int32_t length = m_length; // Do a faster loop for the case where all the characters are ASCII. @@ -275,23 +272,24 @@ PassRefPtr<StringImpl> StringImpl::lower() data[i] = toASCIILower(c); } if (!(ored & ~0x7F)) - return adopt(data); + return newImpl; // Do a slower implementation for cases that include non-ASCII characters. bool error; - int32_t realLength = Unicode::toLower(data.characters(), length, m_data, m_length, &error); + int32_t realLength = Unicode::toLower(data, length, m_data, m_length, &error); if (!error && realLength == length) - return adopt(data); - data.resize(realLength); - Unicode::toLower(data.characters(), realLength, m_data, m_length, &error); + return newImpl; + newImpl = createUninitialized(realLength, data); + Unicode::toLower(data, realLength, m_data, m_length, &error); if (error) return this; - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::upper() { - StringBuffer data(m_length); + UChar* data; + PassRefPtr<StringImpl> newImpl = createUninitialized(m_length, data); int32_t length = m_length; // Do a faster loop for the case where all the characters are ASCII. @@ -302,32 +300,34 @@ PassRefPtr<StringImpl> StringImpl::upper() data[i] = toASCIIUpper(c); } if (!(ored & ~0x7F)) - return adopt(data); + return newImpl; // Do a slower implementation for cases that include non-ASCII characters. bool error; - int32_t realLength = Unicode::toUpper(data.characters(), length, m_data, m_length, &error); + int32_t realLength = Unicode::toUpper(data, length, m_data, m_length, &error); if (!error && realLength == length) - return adopt(data); - data.resize(realLength); - Unicode::toUpper(data.characters(), realLength, m_data, m_length, &error); + return newImpl; + newImpl = createUninitialized(realLength, data); + Unicode::toUpper(data, realLength, m_data, m_length, &error); if (error) return this; - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::secure(UChar aChar) { - int length = m_length; - StringBuffer data(length); + UChar* data; + PassRefPtr<StringImpl> newImpl = createUninitialized(m_length, data); + int32_t length = m_length; for (int i = 0; i < length; ++i) data[i] = aChar; - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::foldCase() { - StringBuffer data(m_length); + UChar* data; + PassRefPtr<StringImpl> newImpl = createUninitialized(m_length, data); int32_t length = m_length; // Do a faster loop for the case where all the characters are ASCII. @@ -338,18 +338,18 @@ PassRefPtr<StringImpl> StringImpl::foldCase() data[i] = toASCIILower(c); } if (!(ored & ~0x7F)) - return adopt(data); + return newImpl; // Do a slower implementation for cases that include non-ASCII characters. bool error; - int32_t realLength = Unicode::foldCase(data.characters(), length, m_data, m_length, &error); + int32_t realLength = Unicode::foldCase(data, length, m_data, m_length, &error); if (!error && realLength == length) - return adopt(data); - data.resize(realLength); - Unicode::foldCase(data.characters(), realLength, m_data, m_length, &error); + return newImpl; + newImpl = createUninitialized(realLength, data); + Unicode::foldCase(data, realLength, m_data, m_length, &error); if (error) return this; - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::stripWhiteSpace() @@ -727,14 +727,16 @@ PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) if (i == m_length) return this; - StringBuffer data(m_length); + UChar* data; + PassRefPtr<StringImpl> newImpl = createUninitialized(m_length, data); + for (i = 0; i != m_length; ++i) { UChar ch = m_data[i]; if (ch == oldC) ch = newC; data[i] = ch; } - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToReplace, StringImpl* str) @@ -744,13 +746,15 @@ PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToR unsigned lengthToInsert = str ? str->length() : 0; if (!lengthToReplace && !lengthToInsert) return this; - StringBuffer buffer(length() - lengthToReplace + lengthToInsert); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); + UChar* data; + PassRefPtr<StringImpl> newImpl = + createUninitialized(length() - lengthToReplace + lengthToInsert, data); + memcpy(data, characters(), position * sizeof(UChar)); if (str) - memcpy(buffer.characters() + position, str->characters(), lengthToInsert * sizeof(UChar)); - memcpy(buffer.characters() + position + lengthToInsert, characters() + position + lengthToReplace, + memcpy(data + position, str->characters(), lengthToInsert * sizeof(UChar)); + memcpy(data + position + lengthToInsert, characters() + position + lengthToReplace, (length() - position - lengthToReplace) * sizeof(UChar)); - return adopt(buffer); + return newImpl; } PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacement) @@ -772,8 +776,10 @@ PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacemen if (!matchCount) return this; - StringBuffer data(m_length - matchCount + (matchCount * repStrLength)); - + UChar* data; + PassRefPtr<StringImpl> newImpl = + createUninitialized(m_length - matchCount + (matchCount * repStrLength), data); + // Construct the new data int srcSegmentEnd; int srcSegmentLength; @@ -782,19 +788,19 @@ PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacemen while ((srcSegmentEnd = find(pattern, srcSegmentStart)) >= 0) { srcSegmentLength = srcSegmentEnd - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); + memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); dstOffset += srcSegmentLength; - memcpy(data.characters() + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); + memcpy(data + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); dstOffset += repStrLength; srcSegmentStart = srcSegmentEnd + 1; } srcSegmentLength = m_length - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); + memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - ASSERT(dstOffset + srcSegmentLength == static_cast<int>(data.length())); + ASSERT(dstOffset + srcSegmentLength == static_cast<int>(newImpl->length())); - return adopt(data); + return newImpl; } PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* replacement) @@ -820,7 +826,9 @@ PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* repl if (!matchCount) return this; - StringBuffer data(m_length + matchCount * (repStrLength - patternLength)); + UChar* data; + PassRefPtr<StringImpl> newImpl = + createUninitialized(m_length + matchCount * (repStrLength - patternLength), data); // Construct the new data int srcSegmentEnd; @@ -830,19 +838,19 @@ PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* repl while ((srcSegmentEnd = find(pattern, srcSegmentStart)) >= 0) { srcSegmentLength = srcSegmentEnd - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); + memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); dstOffset += srcSegmentLength; - memcpy(data.characters() + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); + memcpy(data + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); dstOffset += repStrLength; srcSegmentStart = srcSegmentEnd + patternLength; } srcSegmentLength = m_length - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); + memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - ASSERT(dstOffset + srcSegmentLength == static_cast<int>(data.length())); + ASSERT(dstOffset + srcSegmentLength == static_cast<int>(newImpl->length())); - return adopt(data); + return newImpl; } bool equal(StringImpl* a, StringImpl* b) @@ -965,41 +973,47 @@ PassRefPtr<StringImpl> StringImpl::adopt(Vector<UChar>& vector) return adoptRef(new StringImpl(vector.releaseBuffer(), size, AdoptBuffer())); } -PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned length) +PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*& data) { - if (!characters || !length) + if (!length) { + data = 0; return empty(); + } // Allocate a single buffer large enough to contain the StringImpl // struct as well as the data which it contains. This removes one // heap allocation from this call. size_t size = sizeof(StringImpl) + length * sizeof(UChar); char* buffer = static_cast<char*>(fastMalloc(size)); - UChar* data = reinterpret_cast<UChar*>(buffer + sizeof(StringImpl)); - memcpy(data, characters, length * sizeof(UChar)); + data = reinterpret_cast<UChar*>(buffer + sizeof(StringImpl)); StringImpl* string = new (buffer) StringImpl(data, length, AdoptBuffer()); string->m_bufferIsInternal = true; return adoptRef(string); } +PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned length) +{ + if (!characters || !length) + return empty(); + + UChar* data; + PassRefPtr<StringImpl> string = createUninitialized(length, data); + memcpy(data, characters, length * sizeof(UChar)); + return string; +} + PassRefPtr<StringImpl> StringImpl::create(const char* characters, unsigned length) { if (!characters || !length) return empty(); - // Allocate a single buffer large enough to contain the StringImpl - // struct as well as the data which it contains. This removes one - // heap allocation from this call. - size_t size = sizeof(StringImpl) + length * sizeof(UChar); - char* buffer = static_cast<char*>(fastMalloc(size)); - UChar* data = reinterpret_cast<UChar*>(buffer + sizeof(StringImpl)); + UChar* data; + PassRefPtr<StringImpl> string = createUninitialized(length, data); for (unsigned i = 0; i != length; ++i) { unsigned char c = characters[i]; data[i] = c; } - StringImpl* string = new (buffer) StringImpl(data, length, AdoptBuffer()); - string->m_bufferIsInternal = true; - return adoptRef(string); + return string; } PassRefPtr<StringImpl> StringImpl::create(const char* string) @@ -1009,6 +1023,29 @@ PassRefPtr<StringImpl> StringImpl::create(const char* string) return create(string, strlen(string)); } +#if USE(JSC) +PassRefPtr<StringImpl> StringImpl::create(const JSC::UString& str) +{ + SharedUChar* sharedBuffer = const_cast<JSC::UString*>(&str)->rep()->baseString()->sharedBuffer(); + if (sharedBuffer) { + PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(const_cast<UChar*>(str.data()), str.size(), AdoptBuffer())); + sharedBuffer->ref(); + impl->m_sharedBufferAndFlags.set(sharedBuffer); + return impl; + } + return StringImpl::create(str.data(), str.size()); +} + +JSC::UString StringImpl::ustring() +{ + SharedUChar* sharedBuffer = StringImpl::sharedBuffer(); + if (sharedBuffer) + return JSC::UString::Rep::create(const_cast<UChar*>(m_data), m_length, sharedBuffer); + + return JSC::UString(m_data, m_length); +} +#endif + PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const StringImpl& string) { return adoptRef(new StringImpl(string, WithTerminatingNullCharacter())); @@ -1019,4 +1056,15 @@ PassRefPtr<StringImpl> StringImpl::copy() return create(m_data, m_length); } +StringImpl::SharedUChar* StringImpl::sharedBuffer() +{ + if (m_length < minLengthToShare || m_bufferIsInternal) + return 0; + + if (!m_sharedBufferAndFlags.get()) + m_sharedBufferAndFlags.set(SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef()); + return m_sharedBufferAndFlags.get(); +} + + } // namespace WebCore diff --git a/WebCore/platform/text/StringImpl.h b/WebCore/platform/text/StringImpl.h index 1242f27..f591800 100644 --- a/WebCore/platform/text/StringImpl.h +++ b/WebCore/platform/text/StringImpl.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,11 +25,18 @@ #include <limits.h> #include <wtf/ASCIICType.h> +#include <wtf/CrossThreadRefCounted.h> +#include <wtf/OwnFastMallocPtr.h> #include <wtf/PassRefPtr.h> +#include <wtf/PtrAndFlags.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> #include <wtf/unicode/Unicode.h> +#if USE(JSC) +#include <runtime/UString.h> +#endif + #if PLATFORM(CF) || (PLATFORM(QT) && PLATFORM(DARWIN)) typedef const struct __CFString * CFStringRef; #endif @@ -72,23 +80,34 @@ private: StringImpl(const UChar*, unsigned length, unsigned hash); StringImpl(const char*, unsigned length, unsigned hash); + typedef CrossThreadRefCounted<OwnFastMallocPtr<UChar> > SharedUChar; + public: ~StringImpl(); static PassRefPtr<StringImpl> create(const UChar*, unsigned length); static PassRefPtr<StringImpl> create(const char*, unsigned length); static PassRefPtr<StringImpl> create(const char*); + static PassRefPtr<StringImpl> createUninitialized(unsigned length, UChar*& data); static PassRefPtr<StringImpl> createWithTerminatingNullCharacter(const StringImpl&); static PassRefPtr<StringImpl> createStrippingNullCharacters(const UChar*, unsigned length); static PassRefPtr<StringImpl> adopt(StringBuffer&); static PassRefPtr<StringImpl> adopt(Vector<UChar>&); +#if USE(JSC) + static PassRefPtr<StringImpl> create(const JSC::UString&); + JSC::UString ustring(); +#endif + SharedUChar* sharedBuffer(); const UChar* characters() { return m_data; } unsigned length() { return m_length; } - bool hasTerminatingNullCharacter() { return m_hasTerminatingNullCharacter; } + bool hasTerminatingNullCharacter() const { return m_sharedBufferAndFlags.isFlagSet(HasTerminatingNullCharacter); } + + bool inTable() const { return m_sharedBufferAndFlags.isFlagSet(InTable); } + void setInTable() { return m_sharedBufferAndFlags.setFlag(InTable); } unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; } unsigned existingHash() const { ASSERT(m_hash); return m_hash; } @@ -176,11 +195,16 @@ private: static PassRefPtr<StringImpl> createStrippingNullCharactersSlowCase(const UChar*, unsigned length); + enum StringImplFlags { + HasTerminatingNullCharacter, + InTable, + }; + unsigned m_length; const UChar* m_data; mutable unsigned m_hash; - bool m_inTable; - bool m_hasTerminatingNullCharacter; + PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags; + // In some cases, we allocate the StringImpl struct and its data // within a single heap buffer. In this case, the m_data pointer // is an "internal buffer", and does not need to be deallocated. diff --git a/WebCore/platform/text/TextBoundaries.h b/WebCore/platform/text/TextBoundaries.h index 118dd1a..7eb9cab 100644 --- a/WebCore/platform/text/TextBoundaries.h +++ b/WebCore/platform/text/TextBoundaries.h @@ -30,6 +30,11 @@ namespace WebCore { + inline bool requiresContextForWordBoundary(UChar32 ch) + { + return WTF::Unicode::hasLineBreakingPropertyComplexContext(ch); + } + void findWordBoundary(const UChar*, int len, int position, int* start, int* end); int findNextWordFromIndex(const UChar*, int len, int position, bool forward); diff --git a/WebCore/platform/text/TextBoundariesICU.cpp b/WebCore/platform/text/TextBoundariesICU.cpp index d226048..b1e8ee2 100644 --- a/WebCore/platform/text/TextBoundariesICU.cpp +++ b/WebCore/platform/text/TextBoundariesICU.cpp @@ -27,6 +27,7 @@ #include "TextBoundaries.h" #include <unicode/ubrk.h> +#include <unicode/uchar.h> #include "StringImpl.h" #include "TextBreakIterator.h" diff --git a/WebCore/platform/text/TextCodec.h b/WebCore/platform/text/TextCodec.h index 0a56262..df42582 100644 --- a/WebCore/platform/text/TextCodec.h +++ b/WebCore/platform/text/TextCodec.h @@ -29,6 +29,7 @@ #include <memory> #include <wtf/Noncopyable.h> +#include <wtf/PassOwnPtr.h> #include <wtf/Vector.h> #include <wtf/unicode/Unicode.h> @@ -76,7 +77,7 @@ namespace WebCore { typedef void (*EncodingNameRegistrar)(const char* alias, const char* name); - typedef std::auto_ptr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData); + typedef PassOwnPtr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData); typedef void (*TextCodecRegistrar)(const char* name, NewTextCodecFunction, const void* additionalData); } // namespace WebCore diff --git a/WebCore/platform/text/TextCodecICU.cpp b/WebCore/platform/text/TextCodecICU.cpp index 72054fa..b8e40a9 100644 --- a/WebCore/platform/text/TextCodecICU.cpp +++ b/WebCore/platform/text/TextCodecICU.cpp @@ -34,10 +34,10 @@ #include <unicode/ucnv.h> #include <unicode/ucnv_cb.h> #include <wtf/Assertions.h> +#include <wtf/PassOwnPtr.h> #include <wtf/StringExtras.h> #include <wtf/Threading.h> -using std::auto_ptr; using std::min; namespace WebCore { @@ -55,9 +55,9 @@ static UConverter*& cachedConverterICU() return threadGlobalData().cachedConverterICU().converter; } -static auto_ptr<TextCodec> newTextCodecICU(const TextEncoding& encoding, const void*) +static PassOwnPtr<TextCodec> newTextCodecICU(const TextEncoding& encoding, const void*) { - return auto_ptr<TextCodec>(new TextCodecICU(encoding)); + return new TextCodecICU(encoding); } void TextCodecICU::registerBaseEncodingNames(EncodingNameRegistrar registrar) diff --git a/WebCore/platform/text/TextCodecICU.h b/WebCore/platform/text/TextCodecICU.h index f07758f..bf517f7 100644 --- a/WebCore/platform/text/TextCodecICU.h +++ b/WebCore/platform/text/TextCodecICU.h @@ -30,6 +30,8 @@ #include "TextCodec.h" #include "TextEncoding.h" +#include <unicode/utypes.h> + typedef struct UConverter UConverter; namespace WebCore { diff --git a/WebCore/platform/text/TextCodecLatin1.cpp b/WebCore/platform/text/TextCodecLatin1.cpp index 50f9f97..cfdc5b9 100644 --- a/WebCore/platform/text/TextCodecLatin1.cpp +++ b/WebCore/platform/text/TextCodecLatin1.cpp @@ -30,8 +30,7 @@ #include "PlatformString.h" #include "StringBuffer.h" #include <stdio.h> - -using std::auto_ptr; +#include <wtf/PassOwnPtr.h> namespace WebCore { @@ -104,9 +103,9 @@ void TextCodecLatin1::registerEncodingNames(EncodingNameRegistrar registrar) registrar("x-ansi", "US-ASCII"); } -static auto_ptr<TextCodec> newStreamingTextDecoderWindowsLatin1(const TextEncoding&, const void*) +static PassOwnPtr<TextCodec> newStreamingTextDecoderWindowsLatin1(const TextEncoding&, const void*) { - return auto_ptr<TextCodec>(new TextCodecLatin1); + return new TextCodecLatin1; } void TextCodecLatin1::registerCodecs(TextCodecRegistrar registrar) @@ -120,7 +119,8 @@ void TextCodecLatin1::registerCodecs(TextCodecRegistrar registrar) String TextCodecLatin1::decode(const char* bytes, size_t length, bool, bool, bool&) { - StringBuffer characters(length); + UChar* characters; + String result = String::createUninitialized(length, characters); // Convert the string a fast way and simultaneously do an efficient check to see if it's all ASCII. unsigned char ored = 0; @@ -131,7 +131,7 @@ String TextCodecLatin1::decode(const char* bytes, size_t length, bool, bool, boo } if (!(ored & 0x80)) - return String::adopt(characters); + return result; // Convert the slightly slower way when there are non-ASCII characters. for (size_t i = 0; i < length; ++i) { @@ -139,7 +139,7 @@ String TextCodecLatin1::decode(const char* bytes, size_t length, bool, bool, boo characters[i] = table[c]; } - return String::adopt(characters); + return result; } static CString encodeComplexWindowsLatin1(const UChar* characters, size_t length, UnencodableHandling handling) diff --git a/WebCore/platform/text/TextCodecUTF16.cpp b/WebCore/platform/text/TextCodecUTF16.cpp index a4d0d28..db77000 100644 --- a/WebCore/platform/text/TextCodecUTF16.cpp +++ b/WebCore/platform/text/TextCodecUTF16.cpp @@ -29,8 +29,7 @@ #include "CString.h" #include "PlatformString.h" #include "StringBuffer.h" - -using std::auto_ptr; +#include <wtf/PassOwnPtr.h> namespace WebCore { @@ -49,14 +48,14 @@ void TextCodecUTF16::registerEncodingNames(EncodingNameRegistrar registrar) registrar("unicodeFFFE", "UTF-16BE"); } -static auto_ptr<TextCodec> newStreamingTextDecoderUTF16LE(const TextEncoding&, const void*) +static PassOwnPtr<TextCodec> newStreamingTextDecoderUTF16LE(const TextEncoding&, const void*) { - return auto_ptr<TextCodec>(new TextCodecUTF16(true)); + return new TextCodecUTF16(true); } -static auto_ptr<TextCodec> newStreamingTextDecoderUTF16BE(const TextEncoding&, const void*) +static PassOwnPtr<TextCodec> newStreamingTextDecoderUTF16BE(const TextEncoding&, const void*) { - return auto_ptr<TextCodec>(new TextCodecUTF16(false)); + return new TextCodecUTF16(false); } void TextCodecUTF16::registerCodecs(TextCodecRegistrar registrar) diff --git a/WebCore/platform/text/TextCodecUserDefined.cpp b/WebCore/platform/text/TextCodecUserDefined.cpp index 2dae0f3..b7c8896 100644 --- a/WebCore/platform/text/TextCodecUserDefined.cpp +++ b/WebCore/platform/text/TextCodecUserDefined.cpp @@ -30,8 +30,7 @@ #include "PlatformString.h" #include "StringBuffer.h" #include <stdio.h> - -using std::auto_ptr; +#include <wtf/PassOwnPtr.h> namespace WebCore { @@ -40,9 +39,9 @@ void TextCodecUserDefined::registerEncodingNames(EncodingNameRegistrar registrar registrar("x-user-defined", "x-user-defined"); } -static auto_ptr<TextCodec> newStreamingTextDecoderUserDefined(const TextEncoding&, const void*) +static PassOwnPtr<TextCodec> newStreamingTextDecoderUserDefined(const TextEncoding&, const void*) { - return auto_ptr<TextCodec>(new TextCodecUserDefined); + return new TextCodecUserDefined; } void TextCodecUserDefined::registerCodecs(TextCodecRegistrar registrar) @@ -52,14 +51,15 @@ void TextCodecUserDefined::registerCodecs(TextCodecRegistrar registrar) String TextCodecUserDefined::decode(const char* bytes, size_t length, bool, bool, bool&) { - StringBuffer buffer(length); + UChar* buffer; + String result = String::createUninitialized(length, buffer); for (size_t i = 0; i < length; ++i) { signed char c = bytes[i]; buffer[i] = c & 0xF7FF; } - return String::adopt(buffer); + return result; } static CString encodeComplexUserDefined(const UChar* characters, size_t length, UnencodableHandling handling) diff --git a/WebCore/platform/text/TextEncoding.cpp b/WebCore/platform/text/TextEncoding.cpp index ed58412..5fa927b 100644 --- a/WebCore/platform/text/TextEncoding.cpp +++ b/WebCore/platform/text/TextEncoding.cpp @@ -31,7 +31,7 @@ #include "PlatformString.h" #include "TextCodec.h" #include "TextEncodingRegistry.h" -#if USE(ICU_UNICODE) +#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID) #include <unicode/unorm.h> #elif USE(QT4_UNICODE) #include <QString> @@ -83,7 +83,7 @@ CString TextEncoding::encode(const UChar* characters, size_t length, Unencodable if (!length) return ""; -#if USE(ICU_UNICODE) +#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID) // FIXME: What's the right place to do normalization? // It's a little strange to do it inside the encode function. // Perhaps normalization should be an explicit step done before calling encode. @@ -116,6 +116,24 @@ CString TextEncoding::encode(const UChar* characters, size_t length, Unencodable #endif } +const char* TextEncoding::domName() const +{ + if (noExtendedTextEncodingNameUsed()) + return m_name; + + // We treat EUC-KR as windows-949 (its superset), but need to expose + // the name 'EUC-KR' because the name 'windows-949' is not recognized by + // most Korean web servers even though they do use the encoding + // 'windows-949' with the name 'EUC-KR'. + // FIXME: This is not thread-safe. At the moment, this function is + // only accessed in a single thread, but eventually has to be made + // thread-safe along with usesVisualOrdering(). + static const char* const a = atomicCanonicalTextEncodingName("windows-949"); + if (m_name == a) + return "EUC-KR"; + return m_name; +} + bool TextEncoding::usesVisualOrdering() const { if (noExtendedTextEncodingNameUsed()) diff --git a/WebCore/platform/text/TextEncoding.h b/WebCore/platform/text/TextEncoding.h index b3909f7..a99bfc8 100644 --- a/WebCore/platform/text/TextEncoding.h +++ b/WebCore/platform/text/TextEncoding.h @@ -42,6 +42,7 @@ namespace WebCore { bool isValid() const { return m_name; } const char* name() const { return m_name; } + const char* domName() const; // name exposed via DOM bool usesVisualOrdering() const; bool isJapanese() const; diff --git a/WebCore/platform/text/TextEncodingDetectorICU.cpp b/WebCore/platform/text/TextEncodingDetectorICU.cpp index 26c997e..fcb2aa9 100644 --- a/WebCore/platform/text/TextEncodingDetectorICU.cpp +++ b/WebCore/platform/text/TextEncodingDetectorICU.cpp @@ -32,7 +32,7 @@ #include "TextEncodingDetector.h" #include "TextEncoding.h" -#include "UnusedParam.h" +#include <wtf/UnusedParam.h> #ifndef BUILDING_ON_TIGER #include "unicode/ucnv.h" diff --git a/WebCore/platform/text/TextEncodingDetectorNone.cpp b/WebCore/platform/text/TextEncodingDetectorNone.cpp index 2655f08..3b62bc5 100644 --- a/WebCore/platform/text/TextEncodingDetectorNone.cpp +++ b/WebCore/platform/text/TextEncodingDetectorNone.cpp @@ -32,18 +32,11 @@ #include "TextEncodingDetector.h" #include "TextEncoding.h" -#include "UnusedParam.h" namespace WebCore { -bool detectTextEncoding(const char* data, size_t len, - const char* hintEncodingName, - TextEncoding* detectedEncoding) +bool detectTextEncoding(const char*, size_t, const char*, TextEncoding* detectedEncoding) { - UNUSED_PARAM(data) - UNUSED_PARAM(len) - UNUSED_PARAM(hintEncodingName) - *detectedEncoding = TextEncoding(); return false; } diff --git a/WebCore/platform/text/TextEncodingRegistry.cpp b/WebCore/platform/text/TextEncodingRegistry.cpp index 2d89fac..3c9d65f 100644 --- a/WebCore/platform/text/TextEncodingRegistry.cpp +++ b/WebCore/platform/text/TextEncodingRegistry.cpp @@ -38,7 +38,7 @@ #include <wtf/StringExtras.h> #include <wtf/Threading.h> -#if USE(ICU_UNICODE) +#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID) #include "TextCodecICU.h" #endif #if PLATFORM(MAC) @@ -185,7 +185,7 @@ static void buildBaseTextCodecMaps() TextCodecUserDefined::registerEncodingNames(addToTextEncodingNameMap); TextCodecUserDefined::registerCodecs(addToTextCodecMap); -#if USE(ICU_UNICODE) +#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID) TextCodecICU::registerBaseEncodingNames(addToTextEncodingNameMap); TextCodecICU::registerBaseCodecs(addToTextCodecMap); #endif @@ -193,7 +193,7 @@ static void buildBaseTextCodecMaps() static void extendTextCodecMaps() { -#if USE(ICU_UNICODE) +#if USE(ICU_UNICODE) || USE(GLIB_ICU_UNICODE_HYBRID) TextCodecICU::registerExtendedEncodingNames(addToTextEncodingNameMap); TextCodecICU::registerExtendedCodecs(addToTextCodecMap); #endif @@ -209,7 +209,7 @@ static void extendTextCodecMaps() #endif } -std::auto_ptr<TextCodec> newTextCodec(const TextEncoding& encoding) +PassOwnPtr<TextCodec> newTextCodec(const TextEncoding& encoding) { MutexLocker lock(encodingRegistryMutex()); diff --git a/WebCore/platform/text/TextEncodingRegistry.h b/WebCore/platform/text/TextEncodingRegistry.h index d204734..e6950cf 100644 --- a/WebCore/platform/text/TextEncodingRegistry.h +++ b/WebCore/platform/text/TextEncodingRegistry.h @@ -27,6 +27,7 @@ #define TextEncodingRegistry_h #include <memory> +#include <wtf/PassOwnPtr.h> #include <wtf/unicode/Unicode.h> namespace WebCore { @@ -36,7 +37,7 @@ namespace WebCore { // Use TextResourceDecoder::decode to decode resources, since it handles BOMs. // Use TextEncoding::encode to encode, since it takes care of normalization. - std::auto_ptr<TextCodec> newTextCodec(const TextEncoding&); + PassOwnPtr<TextCodec> newTextCodec(const TextEncoding&); // Only TextEncoding should use this function directly. const char* atomicCanonicalTextEncodingName(const char* alias); diff --git a/WebCore/platform/text/mac/TextBoundaries.mm b/WebCore/platform/text/mac/TextBoundaries.mm index ff1dfd2..bd7ddf8 100644 --- a/WebCore/platform/text/mac/TextBoundaries.mm +++ b/WebCore/platform/text/mac/TextBoundaries.mm @@ -26,6 +26,8 @@ #import "config.h" #import "TextBoundaries.h" +using namespace WTF::Unicode; + namespace WebCore { void findWordBoundary(const UChar* chars, int len, int position, int* start, int* end) diff --git a/WebCore/platform/text/mac/TextCodecMac.cpp b/WebCore/platform/text/mac/TextCodecMac.cpp index 3baf21f..93b9da2 100644 --- a/WebCore/platform/text/mac/TextCodecMac.cpp +++ b/WebCore/platform/text/mac/TextCodecMac.cpp @@ -33,9 +33,9 @@ #include "PlatformString.h" #include "ThreadGlobalData.h" #include <wtf/Assertions.h> +#include <wtf/PassOwnPtr.h> #include <wtf/Threading.h> -using std::auto_ptr; using std::min; namespace WebCore { @@ -64,9 +64,9 @@ void TextCodecMac::registerEncodingNames(EncodingNameRegistrar registrar) } } -static auto_ptr<TextCodec> newTextCodecMac(const TextEncoding&, const void* additionalData) +static PassOwnPtr<TextCodec> newTextCodecMac(const TextEncoding&, const void* additionalData) { - return auto_ptr<TextCodec>(new TextCodecMac(*static_cast<const TECTextEncodingID*>(additionalData))); + return new TextCodecMac(*static_cast<const TECTextEncodingID*>(additionalData)); } void TextCodecMac::registerCodecs(TextCodecRegistrar registrar) diff --git a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp index 4dc23ee..06e8f37 100644 --- a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp +++ b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp @@ -20,6 +20,7 @@ * */ +#include "config.h" #include "TextBreakIterator.h" #if QT_VERSION >= 0x040400 diff --git a/WebCore/platform/text/qt/TextCodecQt.cpp b/WebCore/platform/text/qt/TextCodecQt.cpp index 0f385dd..c6c02cf 100644 --- a/WebCore/platform/text/qt/TextCodecQt.cpp +++ b/WebCore/platform/text/qt/TextCodecQt.cpp @@ -63,9 +63,9 @@ void TextCodecQt::registerEncodingNames(EncodingNameRegistrar registrar) } } -static std::auto_ptr<TextCodec> newTextCodecQt(const TextEncoding& encoding, const void*) +static PassOwnPtr<TextCodec> newTextCodecQt(const TextEncoding& encoding, const void*) { - return std::auto_ptr<TextCodec>(new TextCodecQt(encoding)); + return new TextCodecQt(encoding); } void TextCodecQt::registerCodecs(TextCodecRegistrar registrar) diff --git a/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp b/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp index 14cf130..ce436df 100644 --- a/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp +++ b/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp @@ -25,7 +25,11 @@ namespace WebCore { const char* currentTextBreakLocaleID() { - return "en_us"; + // Using en_US_POSIX now so word selection in address field works as expected as before (double-clicking + // in a URL selects a word delimited by periods rather than selecting the entire URL). + // However, this is not entirely correct - we should honor the system locale in the normal case. + // FIXME: <rdar://problem/6786703> Should use system locale for text breaking + return "en_US_POSIX"; } } |