From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WTF/wtf/text/StringConcatenate.h | 893 +++++--------------------------- 1 file changed, 132 insertions(+), 761 deletions(-) (limited to 'Source/WTF/wtf/text/StringConcatenate.h') diff --git a/Source/WTF/wtf/text/StringConcatenate.h b/Source/WTF/wtf/text/StringConcatenate.h index baeccc1d2..affb7e195 100644 --- a/Source/WTF/wtf/text/StringConcatenate.h +++ b/Source/WTF/wtf/text/StringConcatenate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010-2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,10 +28,14 @@ #include -#ifndef WTFString_h +#ifndef AtomicString_h #include #endif +#ifndef StringView_h +#include +#endif + // This macro is helpful for testing how many intermediate Strings are created while evaluating an // expression containing operator+. #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING @@ -41,382 +45,221 @@ namespace WTF { template -class StringTypeAdapter { -}; +class StringTypeAdapter; template<> class StringTypeAdapter { public: - StringTypeAdapter(char buffer) - : m_buffer(buffer) + StringTypeAdapter(char character) + : m_character(character) { } unsigned length() { return 1; } - bool is8Bit() { return true; } - void writeTo(LChar* destination) + void writeTo(LChar* destination) const { - *destination = m_buffer; + *destination = m_character; } - void writeTo(UChar* destination) { *destination = m_buffer; } - -private: - unsigned char m_buffer; -}; - -template<> -class StringTypeAdapter { -public: - StringTypeAdapter(LChar buffer) - : m_buffer(buffer) - { - } - - unsigned length() { return 1; } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) + void writeTo(UChar* destination) const { - *destination = m_buffer; + *destination = m_character; } - void writeTo(UChar* destination) { *destination = m_buffer; } + String toString() const { return String(&m_character, 1); } private: - LChar m_buffer; + char m_character; }; template<> class StringTypeAdapter { public: - StringTypeAdapter(UChar buffer) - : m_buffer(buffer) + StringTypeAdapter(UChar character) + : m_character(character) { } - unsigned length() { return 1; } - - bool is8Bit() { return m_buffer <= 0xff; } + unsigned length() const { return 1; } + bool is8Bit() const { return m_character <= 0xff; } - void writeTo(LChar* destination) + void writeTo(LChar* destination) const { ASSERT(is8Bit()); - *destination = static_cast(m_buffer); + *destination = static_cast(m_character); } - void writeTo(UChar* destination) { *destination = m_buffer; } - -private: - UChar m_buffer; -}; - -template<> -class StringTypeAdapter { -public: - StringTypeAdapter(char* buffer) - : m_buffer(buffer) - , m_length(strlen(buffer)) - { - } - - unsigned length() { return m_length; } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) + void writeTo(UChar* destination) const { - for (unsigned i = 0; i < m_length; ++i) - destination[i] = static_cast(m_buffer[i]); + *destination = m_character; } - void writeTo(UChar* destination) - { - for (unsigned i = 0; i < m_length; ++i) { - unsigned char c = m_buffer[i]; - destination[i] = c; - } - } + String toString() const { return String(&m_character, 1); } private: - const char* m_buffer; - unsigned m_length; + UChar m_character; }; template<> -class StringTypeAdapter { +class StringTypeAdapter { public: - StringTypeAdapter(LChar* buffer) - : m_buffer(buffer) - , m_length(strlen(reinterpret_cast(buffer))) + StringTypeAdapter(const LChar* characters) + : m_characters(characters) + , m_length(strlen(reinterpret_cast(characters))) { } - unsigned length() { return m_length; } - - bool is8Bit() { return true; } + unsigned length() const { return m_length; } + bool is8Bit() const { return true; } - void writeTo(LChar* destination) + void writeTo(LChar* destination) const { - memcpy(destination, m_buffer, m_length * sizeof(LChar)); + StringView(m_characters, m_length).getCharactersWithUpconvert(destination); } - void writeTo(UChar* destination) + void writeTo(UChar* destination) const { - StringImpl::copyChars(destination, m_buffer, m_length); + StringView(m_characters, m_length).getCharactersWithUpconvert(destination); } + String toString() const { return String(m_characters, m_length); } + private: - const LChar* m_buffer; + const LChar* m_characters; unsigned m_length; }; template<> class StringTypeAdapter { public: - StringTypeAdapter(const UChar* buffer) - : m_buffer(buffer) + StringTypeAdapter(const UChar* characters) + : m_characters(characters) { - size_t len = 0; - while (m_buffer[len] != UChar(0)) - ++len; + unsigned length = 0; + while (m_characters[length]) + ++length; - if (len > std::numeric_limits::max()) + if (length > std::numeric_limits::max()) // FIXME this is silly https://bugs.webkit.org/show_bug.cgi?id=165790 CRASH(); - m_length = len; + m_length = length; } - unsigned length() { return m_length; } + unsigned length() const { return m_length; } + bool is8Bit() const { return false; } - bool is8Bit() { return false; } - - NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) + NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) const { - CRASH(); + CRASH(); // FIXME make this a compile-time failure https://bugs.webkit.org/show_bug.cgi?id=165791 } - void writeTo(UChar* destination) + void writeTo(UChar* destination) const { - memcpy(destination, m_buffer, m_length * sizeof(UChar)); + memcpy(destination, m_characters, m_length * sizeof(UChar)); } + String toString() const { return String(m_characters, m_length); } + private: - const UChar* m_buffer; + const UChar* m_characters; unsigned m_length; }; template<> -class StringTypeAdapter { +class StringTypeAdapter : public StringTypeAdapter { public: - StringTypeAdapter(const char* buffer) - : m_buffer(buffer) - , m_length(strlen(buffer)) - { - } - - unsigned length() { return m_length; } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) - { - memcpy(destination, m_buffer, static_cast(m_length) * sizeof(LChar)); - } - - void writeTo(UChar* destination) + StringTypeAdapter(const char* characters) + : StringTypeAdapter(reinterpret_cast(characters)) { - for (unsigned i = 0; i < m_length; ++i) { - unsigned char c = m_buffer[i]; - destination[i] = c; - } } - -private: - const char* m_buffer; - unsigned m_length; }; template<> -class StringTypeAdapter { +class StringTypeAdapter : public StringTypeAdapter { public: - StringTypeAdapter(const LChar* buffer) - : m_buffer(buffer) - , m_length(strlen(reinterpret_cast(buffer))) - { - } - - unsigned length() { return m_length; } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) + StringTypeAdapter(const char* characters) + : StringTypeAdapter(characters) { - memcpy(destination, m_buffer, static_cast(m_length) * sizeof(LChar)); } - - void writeTo(UChar* destination) - { - StringImpl::copyChars(destination, m_buffer, m_length); - } - -private: - const LChar* m_buffer; - unsigned m_length; }; template<> -class StringTypeAdapter { +class StringTypeAdapter : public StringTypeAdapter { public: - StringTypeAdapter(ASCIILiteral buffer) - : m_buffer(reinterpret_cast(static_cast(buffer))) - , m_length(strlen(buffer)) - { - } - - size_t length() { return m_length; } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) - { - memcpy(destination, m_buffer, static_cast(m_length)); - } - - void writeTo(UChar* destination) + StringTypeAdapter(ASCIILiteral characters) + : StringTypeAdapter(characters) { - StringImpl::copyChars(destination, m_buffer, m_length); } - -private: - const LChar* m_buffer; - unsigned m_length; }; template<> class StringTypeAdapter> { public: - StringTypeAdapter>(const Vector& buffer) - : m_buffer(buffer) + StringTypeAdapter(const Vector& vector) + : m_vector(vector) { } - size_t length() { return m_buffer.size(); } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) - { - for (size_t i = 0; i < m_buffer.size(); ++i) - destination[i] = static_cast(m_buffer[i]); - } + size_t length() const { return m_vector.size(); } + bool is8Bit() const { return true; } - void writeTo(UChar* destination) - { - for (size_t i = 0; i < m_buffer.size(); ++i) - destination[i] = static_cast(m_buffer[i]); - } - -private: - const Vector& m_buffer; -}; - -template<> -class StringTypeAdapter> { -public: - StringTypeAdapter>(const Vector& buffer) - : m_buffer(buffer) + void writeTo(LChar* destination) const { + StringView(reinterpret_cast(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination); } - size_t length() { return m_buffer.size(); } - - bool is8Bit() { return true; } - - void writeTo(LChar* destination) + void writeTo(UChar* destination) const { - for (size_t i = 0; i < m_buffer.size(); ++i) - destination[i] = m_buffer[i]; + StringView(reinterpret_cast(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination); } - void writeTo(UChar* destination) - { - for (size_t i = 0; i < m_buffer.size(); ++i) - destination[i] = m_buffer[i]; - } + String toString() const { return String(m_vector.data(), m_vector.size()); } private: - const Vector& m_buffer; + const Vector& m_vector; }; template<> class StringTypeAdapter { public: StringTypeAdapter(const String& string) - : m_buffer(string) + : m_string(string) { } - unsigned length() { return m_buffer.length(); } + unsigned length() const { return m_string.length(); } + bool is8Bit() const { return m_string.isNull() || m_string.is8Bit(); } - bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); } - - void writeTo(LChar* destination) + void writeTo(LChar* destination) const { - unsigned length = m_buffer.length(); - - ASSERT(is8Bit()); - const LChar* data = m_buffer.characters8(); - for (unsigned i = 0; i < length; ++i) - destination[i] = data[i]; - + StringView(m_string).getCharactersWithUpconvert(destination); WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); } - void writeTo(UChar* destination) + void writeTo(UChar* destination) const { - unsigned length = m_buffer.length(); - - if (is8Bit()) { - const LChar* data = m_buffer.characters8(); - for (unsigned i = 0; i < length; ++i) - destination[i] = data[i]; - } else { - const UChar* data = m_buffer.characters16(); - for (unsigned i = 0; i < length; ++i) - destination[i] = data[i]; - } - + StringView(m_string).getCharactersWithUpconvert(destination); WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); } + String toString() const { return m_string; } + private: - const String& m_buffer; + const String& m_string; }; template<> -class StringTypeAdapter { +class StringTypeAdapter : public StringTypeAdapter { public: - StringTypeAdapter(const AtomicString& string) - : m_adapter(string.string()) + StringTypeAdapter(const AtomicString& string) + : StringTypeAdapter(string.string()) { } - - unsigned length() { return m_adapter.length(); } - - bool is8Bit() { return m_adapter.is8Bit(); } - - void writeTo(LChar* destination) { m_adapter.writeTo(destination); } - void writeTo(UChar* destination) { m_adapter.writeTo(destination); } - -private: - StringTypeAdapter m_adapter; }; -inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow) +inline void sumWithOverflow(bool& overflow, unsigned& total, unsigned addend) { unsigned oldTotal = total; total = oldTotal + addend; @@ -424,569 +267,97 @@ inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow) overflow = true; } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2) -{ - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - - return resultImpl.release(); -} - -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3) +template +inline void sumWithOverflow(bool& overflow, unsigned& total, unsigned addend, Unsigned ...addends) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer = 0; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - - return resultImpl.release(); + unsigned oldTotal = total; + total = oldTotal + addend; + if (total < oldTotal) + overflow = true; + sumWithOverflow(overflow, total, addends...); } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4) +template +inline bool are8Bit(Adapter adapter) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - - return resultImpl.release(); + return adapter.is8Bit(); } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5) +template +inline bool are8Bit(Adapter adapter, Adapters ...adapters) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - StringTypeAdapter adapter5(string5); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - sumWithOverflow(length, adapter5.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - - return resultImpl.release(); + return adapter.is8Bit() && are8Bit(adapters...); } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6) +template +inline void makeStringAccumulator(ResultType* result, Adapter adapter) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - StringTypeAdapter adapter5(string5); - StringTypeAdapter adapter6(string6); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - sumWithOverflow(length, adapter5.length(), overflow); - sumWithOverflow(length, adapter6.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - - return resultImpl.release(); + adapter.writeTo(result); } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7) +template +inline void makeStringAccumulator(ResultType* result, Adapter adapter, Adapters ...adapters) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - StringTypeAdapter adapter5(string5); - StringTypeAdapter adapter6(string6); - StringTypeAdapter adapter7(string7); - - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - sumWithOverflow(length, adapter5.length(), overflow); - sumWithOverflow(length, adapter6.length(), overflow); - sumWithOverflow(length, adapter7.length(), overflow); - if (overflow) - return 0; - - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit() && adapter7.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - - return resultImpl.release(); + adapter.writeTo(result); + makeStringAccumulator(result + adapter.length(), adapters...); } -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8) +template +String tryMakeStringFromAdapters(StringTypeAdapter adapter, StringTypeAdapters ...adapters) { - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - StringTypeAdapter adapter5(string5); - StringTypeAdapter adapter6(string6); - StringTypeAdapter adapter7(string7); - StringTypeAdapter adapter8(string8); - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - sumWithOverflow(length, adapter5.length(), overflow); - sumWithOverflow(length, adapter6.length(), overflow); - sumWithOverflow(length, adapter7.length(), overflow); - sumWithOverflow(length, adapter8.length(), overflow); + unsigned length = adapter.length(); + sumWithOverflow(overflow, length, adapters.length()...); if (overflow) - return 0; + return String(); - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit() && adapter7.is8Bit() && adapter8.is8Bit()) { + if (are8Bit(adapter, adapters...)) { LChar* buffer; RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - result += adapter7.length(); - adapter8.writeTo(result); - - return resultImpl.release(); - } - - UChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - result += adapter7.length(); - adapter8.writeTo(result); - - return resultImpl.release(); -} - -template -PassRefPtr tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8, StringType9 string9) -{ - StringTypeAdapter adapter1(string1); - StringTypeAdapter adapter2(string2); - StringTypeAdapter adapter3(string3); - StringTypeAdapter adapter4(string4); - StringTypeAdapter adapter5(string5); - StringTypeAdapter adapter6(string6); - StringTypeAdapter adapter7(string7); - StringTypeAdapter adapter8(string8); - StringTypeAdapter adapter9(string9); + return String(); - bool overflow = false; - unsigned length = adapter1.length(); - sumWithOverflow(length, adapter2.length(), overflow); - sumWithOverflow(length, adapter3.length(), overflow); - sumWithOverflow(length, adapter4.length(), overflow); - sumWithOverflow(length, adapter5.length(), overflow); - sumWithOverflow(length, adapter6.length(), overflow); - sumWithOverflow(length, adapter7.length(), overflow); - sumWithOverflow(length, adapter8.length(), overflow); - sumWithOverflow(length, adapter9.length(), overflow); - if (overflow) - return 0; + makeStringAccumulator(buffer, adapter, adapters...); - if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit() && adapter7.is8Bit() && adapter8.is8Bit() && adapter9.is8Bit()) { - LChar* buffer; - RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); - if (!resultImpl) - return 0; - - LChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - result += adapter7.length(); - adapter8.writeTo(result); - result += adapter8.length(); - adapter9.writeTo(result); - - return resultImpl.release(); + return WTFMove(resultImpl); } UChar* buffer; RefPtr resultImpl = StringImpl::tryCreateUninitialized(length, buffer); if (!resultImpl) - return 0; - - UChar* result = buffer; - adapter1.writeTo(result); - result += adapter1.length(); - adapter2.writeTo(result); - result += adapter2.length(); - adapter3.writeTo(result); - result += adapter3.length(); - adapter4.writeTo(result); - result += adapter4.length(); - adapter5.writeTo(result); - result += adapter5.length(); - adapter6.writeTo(result); - result += adapter6.length(); - adapter7.writeTo(result); - result += adapter7.length(); - adapter8.writeTo(result); - result += adapter8.length(); - adapter9.writeTo(result); - - return resultImpl.release(); -} - - -// Convenience only. -template -String makeString(StringType1 string1) -{ - return String(string1); -} - -template -String makeString(StringType1 string1, StringType2 string2) -{ - RefPtr resultImpl = tryMakeString(string1, string2); - if (!resultImpl) - CRASH(); - return resultImpl.release(); -} - -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3) -{ - RefPtr resultImpl = tryMakeString(string1, string2, string3); - if (!resultImpl) - CRASH(); - return resultImpl.release(); -} - -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4) -{ - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4); - if (!resultImpl) - CRASH(); - return resultImpl.release(); -} + return String(); -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5) -{ - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4, string5); - if (!resultImpl) - CRASH(); - return resultImpl.release(); -} + makeStringAccumulator(buffer, adapter, adapters...); -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6) -{ - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6); - if (!resultImpl) - CRASH(); - return resultImpl.release(); + return WTFMove(resultImpl); } -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7) +template +String tryMakeString(StringTypes ...strings) { - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7); - if (!resultImpl) - CRASH(); - return resultImpl.release(); + return tryMakeStringFromAdapters(StringTypeAdapter(strings)...); } -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8) +// Convenience only. +template +String makeString(StringType string) { - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7, string8); - if (!resultImpl) - CRASH(); - return resultImpl.release(); + return String(string); } -template -String makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8, StringType9 string9) +template +String makeString(StringTypes... strings) { - RefPtr resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7, string8, string9); - if (!resultImpl) + String result = tryMakeString(strings...); + if (!result) CRASH(); - return resultImpl.release(); + return result; } } // namespace WTF using WTF::makeString; +using WTF::tryMakeString; #include #endif -- cgit v1.2.1