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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved. 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 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "wtf/text/StringConcatenate.h" 7 #include "wtf/text/StringConcatenate.h"
8 8
9 // This macro is helpful for testing how many intermediate Strings are created w hile evaluating an 9 // This macro is helpful for testing how many intermediate Strings are created w hile evaluating an
10 // expression containing operator+. 10 // expression containing operator+.
11 #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING 11 #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
12 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0) 12 #define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0)
13 #endif 13 #endif
14 14
15 void WTF::StringTypeAdapter<char*>::writeTo(LChar* destination) 15 void WTF::StringTypeAdapter<char*>::writeTo(LChar* destination) {
16 { 16 for (unsigned i = 0; i < m_length; ++i)
17 for (unsigned i = 0; i < m_length; ++i) 17 destination[i] = static_cast<LChar>(m_buffer[i]);
18 destination[i] = static_cast<LChar>(m_buffer[i]);
19 } 18 }
20 19
21 void WTF::StringTypeAdapter<char*>::writeTo(UChar* destination) 20 void WTF::StringTypeAdapter<char*>::writeTo(UChar* destination) {
22 { 21 for (unsigned i = 0; i < m_length; ++i) {
23 for (unsigned i = 0; i < m_length; ++i) { 22 unsigned char c = m_buffer[i];
24 unsigned char c = m_buffer[i]; 23 destination[i] = c;
25 destination[i] = c; 24 }
26 }
27 } 25 }
28 26
29 WTF::StringTypeAdapter<LChar*>::StringTypeAdapter(LChar* buffer) 27 WTF::StringTypeAdapter<LChar*>::StringTypeAdapter(LChar* buffer)
30 : m_buffer(buffer) 28 : m_buffer(buffer), m_length(strlen(reinterpret_cast<char*>(buffer))) {}
31 , m_length(strlen(reinterpret_cast<char*>(buffer))) 29
32 { 30 void WTF::StringTypeAdapter<LChar*>::writeTo(LChar* destination) {
31 memcpy(destination, m_buffer, m_length * sizeof(LChar));
33 } 32 }
34 33
35 void WTF::StringTypeAdapter<LChar*>::writeTo(LChar* destination) 34 void WTF::StringTypeAdapter<LChar*>::writeTo(UChar* destination) {
36 { 35 StringImpl::copyChars(destination, m_buffer, m_length);
37 memcpy(destination, m_buffer, m_length * sizeof(LChar));
38 }
39
40 void WTF::StringTypeAdapter<LChar*>::writeTo(UChar* destination)
41 {
42 StringImpl::copyChars(destination, m_buffer, m_length);
43 } 36 }
44 37
45 WTF::StringTypeAdapter<const UChar*>::StringTypeAdapter(const UChar* buffer) 38 WTF::StringTypeAdapter<const UChar*>::StringTypeAdapter(const UChar* buffer)
46 : m_buffer(buffer) 39 : m_buffer(buffer) {
47 { 40 size_t len = 0;
48 size_t len = 0; 41 while (m_buffer[len] != UChar(0))
49 while (m_buffer[len] != UChar(0)) 42 ++len;
50 ++len;
51 43
52 RELEASE_ASSERT(len <= std::numeric_limits<unsigned>::max()); 44 RELEASE_ASSERT(len <= std::numeric_limits<unsigned>::max());
53 45
54 m_length = len; 46 m_length = len;
55 } 47 }
56 48
57 void WTF::StringTypeAdapter<const UChar*>::writeTo(UChar* destination) 49 void WTF::StringTypeAdapter<const UChar*>::writeTo(UChar* destination) {
58 { 50 memcpy(destination, m_buffer, m_length * sizeof(UChar));
59 memcpy(destination, m_buffer, m_length * sizeof(UChar));
60 } 51 }
61 52
62 WTF::StringTypeAdapter<const char*>::StringTypeAdapter(const char* buffer) 53 WTF::StringTypeAdapter<const char*>::StringTypeAdapter(const char* buffer)
63 : m_buffer(buffer) 54 : m_buffer(buffer), m_length(strlen(buffer)) {}
64 , m_length(strlen(buffer)) 55
65 { 56 void WTF::StringTypeAdapter<const char*>::writeTo(LChar* destination) {
57 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
66 } 58 }
67 59
68 void WTF::StringTypeAdapter<const char*>::writeTo(LChar* destination) 60 void WTF::StringTypeAdapter<const char*>::writeTo(UChar* destination) {
69 { 61 for (unsigned i = 0; i < m_length; ++i) {
70 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar)) ; 62 unsigned char c = m_buffer[i];
71 } 63 destination[i] = c;
72 64 }
73 void WTF::StringTypeAdapter<const char*>::writeTo(UChar* destination)
74 {
75 for (unsigned i = 0; i < m_length; ++i) {
76 unsigned char c = m_buffer[i];
77 destination[i] = c;
78 }
79 } 65 }
80 66
81 WTF::StringTypeAdapter<const LChar*>::StringTypeAdapter(const LChar* buffer) 67 WTF::StringTypeAdapter<const LChar*>::StringTypeAdapter(const LChar* buffer)
82 : m_buffer(buffer) 68 : m_buffer(buffer),
83 , m_length(strlen(reinterpret_cast<const char*>(buffer))) 69 m_length(strlen(reinterpret_cast<const char*>(buffer))) {}
84 { 70
71 void WTF::StringTypeAdapter<const LChar*>::writeTo(LChar* destination) {
72 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
85 } 73 }
86 74
87 void WTF::StringTypeAdapter<const LChar*>::writeTo(LChar* destination) 75 void WTF::StringTypeAdapter<const LChar*>::writeTo(UChar* destination) {
88 { 76 StringImpl::copyChars(destination, m_buffer, m_length);
89 memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar)) ;
90 } 77 }
91 78
92 void WTF::StringTypeAdapter<const LChar*>::writeTo(UChar* destination) 79 void WTF::StringTypeAdapter<Vector<char>>::writeTo(LChar* destination) {
93 { 80 for (size_t i = 0; i < m_buffer.size(); ++i)
94 StringImpl::copyChars(destination, m_buffer, m_length); 81 destination[i] = static_cast<unsigned char>(m_buffer[i]);
95 } 82 }
96 83
97 void WTF::StringTypeAdapter<Vector<char>>::writeTo(LChar* destination) 84 void WTF::StringTypeAdapter<Vector<char>>::writeTo(UChar* destination) {
98 { 85 for (size_t i = 0; i < m_buffer.size(); ++i)
99 for (size_t i = 0; i < m_buffer.size(); ++i) 86 destination[i] = static_cast<unsigned char>(m_buffer[i]);
100 destination[i] = static_cast<unsigned char>(m_buffer[i]);
101 } 87 }
102 88
103 void WTF::StringTypeAdapter<Vector<char>>::writeTo(UChar* destination) 89 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(LChar* destination) {
104 { 90 for (size_t i = 0; i < m_buffer.size(); ++i)
105 for (size_t i = 0; i < m_buffer.size(); ++i) 91 destination[i] = m_buffer[i];
106 destination[i] = static_cast<unsigned char>(m_buffer[i]);
107 } 92 }
108 93
109 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(LChar* destination) 94 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(UChar* destination) {
110 { 95 for (size_t i = 0; i < m_buffer.size(); ++i)
111 for (size_t i = 0; i < m_buffer.size(); ++i) 96 destination[i] = m_buffer[i];
112 destination[i] = m_buffer[i];
113 } 97 }
114 98
115 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(UChar* destination) 99 void WTF::StringTypeAdapter<String>::writeTo(LChar* destination) {
116 { 100 unsigned length = m_buffer.length();
117 for (size_t i = 0; i < m_buffer.size(); ++i) 101
118 destination[i] = m_buffer[i]; 102 ASSERT(is8Bit());
103 const LChar* data = m_buffer.characters8();
104 for (unsigned i = 0; i < length; ++i)
105 destination[i] = data[i];
106
107 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
119 } 108 }
120 109
121 void WTF::StringTypeAdapter<String>::writeTo(LChar* destination) 110 void WTF::StringTypeAdapter<String>::writeTo(UChar* destination) {
122 { 111 unsigned length = m_buffer.length();
123 unsigned length = m_buffer.length();
124 112
125 ASSERT(is8Bit()); 113 if (is8Bit()) {
126 const LChar* data = m_buffer.characters8(); 114 const LChar* data = m_buffer.characters8();
127 for (unsigned i = 0; i < length; ++i) 115 for (unsigned i = 0; i < length; ++i)
128 destination[i] = data[i]; 116 destination[i] = data[i];
117 } else {
118 const UChar* data = m_buffer.characters16();
119 for (unsigned i = 0; i < length; ++i)
120 destination[i] = data[i];
121 }
129 122
130 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); 123 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
131 } 124 }
132
133 void WTF::StringTypeAdapter<String>::writeTo(UChar* destination)
134 {
135 unsigned length = m_buffer.length();
136
137 if (is8Bit()) {
138 const LChar* data = m_buffer.characters8();
139 for (unsigned i = 0; i < length; ++i)
140 destination[i] = data[i];
141 } else {
142 const UChar* data = m_buffer.characters16();
143 for (unsigned i = 0; i < length; ++i)
144 destination[i] = data[i];
145 }
146
147 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
148 }
149
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringConcatenate.h ('k') | third_party/WebKit/Source/wtf/text/StringHash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698