| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. |
| 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 #include "wtf/Allocator.h" | 25 #include "wtf/Allocator.h" |
| 26 #include "wtf/text/StringConcatenate.h" | 26 #include "wtf/text/StringConcatenate.h" |
| 27 | 27 |
| 28 namespace WTF { | 28 namespace WTF { |
| 29 | 29 |
| 30 template<typename StringType1, typename StringType2> | 30 template<typename StringType1, typename StringType2> |
| 31 class StringAppend final { | 31 class StringAppend final { |
| 32 STACK_ALLOCATED(); | 32 STACK_ALLOCATED(); |
| 33 public: | 33 public: |
| 34 StringAppend(StringType1 string1, StringType2 string2); | 34 StringAppend(const StringType1& string1, const StringType2& string2) |
| 35 : m_adapter1(string1) |
| 36 , m_adapter2(string2) {} |
| 35 | 37 |
| 36 operator String() const; | 38 operator String() const |
| 39 { |
| 40 return String(makeString(m_adapter1, m_adapter2)); |
| 41 } |
| 42 operator AtomicString() const |
| 43 { |
| 44 return AtomicString(makeString(m_adapter1, m_adapter2)); |
| 45 } |
| 37 | 46 |
| 38 operator AtomicString() const; | 47 unsigned length() const { return m_adapter1.length() + m_adapter2.length();
} |
| 48 bool is8Bit() const { return m_adapter1.is8Bit() && m_adapter2.is8Bit(); } |
| 39 | 49 |
| 40 bool is8Bit(); | 50 void writeTo(LChar* destination) const |
| 41 | 51 { |
| 42 void writeTo(LChar* destination); | 52 DCHECK(is8Bit()); |
| 43 | 53 m_adapter1.writeTo(destination); |
| 44 void writeTo(UChar* destination); | 54 m_adapter2.writeTo(destination + m_adapter1.length()); |
| 45 | 55 } |
| 46 unsigned length(); | 56 void writeTo(UChar* destination) const |
| 57 { |
| 58 m_adapter1.writeTo(destination); |
| 59 m_adapter2.writeTo(destination + m_adapter1.length()); |
| 60 } |
| 47 | 61 |
| 48 private: | 62 private: |
| 49 StringType1 m_string1; | 63 StringTypeAdapter<StringType1> m_adapter1; |
| 50 StringType2 m_string2; | 64 StringTypeAdapter<StringType2> m_adapter2; |
| 51 }; | 65 }; |
| 52 | 66 |
| 53 template<typename StringType1, typename StringType2> | 67 template<typename StringType1, typename StringType2> |
| 54 StringAppend<StringType1, StringType2>::StringAppend(StringType1 string1, String
Type2 string2) | |
| 55 : m_string1(string1) | |
| 56 , m_string2(string2) | |
| 57 { | |
| 58 } | |
| 59 | |
| 60 template<typename StringType1, typename StringType2> | |
| 61 StringAppend<StringType1, StringType2>::operator String() const | |
| 62 { | |
| 63 return String(makeString(m_string1, m_string2)); | |
| 64 } | |
| 65 | |
| 66 template<typename StringType1, typename StringType2> | |
| 67 StringAppend<StringType1, StringType2>::operator AtomicString() const | |
| 68 { | |
| 69 return AtomicString(makeString(m_string1, m_string2)); | |
| 70 } | |
| 71 | |
| 72 template<typename StringType1, typename StringType2> | |
| 73 bool StringAppend<StringType1, StringType2>::is8Bit() | |
| 74 { | |
| 75 StringTypeAdapter<StringType1> adapter1(m_string1); | |
| 76 StringTypeAdapter<StringType2> adapter2(m_string2); | |
| 77 return adapter1.is8Bit() && adapter2.is8Bit(); | |
| 78 } | |
| 79 | |
| 80 template<typename StringType1, typename StringType2> | |
| 81 void StringAppend<StringType1, StringType2>::writeTo(LChar* destination) | |
| 82 { | |
| 83 ASSERT(is8Bit()); | |
| 84 StringTypeAdapter<StringType1> adapter1(m_string1); | |
| 85 StringTypeAdapter<StringType2> adapter2(m_string2); | |
| 86 adapter1.writeTo(destination); | |
| 87 adapter2.writeTo(destination + adapter1.length()); | |
| 88 } | |
| 89 | |
| 90 template<typename StringType1, typename StringType2> | |
| 91 void StringAppend<StringType1, StringType2>::writeTo(UChar* destination) | |
| 92 { | |
| 93 StringTypeAdapter<StringType1> adapter1(m_string1); | |
| 94 StringTypeAdapter<StringType2> adapter2(m_string2); | |
| 95 adapter1.writeTo(destination); | |
| 96 adapter2.writeTo(destination + adapter1.length()); | |
| 97 } | |
| 98 | |
| 99 template<typename StringType1, typename StringType2> | |
| 100 unsigned StringAppend<StringType1, StringType2>::length() | |
| 101 { | |
| 102 StringTypeAdapter<StringType1> adapter1(m_string1); | |
| 103 StringTypeAdapter<StringType2> adapter2(m_string2); | |
| 104 return adapter1.length() + adapter2.length(); | |
| 105 } | |
| 106 | |
| 107 template<typename StringType1, typename StringType2> | |
| 108 class StringTypeAdapter<StringAppend<StringType1, StringType2>> { | 68 class StringTypeAdapter<StringAppend<StringType1, StringType2>> { |
| 109 STACK_ALLOCATED(); | 69 STACK_ALLOCATED(); |
| 110 public: | 70 public: |
| 111 StringTypeAdapter<StringAppend<StringType1, StringType2>>(StringAppend<Strin
gType1, StringType2>& buffer) | 71 StringTypeAdapter<StringAppend<StringType1, StringType2>>(const StringAppend
<StringType1, StringType2>& buffer) |
| 112 : m_buffer(buffer) | 72 : m_buffer(buffer) |
| 113 { | 73 { |
| 114 } | 74 } |
| 115 | 75 |
| 116 unsigned length() { return m_buffer.length(); } | 76 unsigned length() const { return m_buffer.length(); } |
| 77 bool is8Bit() const { return m_buffer.is8Bit(); } |
| 117 | 78 |
| 118 bool is8Bit() { return m_buffer.is8Bit(); } | 79 void writeTo(LChar* destination) const { m_buffer.writeTo(destination); } |
| 119 | 80 void writeTo(UChar* destination) const { m_buffer.writeTo(destination); } |
| 120 void writeTo(LChar* destination) { m_buffer.writeTo(destination); } | |
| 121 void writeTo(UChar* destination) { m_buffer.writeTo(destination); } | |
| 122 | 81 |
| 123 private: | 82 private: |
| 124 StringAppend<StringType1, StringType2>& m_buffer; | 83 const StringAppend<StringType1, StringType2>& m_buffer; |
| 125 }; | 84 }; |
| 126 | 85 |
| 127 inline StringAppend<const char*, String> operator+(const char* string1, const St
ring& string2) | 86 inline StringAppend<const char*, String> operator+(const char* string1, const St
ring& string2) |
| 128 { | 87 { |
| 129 return StringAppend<const char*, String>(string1, string2); | 88 return StringAppend<const char*, String>(string1, string2); |
| 130 } | 89 } |
| 131 | 90 |
| 132 inline StringAppend<const char*, AtomicString> operator+(const char* string1, co
nst AtomicString& string2) | 91 inline StringAppend<const char*, AtomicString> operator+(const char* string1, co
nst AtomicString& string2) |
| 133 { | 92 { |
| 134 return StringAppend<const char*, AtomicString>(string1, string2); | 93 return StringAppend<const char*, AtomicString>(string1, string2); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 164 | 123 |
| 165 template<typename U, typename V, typename W> | 124 template<typename U, typename V, typename W> |
| 166 StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1,
W string2) | 125 StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1,
W string2) |
| 167 { | 126 { |
| 168 return StringAppend<StringAppend<U, V>, W>(string1, string2); | 127 return StringAppend<StringAppend<U, V>, W>(string1, string2); |
| 169 } | 128 } |
| 170 | 129 |
| 171 } // namespace WTF | 130 } // namespace WTF |
| 172 | 131 |
| 173 #endif // StringOperators_h | 132 #endif // StringOperators_h |
| OLD | NEW |