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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 #ifndef StringOperators_h | 22 #ifndef StringOperators_h |
23 #define StringOperators_h | 23 #define StringOperators_h |
24 | 24 |
| 25 #include "StringConcatenate.h" |
| 26 |
25 namespace WTF { | 27 namespace WTF { |
26 | 28 |
27 template<typename StringType1, typename StringType2> | 29 template<typename StringType1, typename StringType2> |
28 class StringAppend { | 30 class StringAppend { |
29 public: | 31 public: |
30 StringAppend(StringType1 string1, StringType2 string2) | 32 StringAppend(StringType1 string1, StringType2 string2); |
31 : m_string1(string1) | |
32 , m_string2(string2) | |
33 { | |
34 } | |
35 | 33 |
36 operator String() const | 34 operator String() const; |
37 { | |
38 return String(makeString(m_string1, m_string2)); | |
39 } | |
40 | 35 |
41 operator AtomicString() const | 36 operator AtomicString() const; |
42 { | |
43 return AtomicString(makeString(m_string1, m_string2)); | |
44 } | |
45 | 37 |
46 bool is8Bit() | 38 bool is8Bit(); |
47 { | |
48 StringTypeAdapter<StringType1> adapter1(m_string1); | |
49 StringTypeAdapter<StringType2> adapter2(m_string2); | |
50 return adapter1.is8Bit() && adapter2.is8Bit(); | |
51 } | |
52 | 39 |
53 void writeTo(LChar* destination) | 40 void writeTo(LChar* destination); |
54 { | |
55 ASSERT(is8Bit()); | |
56 StringTypeAdapter<StringType1> adapter1(m_string1); | |
57 StringTypeAdapter<StringType2> adapter2(m_string2); | |
58 adapter1.writeTo(destination); | |
59 adapter2.writeTo(destination + adapter1.length()); | |
60 } | |
61 | 41 |
62 void writeTo(UChar* destination) | 42 void writeTo(UChar* destination); |
63 { | |
64 StringTypeAdapter<StringType1> adapter1(m_string1); | |
65 StringTypeAdapter<StringType2> adapter2(m_string2); | |
66 adapter1.writeTo(destination); | |
67 adapter2.writeTo(destination + adapter1.length()); | |
68 } | |
69 | 43 |
70 unsigned length() | 44 unsigned length(); |
71 { | |
72 StringTypeAdapter<StringType1> adapter1(m_string1); | |
73 StringTypeAdapter<StringType2> adapter2(m_string2); | |
74 return adapter1.length() + adapter2.length(); | |
75 } | |
76 | 45 |
77 private: | 46 private: |
78 StringType1 m_string1; | 47 StringType1 m_string1; |
79 StringType2 m_string2; | 48 StringType2 m_string2; |
80 }; | 49 }; |
81 | 50 |
82 template<typename StringType1, typename StringType2> | 51 template<typename StringType1, typename StringType2> |
| 52 StringAppend<StringType1, StringType2>::StringAppend(StringType1 string1, String
Type2 string2) |
| 53 : m_string1(string1) |
| 54 , m_string2(string2) |
| 55 { |
| 56 } |
| 57 |
| 58 template<typename StringType1, typename StringType2> |
| 59 StringAppend<StringType1, StringType2>::operator String() const |
| 60 { |
| 61 return String(makeString(m_string1, m_string2)); |
| 62 } |
| 63 |
| 64 template<typename StringType1, typename StringType2> |
| 65 StringAppend<StringType1, StringType2>::operator AtomicString() const |
| 66 { |
| 67 return AtomicString(makeString(m_string1, m_string2)); |
| 68 } |
| 69 |
| 70 template<typename StringType1, typename StringType2> |
| 71 bool StringAppend<StringType1, StringType2>::is8Bit() |
| 72 { |
| 73 StringTypeAdapter<StringType1> adapter1(m_string1); |
| 74 StringTypeAdapter<StringType2> adapter2(m_string2); |
| 75 return adapter1.is8Bit() && adapter2.is8Bit(); |
| 76 } |
| 77 |
| 78 template<typename StringType1, typename StringType2> |
| 79 void StringAppend<StringType1, StringType2>::writeTo(LChar* destination) |
| 80 { |
| 81 ASSERT(is8Bit()); |
| 82 StringTypeAdapter<StringType1> adapter1(m_string1); |
| 83 StringTypeAdapter<StringType2> adapter2(m_string2); |
| 84 adapter1.writeTo(destination); |
| 85 adapter2.writeTo(destination + adapter1.length()); |
| 86 } |
| 87 |
| 88 template<typename StringType1, typename StringType2> |
| 89 void StringAppend<StringType1, StringType2>::writeTo(UChar* destination) |
| 90 { |
| 91 StringTypeAdapter<StringType1> adapter1(m_string1); |
| 92 StringTypeAdapter<StringType2> adapter2(m_string2); |
| 93 adapter1.writeTo(destination); |
| 94 adapter2.writeTo(destination + adapter1.length()); |
| 95 } |
| 96 |
| 97 template<typename StringType1, typename StringType2> |
| 98 unsigned StringAppend<StringType1, StringType2>::length() |
| 99 { |
| 100 StringTypeAdapter<StringType1> adapter1(m_string1); |
| 101 StringTypeAdapter<StringType2> adapter2(m_string2); |
| 102 return adapter1.length() + adapter2.length(); |
| 103 } |
| 104 |
| 105 template<typename StringType1, typename StringType2> |
83 class StringTypeAdapter<StringAppend<StringType1, StringType2> > { | 106 class StringTypeAdapter<StringAppend<StringType1, StringType2> > { |
84 public: | 107 public: |
85 StringTypeAdapter<StringAppend<StringType1, StringType2> >(StringAppend<Stri
ngType1, StringType2>& buffer) | 108 StringTypeAdapter<StringAppend<StringType1, StringType2> >(StringAppend<Stri
ngType1, StringType2>& buffer) |
86 : m_buffer(buffer) | 109 : m_buffer(buffer) |
87 { | 110 { |
88 } | 111 } |
89 | 112 |
90 unsigned length() { return m_buffer.length(); } | 113 unsigned length() { return m_buffer.length(); } |
91 | 114 |
92 bool is8Bit() { return m_buffer.is8Bit(); } | 115 bool is8Bit() { return m_buffer.is8Bit(); } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 161 |
139 template<typename U, typename V, typename W> | 162 template<typename U, typename V, typename W> |
140 StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1,
W string2) | 163 StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1,
W string2) |
141 { | 164 { |
142 return StringAppend<StringAppend<U, V>, W>(string1, string2); | 165 return StringAppend<StringAppend<U, V>, W>(string1, string2); |
143 } | 166 } |
144 | 167 |
145 } // namespace WTF | 168 } // namespace WTF |
146 | 169 |
147 #endif // StringOperators_h | 170 #endif // StringOperators_h |
OLD | NEW |