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.
8 #include "StringConcatenate.h"
10 // This macro is helpful for testing how many intermediate Strings are created while evaluating an
11 // expression containing operator+.
12 #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
13 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0)
16 void WTF::StringTypeAdapter
<char*>::writeTo(LChar
* destination
)
18 for (unsigned i
= 0; i
< m_length
; ++i
)
19 destination
[i
] = static_cast<LChar
>(m_buffer
[i
]);
22 void WTF::StringTypeAdapter
<char*>::writeTo(UChar
* destination
)
24 for (unsigned i
= 0; i
< m_length
; ++i
) {
25 unsigned char c
= m_buffer
[i
];
30 WTF::StringTypeAdapter
<LChar
*>::StringTypeAdapter(LChar
* buffer
)
32 , m_length(strlen(reinterpret_cast<char*>(buffer
)))
36 void WTF::StringTypeAdapter
<LChar
*>::writeTo(LChar
* destination
)
38 memcpy(destination
, m_buffer
, m_length
* sizeof(LChar
));
41 void WTF::StringTypeAdapter
<LChar
*>::writeTo(UChar
* destination
)
43 StringImpl::copyChars(destination
, m_buffer
, m_length
);
46 WTF::StringTypeAdapter
<const UChar
*>::StringTypeAdapter(const UChar
* buffer
)
50 while (m_buffer
[len
] != UChar(0))
53 RELEASE_ASSERT(len
<= std::numeric_limits
<unsigned>::max());
58 void WTF::StringTypeAdapter
<const UChar
*>::writeTo(UChar
* destination
)
60 memcpy(destination
, m_buffer
, m_length
* sizeof(UChar
));
63 WTF::StringTypeAdapter
<const char*>::StringTypeAdapter(const char* buffer
)
65 , m_length(strlen(buffer
))
69 void WTF::StringTypeAdapter
<const char*>::writeTo(LChar
* destination
)
71 memcpy(destination
, m_buffer
, static_cast<size_t>(m_length
) * sizeof(LChar
));
74 void WTF::StringTypeAdapter
<const char*>::writeTo(UChar
* destination
)
76 for (unsigned i
= 0; i
< m_length
; ++i
) {
77 unsigned char c
= m_buffer
[i
];
82 WTF::StringTypeAdapter
<const LChar
*>::StringTypeAdapter(const LChar
* buffer
)
84 , m_length(strlen(reinterpret_cast<const char*>(buffer
)))
88 void WTF::StringTypeAdapter
<const LChar
*>::writeTo(LChar
* destination
)
90 memcpy(destination
, m_buffer
, static_cast<size_t>(m_length
) * sizeof(LChar
));
93 void WTF::StringTypeAdapter
<const LChar
*>::writeTo(UChar
* destination
)
95 StringImpl::copyChars(destination
, m_buffer
, m_length
);
98 void WTF::StringTypeAdapter
<Vector
<char>>::writeTo(LChar
* destination
)
100 for (size_t i
= 0; i
< m_buffer
.size(); ++i
)
101 destination
[i
] = static_cast<unsigned char>(m_buffer
[i
]);
104 void WTF::StringTypeAdapter
<Vector
<char>>::writeTo(UChar
* destination
)
106 for (size_t i
= 0; i
< m_buffer
.size(); ++i
)
107 destination
[i
] = static_cast<unsigned char>(m_buffer
[i
]);
110 void WTF::StringTypeAdapter
<Vector
<LChar
>>::writeTo(LChar
* destination
)
112 for (size_t i
= 0; i
< m_buffer
.size(); ++i
)
113 destination
[i
] = m_buffer
[i
];
116 void WTF::StringTypeAdapter
<Vector
<LChar
>>::writeTo(UChar
* destination
)
118 for (size_t i
= 0; i
< m_buffer
.size(); ++i
)
119 destination
[i
] = m_buffer
[i
];
122 void WTF::StringTypeAdapter
<String
>::writeTo(LChar
* destination
)
124 unsigned length
= m_buffer
.length();
127 const LChar
* data
= m_buffer
.characters8();
128 for (unsigned i
= 0; i
< length
; ++i
)
129 destination
[i
] = data
[i
];
131 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
134 void WTF::StringTypeAdapter
<String
>::writeTo(UChar
* destination
)
136 unsigned length
= m_buffer
.length();
139 const LChar
* data
= m_buffer
.characters8();
140 for (unsigned i
= 0; i
< length
; ++i
)
141 destination
[i
] = data
[i
];
143 const UChar
* data
= m_buffer
.characters16();
144 for (unsigned i
= 0; i
< length
; ++i
)
145 destination
[i
] = data
[i
];
148 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();