Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringConcatenate.h

Issue 2764243002: Move files in wtf/ to platform/wtf/ (Part 9). (Closed)
Patch Set: Rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 4
26 #ifndef StringConcatenate_h 5 #include "platform/wtf/text/StringConcatenate.h"
27 #define StringConcatenate_h
28 6
29 #include "wtf/Allocator.h" 7 // The contents of this header was moved to platform/wtf as part of
30 #include <string.h> 8 // WTF migration project. See the following post for details:
31 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY CAAJ
32 #ifndef WTFString_h
33 #include "wtf/text/AtomicString.h"
34 #endif
35
36 // This macro is helpful for testing how many intermediate Strings are created
37 // while evaluating an expression containing operator+.
38 #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
39 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0)
40 #endif
41
42 namespace WTF {
43
44 template <typename StringType>
45 class StringTypeAdapter {
46 DISALLOW_NEW();
47 };
48
49 template <>
50 class StringTypeAdapter<char> {
51 DISALLOW_NEW();
52
53 public:
54 explicit StringTypeAdapter<char>(char buffer) : m_buffer(buffer) {}
55
56 unsigned length() const { return 1; }
57 bool is8Bit() const { return true; }
58
59 void writeTo(LChar* destination) const { *destination = m_buffer; }
60 void writeTo(UChar* destination) const { *destination = m_buffer; }
61
62 private:
63 const unsigned char m_buffer;
64 };
65
66 template <>
67 class StringTypeAdapter<LChar> {
68 DISALLOW_NEW();
69
70 public:
71 explicit StringTypeAdapter<LChar>(LChar buffer) : m_buffer(buffer) {}
72
73 unsigned length() const { return 1; }
74 bool is8Bit() const { return true; }
75
76 void writeTo(LChar* destination) const { *destination = m_buffer; }
77 void writeTo(UChar* destination) const { *destination = m_buffer; }
78
79 private:
80 const LChar m_buffer;
81 };
82
83 template <>
84 class StringTypeAdapter<UChar> {
85 DISALLOW_NEW();
86
87 public:
88 explicit StringTypeAdapter<UChar>(UChar buffer) : m_buffer(buffer) {}
89
90 unsigned length() const { return 1; }
91 bool is8Bit() const { return m_buffer <= 0xff; }
92
93 void writeTo(LChar* destination) const {
94 DCHECK(is8Bit());
95 *destination = static_cast<LChar>(m_buffer);
96 }
97
98 void writeTo(UChar* destination) const { *destination = m_buffer; }
99
100 private:
101 const UChar m_buffer;
102 };
103
104 template <>
105 class WTF_EXPORT StringTypeAdapter<char*> {
106 DISALLOW_NEW();
107
108 public:
109 explicit StringTypeAdapter<char*>(char* buffer)
110 : m_buffer(buffer), m_length(strlen(buffer)) {}
111
112 unsigned length() const { return m_length; }
113 bool is8Bit() const { return true; }
114
115 void writeTo(LChar* destination) const;
116 void writeTo(UChar* destination) const;
117
118 private:
119 const char* m_buffer;
120 unsigned m_length;
121 };
122
123 template <>
124 class WTF_EXPORT StringTypeAdapter<LChar*> {
125 DISALLOW_NEW();
126
127 public:
128 explicit StringTypeAdapter<LChar*>(LChar* buffer);
129
130 unsigned length() const { return m_length; }
131 bool is8Bit() const { return true; }
132
133 void writeTo(LChar* destination) const;
134 void writeTo(UChar* destination) const;
135
136 private:
137 const LChar* m_buffer;
138 const unsigned m_length;
139 };
140
141 template <>
142 class WTF_EXPORT StringTypeAdapter<const UChar*> {
143 DISALLOW_NEW();
144
145 public:
146 explicit StringTypeAdapter(const UChar* buffer);
147
148 unsigned length() const { return m_length; }
149 bool is8Bit() const { return false; }
150
151 void writeTo(LChar*) const { RELEASE_ASSERT(false); }
152 void writeTo(UChar* destination) const;
153
154 private:
155 const UChar* m_buffer;
156 const unsigned m_length;
157 };
158
159 template <>
160 class WTF_EXPORT StringTypeAdapter<const char*> {
161 DISALLOW_NEW();
162
163 public:
164 explicit StringTypeAdapter<const char*>(const char* buffer);
165
166 unsigned length() const { return m_length; }
167 bool is8Bit() const { return true; }
168
169 void writeTo(LChar* destination) const;
170 void writeTo(UChar* destination) const;
171
172 private:
173 const char* m_buffer;
174 const unsigned m_length;
175 };
176
177 template <>
178 class WTF_EXPORT StringTypeAdapter<const LChar*> {
179 DISALLOW_NEW();
180
181 public:
182 explicit StringTypeAdapter<const LChar*>(const LChar* buffer);
183
184 unsigned length() const { return m_length; }
185 bool is8Bit() const { return true; }
186
187 void writeTo(LChar* destination) const;
188 void writeTo(UChar* destination) const;
189
190 private:
191 const LChar* m_buffer;
192 const unsigned m_length;
193 };
194
195 template <>
196 class WTF_EXPORT StringTypeAdapter<StringView> {
197 DISALLOW_NEW();
198
199 public:
200 explicit StringTypeAdapter(const StringView& view) : m_view(view) {}
201
202 unsigned length() const { return m_view.length(); }
203 bool is8Bit() const { return m_view.is8Bit(); }
204
205 void writeTo(LChar* destination) const;
206 void writeTo(UChar* destination) const;
207
208 private:
209 const StringView m_view;
210 };
211
212 template <>
213 class StringTypeAdapter<String> : public StringTypeAdapter<StringView> {
214 public:
215 explicit StringTypeAdapter(const String& string)
216 : StringTypeAdapter<StringView>(string) {}
217 };
218
219 template <>
220 class StringTypeAdapter<AtomicString> : public StringTypeAdapter<StringView> {
221 public:
222 explicit StringTypeAdapter(const AtomicString& string)
223 : StringTypeAdapter<StringView>(string) {}
224 };
225
226 } // namespace WTF
227
228 #include "wtf/text/StringOperators.h"
229 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringBuilder.cpp ('k') | third_party/WebKit/Source/wtf/text/StringConcatenate.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698