diff options
author | Ben Murdoch <benm@google.com> | 2009-08-11 17:01:47 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2009-08-11 18:21:02 +0100 |
commit | 0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch) | |
tree | 2943df35f62d885c89d01063cc528dd73b480fea /WebCore/platform/text | |
parent | 7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff) | |
download | external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2 |
Merge in WebKit r47029.
Diffstat (limited to 'WebCore/platform/text')
21 files changed, 389 insertions, 77 deletions
diff --git a/WebCore/platform/text/BidiResolver.h b/WebCore/platform/text/BidiResolver.h index b6c2e88..286cdcd 100644 --- a/WebCore/platform/text/BidiResolver.h +++ b/WebCore/platform/text/BidiResolver.h @@ -29,6 +29,28 @@ namespace WebCore { +template <class Iterator> struct MidpointState { + MidpointState() + { + reset(); + } + + void reset() + { + numMidpoints = 0; + currentMidpoint = 0; + betweenMidpoints = false; + } + + // The goal is to reuse the line state across multiple + // lines so we just keep an array around for midpoints and never clear it across multiple + // lines. We track the number of items and position using the two other variables. + Vector<Iterator> midpoints; + unsigned numMidpoints; + unsigned currentMidpoint; + bool betweenMidpoints; +}; + // The BidiStatus at a given position (typically the end of a line) can // be cached and then used to restart bidi resolution at that position. struct BidiStatus { @@ -135,6 +157,8 @@ public : const BidiStatus& status() const { return m_status; } void setStatus(const BidiStatus s) { m_status = s; } + MidpointState<Iterator>& midpointState() { return m_midpointState; } + void embed(WTF::Unicode::Direction); void commitExplicitEmbedding(); @@ -172,6 +196,7 @@ protected: Run* m_lastRun; Run* m_logicallyLastRun; unsigned m_runCount; + MidpointState<Iterator> m_midpointState; private: void raiseExplicitEmbeddingLevel(WTF::Unicode::Direction from, WTF::Unicode::Direction to); diff --git a/WebCore/platform/text/CharacterNames.h b/WebCore/platform/text/CharacterNames.h index 5b1a337..cd09447 100644 --- a/WebCore/platform/text/CharacterNames.h +++ b/WebCore/platform/text/CharacterNames.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,22 +37,26 @@ namespace WebCore { const UChar blackSquare = 0x25A0; const UChar bullet = 0x2022; + const UChar hebrewPunctuationGeresh = 0x05F3; const UChar hebrewPunctuationGershayim = 0x05F4; const UChar horizontalEllipsis = 0x2026; - const UChar ideographicSpace = 0x3000; const UChar ideographicComma = 0x3001; const UChar ideographicFullStop = 0x3002; - const UChar leftToRightMark = 0x200E; + const UChar ideographicSpace = 0x3000; + const UChar leftDoubleQuotationMark = 0x201C; + const UChar leftSingleQuotationMark = 0x2018; const UChar leftToRightEmbed = 0x202A; + const UChar leftToRightMark = 0x200E; const UChar leftToRightOverride = 0x202D; const UChar newlineCharacter = 0x000A; const UChar noBreakSpace = 0x00A0; const UChar objectReplacementCharacter = 0xFFFC; const UChar popDirectionalFormatting = 0x202C; const UChar replacementCharacter = 0xFFFD; + const UChar rightDoubleQuotationMark = 0x201D; const UChar rightSingleQuotationMark = 0x2019; - const UChar rightToLeftMark = 0x200F; const UChar rightToLeftEmbed = 0x202B; + const UChar rightToLeftMark = 0x200F; const UChar rightToLeftOverride = 0x202E; const UChar softHyphen = 0x00AD; const UChar whiteBullet = 0x25E6; diff --git a/WebCore/platform/text/PlatformString.h b/WebCore/platform/text/PlatformString.h index 1cc60b2..6d5384f 100644 --- a/WebCore/platform/text/PlatformString.h +++ b/WebCore/platform/text/PlatformString.h @@ -49,6 +49,7 @@ typedef const struct __CFString * CFStringRef; QT_BEGIN_NAMESPACE class QString; QT_END_NAMESPACE +#include <QDataStream> #endif #if PLATFORM(WX) @@ -176,11 +177,13 @@ public: unsigned toUIntStrict(bool* ok = 0, int base = 10) const; int64_t toInt64Strict(bool* ok = 0, int base = 10) const; uint64_t toUInt64Strict(bool* ok = 0, int base = 10) const; + intptr_t toIntPtrStrict(bool* ok = 0, int base = 10) const; int toInt(bool* ok = 0) const; unsigned toUInt(bool* ok = 0) const; int64_t toInt64(bool* ok = 0) const; uint64_t toUInt64(bool* ok = 0) const; + intptr_t toIntPtr(bool* ok = 0) const; double toDouble(bool* ok = 0) const; float toFloat(bool* ok = 0) const; @@ -246,6 +249,11 @@ private: RefPtr<StringImpl> m_impl; }; +#if PLATFORM(QT) +QDataStream& operator<<(QDataStream& stream, const String& str); +QDataStream& operator>>(QDataStream& stream, String& str); +#endif + String operator+(const String&, const String&); String operator+(const String&, const char*); String operator+(const char*, const String&); @@ -264,6 +272,8 @@ inline bool equalIgnoringCase(const String& a, const String& b) { return equalIg inline bool equalIgnoringCase(const String& a, const char* b) { return equalIgnoringCase(a.impl(), b); } inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(a, b.impl()); } +inline bool equalIgnoringNullity(const String& a, const String& b) { return equalIgnoringNullity(a.impl(), b.impl()); } + inline bool operator!(const String& str) { return str.isNull(); } inline void swap(String& a, String& b) { a.swap(b); } @@ -276,11 +286,13 @@ int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10); unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10); int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10); uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10); +intptr_t charactersToIntPtrStrict(const UChar*, size_t, bool* ok = 0, int base = 10); int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage +intptr_t charactersToIntPtr(const UChar*, size_t, bool* ok = 0); // ignores trailing garbage double charactersToDouble(const UChar*, size_t, bool* ok = 0); float charactersToFloat(const UChar*, size_t, bool* ok = 0); diff --git a/WebCore/platform/text/String.cpp b/WebCore/platform/text/String.cpp index cd87e2c..2730939 100644 --- a/WebCore/platform/text/String.cpp +++ b/WebCore/platform/text/String.cpp @@ -1,6 +1,7 @@ /* * (C) 1999 Lars Knoll (knoll@kde.org) * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007-2009 Torch Mobile, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -353,6 +354,29 @@ String String::format(const char *format, ...) va_end(args); return buffer; + +#elif PLATFORM(WINCE) + va_list args; + va_start(args, format); + + Vector<char, 256> buffer; + + int bufferSize = 256; + buffer.resize(bufferSize); + for (;;) { + int written = vsnprintf(buffer.data(), bufferSize, format, args); + va_end(args); + + if (written == 0) + return String(""); + if (written > 0) + return StringImpl::create(buffer.data(), written); + + bufferSize <<= 1; + buffer.resize(bufferSize); + va_start(args, format); + } + #else va_list args; va_start(args, format); @@ -484,6 +508,17 @@ uint64_t String::toUInt64Strict(bool* ok, int base) const return m_impl->toUInt64Strict(ok, base); } +intptr_t String::toIntPtrStrict(bool* ok, int base) const +{ + if (!m_impl) { + if (ok) + *ok = false; + return 0; + } + return m_impl->toIntPtrStrict(ok, base); +} + + int String::toInt(bool* ok) const { if (!m_impl) { @@ -524,6 +559,16 @@ uint64_t String::toUInt64(bool* ok) const return m_impl->toUInt64(ok); } +intptr_t String::toIntPtr(bool* ok) const +{ + if (!m_impl) { + if (ok) + *ok = false; + return 0; + } + return m_impl->toIntPtr(ok); +} + double String::toDouble(bool* ok) const { if (!m_impl) { @@ -804,6 +849,11 @@ uint64_t charactersToUInt64Strict(const UChar* data, size_t length, bool* ok, in return toIntegralType<uint64_t>(data, length, ok, base); } +intptr_t charactersToIntPtrStrict(const UChar* data, size_t length, bool* ok, int base) +{ + return toIntegralType<intptr_t>(data, length, ok, base); +} + int charactersToInt(const UChar* data, size_t length, bool* ok) { return toIntegralType<int>(data, lengthOfCharactersAsInteger(data, length), ok, 10); @@ -824,6 +874,11 @@ uint64_t charactersToUInt64(const UChar* data, size_t length, bool* ok) return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger(data, length), ok, 10); } +intptr_t charactersToIntPtr(const UChar* data, size_t length, bool* ok) +{ + return toIntegralType<intptr_t>(data, lengthOfCharactersAsInteger(data, length), ok, 10); +} + double charactersToDouble(const UChar* data, size_t length, bool* ok) { if (!length) { diff --git a/WebCore/platform/text/StringBuffer.h b/WebCore/platform/text/StringBuffer.h index 28d4e89..353a44a 100644 --- a/WebCore/platform/text/StringBuffer.h +++ b/WebCore/platform/text/StringBuffer.h @@ -35,7 +35,7 @@ namespace WebCore { -class StringBuffer : Noncopyable { +class StringBuffer : public Noncopyable { public: explicit StringBuffer(unsigned length) : m_length(length) diff --git a/WebCore/platform/text/StringImpl.cpp b/WebCore/platform/text/StringImpl.cpp index 8bc4dde..8b749c7 100644 --- a/WebCore/platform/text/StringImpl.cpp +++ b/WebCore/platform/text/StringImpl.cpp @@ -205,24 +205,26 @@ bool StringImpl::containsOnlyWhitespace() return true; } -PassRefPtr<StringImpl> StringImpl::substring(unsigned pos, unsigned len) +PassRefPtr<StringImpl> StringImpl::substring(unsigned start, unsigned length) { - if (pos >= m_length) + if (start >= m_length) return empty(); - if (len > m_length - pos) - len = m_length - pos; - return create(m_data + pos, len); + unsigned maxLength = m_length - start; + if (length >= maxLength) { + if (!start) + return this; + length = maxLength; + } + return create(m_data + start, length); } -PassRefPtr<StringImpl> StringImpl::substringCopy(unsigned pos, unsigned len) +PassRefPtr<StringImpl> StringImpl::substringCopy(unsigned start, unsigned length) { - if (pos >= m_length) - pos = m_length; - if (len > m_length - pos) - len = m_length - pos; - if (!len) + start = min(start, m_length); + length = min(length, m_length - start); + if (!length) return adoptRef(new StringImpl); - return substring(pos, len); + return create(m_data + start, length); } UChar32 StringImpl::characterStartingAt(unsigned i) @@ -486,6 +488,11 @@ uint64_t StringImpl::toUInt64Strict(bool* ok, int base) return charactersToUInt64Strict(m_data, m_length, ok, base); } +intptr_t StringImpl::toIntPtrStrict(bool* ok, int base) +{ + return charactersToIntPtrStrict(m_data, m_length, ok, base); +} + int StringImpl::toInt(bool* ok) { return charactersToInt(m_data, m_length, ok); @@ -506,6 +513,11 @@ uint64_t StringImpl::toUInt64(bool* ok) return charactersToUInt64(m_data, m_length, ok); } +intptr_t StringImpl::toIntPtr(bool* ok) +{ + return charactersToIntPtr(m_data, m_length, ok); +} + double StringImpl::toDouble(bool* ok) { return charactersToDouble(m_data, m_length, ok); @@ -527,9 +539,8 @@ static bool equal(const UChar* a, const char* b, int length) return true; } -static bool equalIgnoringCase(const UChar* a, const char* b, int length) +bool equalIgnoringCase(const UChar* a, const char* b, unsigned length) { - ASSERT(length >= 0); while (length--) { unsigned char bc = *b++; if (foldCase(*a++) != foldCase(bc)) @@ -917,6 +928,18 @@ bool equalIgnoringCase(StringImpl* a, const char* b) return equal && !b[length]; } +bool equalIgnoringNullity(StringImpl* a, StringImpl* b) +{ + if (StringHash::equal(a, b)) + return true; + if (!a && b && !b->length()) + return true; + if (!b && a && !a->length()) + return true; + + return false; +} + Vector<char> StringImpl::ascii() { Vector<char> buffer(m_length + 1); @@ -1026,7 +1049,7 @@ PassRefPtr<StringImpl> StringImpl::create(const char* string) #if USE(JSC) PassRefPtr<StringImpl> StringImpl::create(const JSC::UString& str) { - SharedUChar* sharedBuffer = const_cast<JSC::UString*>(&str)->rep()->baseString()->sharedBuffer(); + SharedUChar* sharedBuffer = const_cast<JSC::UString*>(&str)->rep()->sharedBuffer(); if (sharedBuffer) { PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(const_cast<UChar*>(str.data()), str.size(), AdoptBuffer())); sharedBuffer->ref(); @@ -1038,7 +1061,7 @@ PassRefPtr<StringImpl> StringImpl::create(const JSC::UString& str) JSC::UString StringImpl::ustring() { - SharedUChar* sharedBuffer = StringImpl::sharedBuffer(); + SharedUChar* sharedBuffer = this->sharedBuffer(); if (sharedBuffer) return JSC::UString::Rep::create(const_cast<UChar*>(m_data), m_length, sharedBuffer); @@ -1053,7 +1076,8 @@ PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const Stri PassRefPtr<StringImpl> StringImpl::copy() { - return create(m_data, m_length); + // Using the constructor directly to make sure that per-thread empty string instance isn't returned. + return adoptRef(new StringImpl(m_data, m_length)); } StringImpl::SharedUChar* StringImpl::sharedBuffer() diff --git a/WebCore/platform/text/StringImpl.h b/WebCore/platform/text/StringImpl.h index f591800..8b4e82d 100644 --- a/WebCore/platform/text/StringImpl.h +++ b/WebCore/platform/text/StringImpl.h @@ -135,11 +135,13 @@ public: unsigned toUIntStrict(bool* ok = 0, int base = 10); int64_t toInt64Strict(bool* ok = 0, int base = 10); uint64_t toUInt64Strict(bool* ok = 0, int base = 10); + intptr_t toIntPtrStrict(bool* ok = 0, int base = 10); int toInt(bool* ok = 0); // ignores trailing garbage unsigned toUInt(bool* ok = 0); // ignores trailing garbage int64_t toInt64(bool* ok = 0); // ignores trailing garbage uint64_t toUInt64(bool* ok = 0); // ignores trailing garbage + intptr_t toIntPtr(bool* ok = 0); // ignores trailing garbage double toDouble(bool* ok = 0); float toFloat(bool* ok = 0); @@ -218,6 +220,10 @@ inline bool equal(const char* a, StringImpl* b) { return equal(b, a); } bool equalIgnoringCase(StringImpl*, StringImpl*); bool equalIgnoringCase(StringImpl*, const char*); inline bool equalIgnoringCase(const char* a, StringImpl* b) { return equalIgnoringCase(b, a); } +bool equalIgnoringCase(const UChar* a, const char* b, unsigned length); +inline bool equalIgnoringCase(const char* a, const UChar* b, unsigned length) { return equalIgnoringCase(b, a, length); } + +bool equalIgnoringNullity(StringImpl*, StringImpl*); // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's // or anything like that. diff --git a/WebCore/platform/text/TextBreakIteratorICU.cpp b/WebCore/platform/text/TextBreakIteratorICU.cpp index c4fc1b0..c922fbc 100644 --- a/WebCore/platform/text/TextBreakIteratorICU.cpp +++ b/WebCore/platform/text/TextBreakIteratorICU.cpp @@ -160,7 +160,7 @@ TextBreakIterator* cursorMovementIterator(const UChar* string, int length) "$LF = [\\p{Grapheme_Cluster_Break = LF}];" "$Control = [\\p{Grapheme_Cluster_Break = Control}];" "$VoiceMarks = [\\uFF9E\\uFF9F];" // Japanese half-width katakana voiced marks - "$Extend = [\\p{Grapheme_Cluster_Break = Extend} $VoiceMarks];" + "$Extend = [\\p{Grapheme_Cluster_Break = Extend} $VoiceMarks - [\\u0E30 \\u0E32 \\u0E45 \\u0EB0 \\u0EB2]];" "$SpacingMark = [[\\p{General_Category = Spacing Mark}] - $Extend];" "$L = [\\p{Grapheme_Cluster_Break = L}];" "$V = [\\p{Grapheme_Cluster_Break = V}];" diff --git a/WebCore/platform/text/TextBreakIteratorInternalICU.h b/WebCore/platform/text/TextBreakIteratorInternalICU.h index d4b25e7..68b7003 100644 --- a/WebCore/platform/text/TextBreakIteratorInternalICU.h +++ b/WebCore/platform/text/TextBreakIteratorInternalICU.h @@ -21,10 +21,12 @@ #ifndef TextBreakIteratorInternalICU_h #define TextBreakIteratorInternalICU_h -#include <wtf/unicode/Unicode.h> +// FIXME: Now that this handles locales for ICU, not just for text breaking, +// this file and the various implementation files should be renamed. namespace WebCore { + const char* currentSearchLocaleID(); const char* currentTextBreakLocaleID(); } diff --git a/WebCore/platform/text/TextCodec.h b/WebCore/platform/text/TextCodec.h index df42582..3c74165 100644 --- a/WebCore/platform/text/TextCodec.h +++ b/WebCore/platform/text/TextCodec.h @@ -56,7 +56,7 @@ namespace WebCore { typedef char UnencodableReplacementArray[32]; - class TextCodec : Noncopyable { + class TextCodec : public Noncopyable { public: virtual ~TextCodec(); diff --git a/WebCore/platform/text/TextEncoding.cpp b/WebCore/platform/text/TextEncoding.cpp index 5fa927b..b76f739 100644 --- a/WebCore/platform/text/TextEncoding.cpp +++ b/WebCore/platform/text/TextEncoding.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> + * Copyright (C) 2007-2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -113,6 +114,10 @@ CString TextEncoding::encode(const UChar* characters, size_t length, Unencodable QString str(reinterpret_cast<const QChar*>(characters), length); str = str.normalized(QString::NormalizationForm_C); return newTextCodec(*this)->encode(reinterpret_cast<const UChar *>(str.utf16()), str.length(), handling); +#elif PLATFORM(WINCE) + // normalization will be done by Windows CE API + OwnPtr<TextCodec> textCodec = newTextCodec(*this); + return textCodec.get() ? textCodec->encode(characters, length, handling) : CString(); #endif } diff --git a/WebCore/platform/text/TextEncodingRegistry.cpp b/WebCore/platform/text/TextEncodingRegistry.cpp index 3c9d65f..5ab1c87 100644 --- a/WebCore/platform/text/TextEncodingRegistry.cpp +++ b/WebCore/platform/text/TextEncodingRegistry.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007-2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,6 +48,9 @@ #if PLATFORM(QT) #include "qt/TextCodecQt.h" #endif +#if PLATFORM(WINCE) +#include "TextCodecWince.h" +#endif using namespace WTF; @@ -189,6 +193,11 @@ static void buildBaseTextCodecMaps() TextCodecICU::registerBaseEncodingNames(addToTextEncodingNameMap); TextCodecICU::registerBaseCodecs(addToTextCodecMap); #endif + +#if PLATFORM(WINCE) + TextCodecWince::registerBaseEncodingNames(addToTextEncodingNameMap); + TextCodecWince::registerBaseCodecs(addToTextCodecMap); +#endif } static void extendTextCodecMaps() @@ -207,6 +216,11 @@ static void extendTextCodecMaps() TextCodecMac::registerEncodingNames(addToTextEncodingNameMap); TextCodecMac::registerCodecs(addToTextCodecMap); #endif + +#if PLATFORM(WINCE) + TextCodecWince::registerExtendedEncodingNames(addToTextEncodingNameMap); + TextCodecWince::registerExtendedCodecs(addToTextCodecMap); +#endif } PassOwnPtr<TextCodec> newTextCodec(const TextEncoding& encoding) diff --git a/WebCore/platform/text/chromium/TextBreakIteratorInternalICUChromium.cpp b/WebCore/platform/text/chromium/TextBreakIteratorInternalICUChromium.cpp index 09096d7..4e2aceb 100644 --- a/WebCore/platform/text/chromium/TextBreakIteratorInternalICUChromium.cpp +++ b/WebCore/platform/text/chromium/TextBreakIteratorInternalICUChromium.cpp @@ -24,8 +24,15 @@ namespace WebCore { +const char* currentSearchLocaleID() +{ + // FIXME: Should use system locale. + return ""; +} + const char* currentTextBreakLocaleID() { + // FIXME: Should use system locale. return "en_us"; } diff --git a/WebCore/platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp b/WebCore/platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp index 9b9bd1f..35e5a05 100644 --- a/WebCore/platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp +++ b/WebCore/platform/text/gtk/TextBreakIteratorInternalICUGtk.cpp @@ -22,8 +22,15 @@ namespace WebCore { +const char* currentSearchLocaleID() +{ + // FIXME: Should use system locale. + return ""; +} + const char* currentTextBreakLocaleID() { + // FIXME: Should use system locale. return "en_us"; } diff --git a/WebCore/platform/text/haiku/StringHaiku.cpp b/WebCore/platform/text/haiku/StringHaiku.cpp new file mode 100644 index 0000000..9e0fd3f --- /dev/null +++ b/WebCore/platform/text/haiku/StringHaiku.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Ryan Leavengood <leavengood@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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR + * 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 "CString.h" + +#include "PlatformString.h" + +#include <String.h> + + +namespace WebCore { + +// String conversions +String::String(const BString& str) +{ + m_impl = String::fromUTF8(str.String(), str.Length()).impl(); +} + +String::operator BString() const +{ + BString string; + string.SetTo(utf8().data()); + + return string; +} + +} // namespace WebCore + diff --git a/WebCore/platform/text/haiku/TextBreakIteratorInternalICUHaiku.cpp b/WebCore/platform/text/haiku/TextBreakIteratorInternalICUHaiku.cpp new file mode 100644 index 0000000..2c732d6 --- /dev/null +++ b/WebCore/platform/text/haiku/TextBreakIteratorInternalICUHaiku.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007 Apple 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 + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" +#include "TextBreakIteratorInternalICU.h" + +#include "NotImplemented.h" + + +namespace WebCore { + +const char* currentTextBreakLocaleID() +{ + notImplemented(); + return "en_us"; +} + +} // namespace WebCore + diff --git a/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm b/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm index 92983eb..5da10e0 100644 --- a/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm +++ b/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2009 Apple 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 @@ -21,41 +21,79 @@ #include "config.h" #include "TextBreakIteratorInternalICU.h" +#include <wtf/RetainPtr.h> + namespace WebCore { static const int maxLocaleStringLength = 32; -// This code was swiped from the CarbonCore UnicodeUtilities. One change from that is to use the empty -// string instead of the "old locale model" as the ultimate fallback. This change is per the UnicodeUtilities -// engineer. -static void getTextBreakLocale(char localeStringBuffer[maxLocaleStringLength]) +static inline RetainPtr<CFStringRef> textBreakLocalePreference() { - // Empty string means "root locale", which is what we use if we can't use a pref. + RetainPtr<CFPropertyListRef> locale(AdoptCF, CFPreferencesCopyValue(CFSTR("AppleTextBreakLocale"), + kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)); + if (!locale || CFGetTypeID(locale.get()) != CFStringGetTypeID()) + return 0; + return static_cast<CFStringRef>(locale.get()); +} - // We get the parts string from AppleTextBreakLocale pref. - // If that fails then look for the first language in the AppleLanguages pref. - CFStringRef prefLocaleStr = (CFStringRef)CFPreferencesCopyValue(CFSTR("AppleTextBreakLocale"), - kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - if (!prefLocaleStr) { - CFArrayRef appleLangArr = (CFArrayRef)CFPreferencesCopyValue(CFSTR("AppleLanguages"), - kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - if (appleLangArr) { - // Take the topmost language. Retain so that we can blindly release later. - prefLocaleStr = (CFStringRef)CFArrayGetValueAtIndex(appleLangArr, 0); - if (prefLocaleStr) - CFRetain(prefLocaleStr); - CFRelease(appleLangArr); - } - } - if (prefLocaleStr) { - // Canonicalize pref string in case it is not in the canonical format. - CFStringRef canonLocaleCFStr = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, prefLocaleStr); - if (canonLocaleCFStr) { - CFStringGetCString(canonLocaleCFStr, localeStringBuffer, maxLocaleStringLength, kCFStringEncodingASCII); - CFRelease(canonLocaleCFStr); - } - CFRelease(prefLocaleStr); +static RetainPtr<CFStringRef> topLanguagePreference() +{ + RetainPtr<CFPropertyListRef> languages(AdoptCF, CFPreferencesCopyValue(CFSTR("AppleLanguages"), + kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)); + if (!languages || CFGetTypeID(languages.get()) != CFArrayGetTypeID()) + return 0; + CFArrayRef languagesArray = static_cast<CFArrayRef>(languages.get()); + if (CFArrayGetCount(languagesArray) < 1) + return 0; + const void* value = CFArrayGetValueAtIndex(languagesArray, 0); + if (!value || CFGetTypeID(value) != CFStringGetTypeID()) + return 0; + return static_cast<CFStringRef>(value); +} + +static RetainPtr<CFStringRef> canonicalLanguageIdentifier(CFStringRef locale) +{ + if (!locale) + return 0; + RetainPtr<CFStringRef> canonicalLocale(AdoptCF, + CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, locale)); + if (!canonicalLocale) + return locale; + return canonicalLocale; +} + +static void getLocale(CFStringRef locale, char localeStringBuffer[maxLocaleStringLength]) +{ + // Empty string means "root locale", and that is what we use if we can't get a preference. + localeStringBuffer[0] = 0; + if (!locale) + return; + CFStringGetCString(locale, localeStringBuffer, maxLocaleStringLength, kCFStringEncodingASCII); +} + +static void getSearchLocale(char localeStringBuffer[maxLocaleStringLength]) +{ + getLocale(canonicalLanguageIdentifier(topLanguagePreference().get()).get(), localeStringBuffer); +} + +const char* currentSearchLocaleID() +{ + static char localeStringBuffer[maxLocaleStringLength]; + static bool gotSearchLocale = false; + if (!gotSearchLocale) { + getSearchLocale(localeStringBuffer); + gotSearchLocale = true; } + return localeStringBuffer; +} + +static void getTextBreakLocale(char localeStringBuffer[maxLocaleStringLength]) +{ + // If there is no text break locale, use the top language preference. + RetainPtr<CFStringRef> locale = textBreakLocalePreference(); + if (!locale) + locale = topLanguagePreference(); + getLocale(canonicalLanguageIdentifier(locale.get()).get(), localeStringBuffer); } const char* currentTextBreakLocaleID() diff --git a/WebCore/platform/text/qt/StringQt.cpp b/WebCore/platform/text/qt/StringQt.cpp index de9f527..62aa979 100644 --- a/WebCore/platform/text/qt/StringQt.cpp +++ b/WebCore/platform/text/qt/StringQt.cpp @@ -41,7 +41,7 @@ String::String(const QString& qstr) String::String(const QStringRef& ref) { - if (!ref.string()) + if (!ref.string()) return; m_impl = StringImpl::create(reinterpret_cast<const UChar*>(ref.unicode()), ref.length()); } @@ -51,6 +51,22 @@ String::operator QString() const return QString(reinterpret_cast<const QChar*>(characters()), length()); } +QDataStream& operator<<(QDataStream& stream, const String& str) +{ + // could be faster + stream << QString(str); + return stream; +} + +QDataStream& operator>>(QDataStream& stream, String& str) +{ + // mabe not the fastest way, but really easy + QString tmp; + stream >> tmp; + str = tmp; + return stream; +} + } // vim: ts=4 sw=4 et diff --git a/WebCore/platform/text/qt/TextBoundaries.cpp b/WebCore/platform/text/qt/TextBoundaries.cpp index bdc851b..ffc4c44 100644 --- a/WebCore/platform/text/qt/TextBoundaries.cpp +++ b/WebCore/platform/text/qt/TextBoundaries.cpp @@ -39,8 +39,7 @@ #if QT_VERSION >= 0x040400 #include <qtextboundaryfinder.h> -namespace WebCore -{ +namespace WebCore { int findNextWordFromIndex(UChar const* buffer, int len, int position, bool forward) { @@ -78,9 +77,8 @@ void findWordBoundary(UChar const* buffer, int len, int position, int* start, in } #else -namespace WebCore -{ - +namespace WebCore { + int findNextWordFromIndex(UChar const* buffer, int len, int position, bool forward) { QString str(reinterpret_cast<QChar const*>(buffer), len); diff --git a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp index 06e8f37..d80e270 100644 --- a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp +++ b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp @@ -36,8 +36,7 @@ namespace WebCore { - class TextBreakIterator : public QTextBoundaryFinder - { + class TextBreakIterator : public QTextBoundaryFinder { }; static QTextBoundaryFinder* iterator = 0; static unsigned char buffer[1024]; @@ -138,17 +137,18 @@ namespace WebCore { namespace WebCore { - class TextBreakIterator - { + class TextBreakIterator { public: virtual int first() = 0; virtual int next() = 0; virtual int previous() = 0; - inline int following(int pos) { + inline int following(int pos) + { currentPos = pos; return next(); } - inline int preceding(int pos) { + inline int preceding(int pos) + { currentPos = pos; return previous(); } @@ -157,16 +157,14 @@ namespace WebCore { int length; }; - class WordBreakIteratorQt : public TextBreakIterator - { + class WordBreakIteratorQt : public TextBreakIterator { public: virtual int first(); virtual int next(); virtual int previous(); }; - class CharBreakIteratorQt : public TextBreakIterator - { + class CharBreakIteratorQt : public TextBreakIterator { public: virtual int first(); virtual int next(); @@ -174,12 +172,14 @@ namespace WebCore { QTextLayout layout; }; - int WordBreakIteratorQt::first() { + int WordBreakIteratorQt::first() + { currentPos = 0; return currentPos; } - int WordBreakIteratorQt::next() { + int WordBreakIteratorQt::next() + { if (currentPos >= length) { currentPos = -1; return currentPos; @@ -194,7 +194,9 @@ namespace WebCore { } return currentPos; } - int WordBreakIteratorQt::previous() { + + int WordBreakIteratorQt::previous() + { if (currentPos <= 0) { currentPos = -1; return currentPos; @@ -210,18 +212,22 @@ namespace WebCore { return currentPos; } - int CharBreakIteratorQt::first() { + int CharBreakIteratorQt::first() + { currentPos = 0; return currentPos; } - int CharBreakIteratorQt::next() { + int CharBreakIteratorQt::next() + { if (currentPos >= length) return -1; currentPos = layout.nextCursorPosition(currentPos); return currentPos; } - int CharBreakIteratorQt::previous() { + + int CharBreakIteratorQt::previous() + { if (currentPos <= 0) return -1; currentPos = layout.previousCursorPosition(currentPos); @@ -252,7 +258,7 @@ TextBreakIterator* characterBreakIterator(const UChar* string, int length) iterator->length = length; iterator->currentPos = 0; iterator->layout.setText(QString(reinterpret_cast<const QChar*>(string), length)); - + return iterator; } diff --git a/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp b/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp index ce436df..e417e17 100644 --- a/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp +++ b/WebCore/platform/text/win/TextBreakIteratorInternalICUWin.cpp @@ -23,6 +23,12 @@ namespace WebCore { +const char* currentSearchLocaleID() +{ + // FIXME: Should use system locale. + return ""; +} + const char* currentTextBreakLocaleID() { // Using en_US_POSIX now so word selection in address field works as expected as before (double-clicking |