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.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
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
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef StringOperators_h
23 #define StringOperators_h
27 template<typename StringType1, typename StringType2>
30 StringAppend(StringType1 string1, StringType2 string2)
36 operator String() const
38 RefPtr<StringImpl> resultImpl = tryMakeString(m_string1, m_string2);
41 return resultImpl.release();
44 operator AtomicString() const
46 return operator String();
49 void writeTo(UChar* destination)
51 StringTypeAdapter<StringType1> adapter1(m_string1);
52 StringTypeAdapter<StringType2> adapter2(m_string2);
53 adapter1.writeTo(destination);
54 adapter2.writeTo(destination + adapter1.length());
59 StringTypeAdapter<StringType1> adapter1(m_string1);
60 StringTypeAdapter<StringType2> adapter2(m_string2);
61 return adapter1.length() + adapter2.length();
65 StringType1 m_string1;
66 StringType2 m_string2;
69 template<typename StringType1, typename StringType2>
70 class StringTypeAdapter<StringAppend<StringType1, StringType2> > {
72 StringTypeAdapter<StringAppend<StringType1, StringType2> >(StringAppend<StringType1, StringType2>& buffer)
77 unsigned length() { return m_buffer.length(); }
78 void writeTo(UChar* destination) { m_buffer.writeTo(destination); }
81 StringAppend<StringType1, StringType2>& m_buffer;
84 inline StringAppend<const char*, String> operator+(const char* string1, const String& string2)
86 return StringAppend<const char*, String>(string1, string2);
89 inline StringAppend<const char*, AtomicString> operator+(const char* string1, const AtomicString& string2)
91 return StringAppend<const char*, AtomicString>(string1, string2);
94 template<typename U, typename V>
95 StringAppend<const char*, StringAppend<U, V> > operator+(const char* string1, const StringAppend<U, V>& string2)
97 return StringAppend<const char*, StringAppend<U, V> >(string1, string2);
100 inline StringAppend<const UChar*, String> operator+(const UChar* string1, const String& string2)
102 return StringAppend<const UChar*, String>(string1, string2);
105 inline StringAppend<const UChar*, AtomicString> operator+(const UChar* string1, const AtomicString& string2)
107 return StringAppend<const UChar*, AtomicString>(string1, string2);
110 template<typename U, typename V>
111 StringAppend<const UChar*, StringAppend<U, V> > operator+(const UChar* string1, const StringAppend<U, V>& string2)
113 return StringAppend<const UChar*, StringAppend<U, V> >(string1, string2);
117 StringAppend<String, T> operator+(const String& string1, T string2)
119 return StringAppend<String, T>(string1, string2);
122 template<typename U, typename V, typename W>
123 StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1, W string2)
125 return StringAppend<StringAppend<U, V>, W>(string1, string2);
130 #endif // StringOperators_h