diff options
author | Ben Murdoch <benm@google.com> | 2011-05-24 11:24:40 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-06-02 09:53:15 +0100 |
commit | 81bc750723a18f21cd17d1b173cd2a4dda9cea6e (patch) | |
tree | 7a9e5ed86ff429fd347a25153107221543909b19 /Source/JavaScriptCore/wtf/text | |
parent | 94088a6d336c1dd80a1e734af51e96abcbb689a7 (diff) | |
download | external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.zip external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.gz external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.bz2 |
Merge WebKit at r80534: Intial merge by Git
Change-Id: Ia7a83357124c9e1cdb1debf55d9661ec0bd09a61
Diffstat (limited to 'Source/JavaScriptCore/wtf/text')
-rw-r--r-- | Source/JavaScriptCore/wtf/text/AtomicString.h | 2 | ||||
-rw-r--r-- | Source/JavaScriptCore/wtf/text/StringImpl.cpp | 22 | ||||
-rw-r--r-- | Source/JavaScriptCore/wtf/text/StringImpl.h | 10 | ||||
-rw-r--r-- | Source/JavaScriptCore/wtf/text/TextPosition.h | 2 | ||||
-rw-r--r-- | Source/JavaScriptCore/wtf/text/WTFString.cpp | 25 | ||||
-rw-r--r-- | Source/JavaScriptCore/wtf/text/WTFString.h | 32 |
6 files changed, 64 insertions, 29 deletions
diff --git a/Source/JavaScriptCore/wtf/text/AtomicString.h b/Source/JavaScriptCore/wtf/text/AtomicString.h index ab5b366..45a71e7 100644 --- a/Source/JavaScriptCore/wtf/text/AtomicString.h +++ b/Source/JavaScriptCore/wtf/text/AtomicString.h @@ -95,7 +95,7 @@ public: static void remove(StringImpl*); -#if PLATFORM(CF) +#if USE(CF) AtomicString(CFStringRef s) : m_string(add(String(s).impl())) { } CFStringRef createCFString() const { return m_string.createCFString(); } #endif diff --git a/Source/JavaScriptCore/wtf/text/StringImpl.cpp b/Source/JavaScriptCore/wtf/text/StringImpl.cpp index c83ec42..9afd1d2 100644 --- a/Source/JavaScriptCore/wtf/text/StringImpl.cpp +++ b/Source/JavaScriptCore/wtf/text/StringImpl.cpp @@ -458,14 +458,14 @@ intptr_t StringImpl::toIntPtr(bool* ok) return charactersToIntPtr(m_data, m_length, ok); } -double StringImpl::toDouble(bool* ok) +double StringImpl::toDouble(bool* ok, bool* didReadNumber) { - return charactersToDouble(m_data, m_length, ok); + return charactersToDouble(m_data, m_length, ok, didReadNumber); } -float StringImpl::toFloat(bool* ok) +float StringImpl::toFloat(bool* ok, bool* didReadNumber) { - return charactersToFloat(m_data, m_length, ok); + return charactersToFloat(m_data, m_length, ok, didReadNumber); } static bool equal(const UChar* a, const char* b, int length) @@ -1005,15 +1005,23 @@ bool equalIgnoringNullity(StringImpl* a, StringImpl* b) return false; } -WTF::Unicode::Direction StringImpl::defaultWritingDirection() +WTF::Unicode::Direction StringImpl::defaultWritingDirection(bool* hasStrongDirectionality) { for (unsigned i = 0; i < m_length; ++i) { WTF::Unicode::Direction charDirection = WTF::Unicode::direction(m_data[i]); - if (charDirection == WTF::Unicode::LeftToRight) + if (charDirection == WTF::Unicode::LeftToRight) { + if (hasStrongDirectionality) + *hasStrongDirectionality = true; return WTF::Unicode::LeftToRight; - if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) + } + if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) { + if (hasStrongDirectionality) + *hasStrongDirectionality = true; return WTF::Unicode::RightToLeft; + } } + if (hasStrongDirectionality) + *hasStrongDirectionality = false; return WTF::Unicode::LeftToRight; } diff --git a/Source/JavaScriptCore/wtf/text/StringImpl.h b/Source/JavaScriptCore/wtf/text/StringImpl.h index 25411e1..a08427b 100644 --- a/Source/JavaScriptCore/wtf/text/StringImpl.h +++ b/Source/JavaScriptCore/wtf/text/StringImpl.h @@ -34,7 +34,7 @@ #include <wtf/text/StringImplBase.h> #include <wtf/unicode/Unicode.h> -#if PLATFORM(CF) +#if USE(CF) typedef const struct __CFString * CFStringRef; #endif @@ -281,8 +281,8 @@ public: 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); + double toDouble(bool* ok = 0, bool* didReadNumber = 0); + float toFloat(bool* ok = 0, bool* didReadNumber = 0); PassRefPtr<StringImpl> lower(); PassRefPtr<StringImpl> upper(); @@ -316,9 +316,9 @@ public: PassRefPtr<StringImpl> replace(StringImpl*, StringImpl*); PassRefPtr<StringImpl> replace(unsigned index, unsigned len, StringImpl*); - WTF::Unicode::Direction defaultWritingDirection(); + WTF::Unicode::Direction defaultWritingDirection(bool* hasStrongDirectionality = 0); -#if PLATFORM(CF) +#if USE(CF) CFStringRef createCFString(); #endif #ifdef __OBJC__ diff --git a/Source/JavaScriptCore/wtf/text/TextPosition.h b/Source/JavaScriptCore/wtf/text/TextPosition.h index 9f426ea..bb3ffa4 100644 --- a/Source/JavaScriptCore/wtf/text/TextPosition.h +++ b/Source/JavaScriptCore/wtf/text/TextPosition.h @@ -89,7 +89,7 @@ public: ZeroBasedNumber() {} int zeroBasedInt() const { return m_value; } - + int convertAsOneBasedInt() const { return m_value + 1; } OneBasedNumber convertToOneBased() const; bool operator==(ZeroBasedNumber other) { return m_value == other.m_value; } diff --git a/Source/JavaScriptCore/wtf/text/WTFString.cpp b/Source/JavaScriptCore/wtf/text/WTFString.cpp index b9b4e74..d862f96 100644 --- a/Source/JavaScriptCore/wtf/text/WTFString.cpp +++ b/Source/JavaScriptCore/wtf/text/WTFString.cpp @@ -561,24 +561,28 @@ intptr_t String::toIntPtr(bool* ok) const return m_impl->toIntPtr(ok); } -double String::toDouble(bool* ok) const +double String::toDouble(bool* ok, bool* didReadNumber) const { if (!m_impl) { if (ok) *ok = false; + if (didReadNumber) + *didReadNumber = false; return 0.0; } - return m_impl->toDouble(ok); + return m_impl->toDouble(ok, didReadNumber); } -float String::toFloat(bool* ok) const +float String::toFloat(bool* ok, bool* didReadNumber) const { if (!m_impl) { if (ok) *ok = false; + if (didReadNumber) + *didReadNumber = false; return 0.0f; } - return m_impl->toFloat(ok); + return m_impl->toFloat(ok, didReadNumber); } String String::threadsafeCopy() const @@ -937,11 +941,13 @@ 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) +double charactersToDouble(const UChar* data, size_t length, bool* ok, bool* didReadNumber) { if (!length) { if (ok) *ok = false; + if (didReadNumber) + *didReadNumber = false; return 0.0; } @@ -949,17 +955,20 @@ double charactersToDouble(const UChar* data, size_t length, bool* ok) for (unsigned i = 0; i < length; ++i) bytes[i] = data[i] < 0x7F ? data[i] : '?'; bytes[length] = '\0'; + char* start = bytes.data(); char* end; - double val = WTF::strtod(bytes.data(), &end); + double val = WTF::strtod(start, &end); if (ok) *ok = (end == 0 || *end == '\0'); + if (didReadNumber) + *didReadNumber = end - start; return val; } -float charactersToFloat(const UChar* data, size_t length, bool* ok) +float charactersToFloat(const UChar* data, size_t length, bool* ok, bool* didReadNumber) { // FIXME: This will return ok even when the string fits into a double but not a float. - return static_cast<float>(charactersToDouble(data, length, ok)); + return static_cast<float>(charactersToDouble(data, length, ok, didReadNumber)); } } // namespace WTF diff --git a/Source/JavaScriptCore/wtf/text/WTFString.h b/Source/JavaScriptCore/wtf/text/WTFString.h index 0aee2ef..713a6c3 100644 --- a/Source/JavaScriptCore/wtf/text/WTFString.h +++ b/Source/JavaScriptCore/wtf/text/WTFString.h @@ -31,7 +31,7 @@ #include <objc/objc.h> #endif -#if PLATFORM(CF) +#if USE(CF) typedef const struct __CFString * CFStringRef; #endif @@ -79,8 +79,8 @@ int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ignores traili 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); +double charactersToDouble(const UChar*, size_t, bool* ok = 0, bool* didReadNumber = 0); +float charactersToFloat(const UChar*, size_t, bool* ok = 0, bool* didReadNumber = 0); template<bool isSpecialCharacter(UChar)> bool isAllSpecialCharacters(const UChar*, size_t); @@ -92,6 +92,11 @@ public: // Construct a string with UTF-16 data. String(const UChar* characters, unsigned length); + // Construct a string by copying the contents of a vector. To avoid + // copying, consider using String::adopt instead. + template<size_t inlineCapacity> + explicit String(const Vector<UChar, inlineCapacity>&); + // Construct a string with UTF-16 data, from a null-terminated source. String(const UChar*); @@ -264,8 +269,8 @@ public: 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; + double toDouble(bool* ok = 0, bool* didReadNumber = 0) const; + float toFloat(bool* ok = 0, bool* didReadNumber = 0) const; bool percentage(int& percentage) const; @@ -284,7 +289,7 @@ public: operator UnspecifiedBoolTypeA() const; operator UnspecifiedBoolTypeB() const; -#if PLATFORM(CF) +#if USE(CF) String(CFStringRef); CFStringRef createCFString() const; #endif @@ -326,7 +331,14 @@ public: static String fromUTF8WithLatin1Fallback(const char*, size_t); // Determines the writing direction using the Unicode Bidi Algorithm rules P2 and P3. - WTF::Unicode::Direction defaultWritingDirection() const { return m_impl ? m_impl->defaultWritingDirection() : WTF::Unicode::LeftToRight; } + WTF::Unicode::Direction defaultWritingDirection(bool* hasStrongDirectionality = 0) const + { + if (m_impl) + return m_impl->defaultWritingDirection(hasStrongDirectionality); + if (hasStrongDirectionality) + *hasStrongDirectionality = false; + return WTF::Unicode::LeftToRight; + } bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); } bool containsOnlyLatin1() const { return charactersAreAllLatin1(characters(), length()); } @@ -378,6 +390,12 @@ inline void swap(String& a, String& b) { a.swap(b); } // Definitions of string operations +template<size_t inlineCapacity> +String::String(const Vector<UChar, inlineCapacity>& vector) + : m_impl(vector.size() ? StringImpl::create(vector.data(), vector.size()) : 0) +{ +} + #ifdef __OBJC__ // This is for situations in WebKit where the long standing behavior has been // "nil if empty", so we try to maintain longstanding behavior for the sake of |