OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 #include "wtf/text/StringConcatenate.h" | |
8 | |
9 #include "wtf/text/StringImpl.h" | |
10 | |
11 // This macro is helpful for testing how many intermediate Strings are created | |
12 // while evaluating an expression containing operator+. | |
13 #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING | |
14 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0) | |
15 #endif | |
16 | |
17 void WTF::StringTypeAdapter<char*>::writeTo(LChar* destination) const { | |
18 for (unsigned i = 0; i < m_length; ++i) | |
19 destination[i] = static_cast<LChar>(m_buffer[i]); | |
20 } | |
21 | |
22 void WTF::StringTypeAdapter<char*>::writeTo(UChar* destination) const { | |
23 for (unsigned i = 0; i < m_length; ++i) { | |
24 unsigned char c = m_buffer[i]; | |
25 destination[i] = c; | |
26 } | |
27 } | |
28 | |
29 WTF::StringTypeAdapter<LChar*>::StringTypeAdapter(LChar* buffer) | |
30 : m_buffer(buffer), m_length(strlen(reinterpret_cast<char*>(buffer))) {} | |
31 | |
32 void WTF::StringTypeAdapter<LChar*>::writeTo(LChar* destination) const { | |
33 memcpy(destination, m_buffer, m_length * sizeof(LChar)); | |
34 } | |
35 | |
36 void WTF::StringTypeAdapter<LChar*>::writeTo(UChar* destination) const { | |
37 StringImpl::copyChars(destination, m_buffer, m_length); | |
38 } | |
39 | |
40 WTF::StringTypeAdapter<const UChar*>::StringTypeAdapter(const UChar* buffer) | |
41 : m_buffer(buffer), m_length(lengthOfNullTerminatedString(buffer)) {} | |
42 | |
43 void WTF::StringTypeAdapter<const UChar*>::writeTo(UChar* destination) const { | |
44 memcpy(destination, m_buffer, m_length * sizeof(UChar)); | |
45 } | |
46 | |
47 WTF::StringTypeAdapter<const char*>::StringTypeAdapter(const char* buffer) | |
48 : m_buffer(buffer), m_length(strlen(buffer)) {} | |
49 | |
50 void WTF::StringTypeAdapter<const char*>::writeTo(LChar* destination) const { | |
51 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar)); | |
52 } | |
53 | |
54 void WTF::StringTypeAdapter<const char*>::writeTo(UChar* destination) const { | |
55 for (unsigned i = 0; i < m_length; ++i) { | |
56 unsigned char c = m_buffer[i]; | |
57 destination[i] = c; | |
58 } | |
59 } | |
60 | |
61 WTF::StringTypeAdapter<const LChar*>::StringTypeAdapter(const LChar* buffer) | |
62 : m_buffer(buffer), | |
63 m_length(strlen(reinterpret_cast<const char*>(buffer))) {} | |
64 | |
65 void WTF::StringTypeAdapter<const LChar*>::writeTo(LChar* destination) const { | |
66 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar)); | |
67 } | |
68 | |
69 void WTF::StringTypeAdapter<const LChar*>::writeTo(UChar* destination) const { | |
70 StringImpl::copyChars(destination, m_buffer, m_length); | |
71 } | |
72 | |
73 void WTF::StringTypeAdapter<StringView>::writeTo(LChar* destination) const { | |
74 DCHECK(is8Bit()); | |
75 StringImpl::copyChars(destination, m_view.characters8(), m_view.length()); | |
76 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); | |
77 } | |
78 | |
79 void WTF::StringTypeAdapter<StringView>::writeTo(UChar* destination) const { | |
80 if (is8Bit()) | |
81 StringImpl::copyChars(destination, m_view.characters8(), m_view.length()); | |
82 else | |
83 StringImpl::copyChars(destination, m_view.characters16(), m_view.length()); | |
84 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); | |
85 } | |
OLD | NEW |