OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 void writeTo(LChar* destination); | 258 void writeTo(LChar* destination); |
259 | 259 |
260 void writeTo(UChar* destination); | 260 void writeTo(UChar* destination); |
261 | 261 |
262 private: | 262 private: |
263 const Vector<LChar>& m_buffer; | 263 const Vector<LChar>& m_buffer; |
264 }; | 264 }; |
265 | 265 |
266 template<> | 266 template<> |
267 class WTF_EXPORT StringTypeAdapter<String> { | 267 class WTF_EXPORT StringTypeAdapter<StringView> { |
268 DISALLOW_NEW(); | 268 DISALLOW_NEW(); |
269 public: | 269 public: |
270 StringTypeAdapter<String>(const String& string) | 270 StringTypeAdapter(const StringView& view) |
271 : m_buffer(string) | 271 : m_view(view) {} |
272 { | |
273 } | |
274 | 272 |
275 unsigned length() { return m_buffer.length(); } | 273 unsigned length() { return m_view.length(); } |
276 | 274 bool is8Bit() { return m_view.is8Bit(); } |
277 bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); } | |
278 | |
279 void writeTo(LChar* destination); | 275 void writeTo(LChar* destination); |
280 | |
281 void writeTo(UChar* destination); | 276 void writeTo(UChar* destination); |
282 | 277 |
283 private: | 278 private: |
284 const String& m_buffer; | 279 const StringView m_view; |
285 }; | 280 }; |
286 | 281 |
287 template<> | 282 template<> |
288 class StringTypeAdapter<AtomicString> { | 283 class StringTypeAdapter<String> : public StringTypeAdapter<StringView> { |
289 DISALLOW_NEW(); | |
290 public: | 284 public: |
291 StringTypeAdapter<AtomicString>(const AtomicString& string) | 285 StringTypeAdapter(const String& string) |
292 : m_adapter(string.getString()) | 286 : StringTypeAdapter<StringView>(string) {} |
293 { | 287 }; |
294 } | |
295 | 288 |
296 unsigned length() { return m_adapter.length(); } | 289 template<> |
297 | 290 class StringTypeAdapter<AtomicString> : public StringTypeAdapter<StringView> { |
298 bool is8Bit() { return m_adapter.is8Bit(); } | 291 public: |
299 | 292 StringTypeAdapter(const AtomicString& string) |
300 void writeTo(LChar* destination) { m_adapter.writeTo(destination); } | 293 : StringTypeAdapter<StringView>(string) {} |
301 void writeTo(UChar* destination) { m_adapter.writeTo(destination); } | |
302 | |
303 private: | |
304 StringTypeAdapter<String> m_adapter; | |
305 }; | 294 }; |
306 | 295 |
307 inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow) | 296 inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow) |
308 { | 297 { |
309 unsigned oldTotal = total; | 298 unsigned oldTotal = total; |
310 total = oldTotal + addend; | 299 total = oldTotal + addend; |
311 if (total < oldTotal) | 300 if (total < oldTotal) |
312 overflow = true; | 301 overflow = true; |
313 } | 302 } |
314 | 303 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 result += adapter1.length(); | 337 result += adapter1.length(); |
349 adapter2.writeTo(result); | 338 adapter2.writeTo(result); |
350 | 339 |
351 return resultImpl.release(); | 340 return resultImpl.release(); |
352 } | 341 } |
353 | 342 |
354 } // namespace WTF | 343 } // namespace WTF |
355 | 344 |
356 #include "wtf/text/StringOperators.h" | 345 #include "wtf/text/StringOperators.h" |
357 #endif | 346 #endif |
OLD | NEW |