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

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

Issue 2473093003: Fix up naming in CString. (Closed)
Patch Set: Created 4 years, 1 month 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 (C) 2004, 2006, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008, 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 UnencodableHandling) { 156 UnencodableHandling) {
157 // We need to be sure we can double the length without overflowing. 157 // We need to be sure we can double the length without overflowing.
158 // Since the passed-in length is the length of an actual existing 158 // Since the passed-in length is the length of an actual existing
159 // character buffer, each character is two bytes, and we know 159 // character buffer, each character is two bytes, and we know
160 // the buffer doesn't occupy the entire address space, we can 160 // the buffer doesn't occupy the entire address space, we can
161 // assert here that doubling the length does not overflow size_t 161 // assert here that doubling the length does not overflow size_t
162 // and there's no need for a runtime check. 162 // and there's no need for a runtime check.
163 ASSERT(length <= numeric_limits<size_t>::max() / 2); 163 ASSERT(length <= numeric_limits<size_t>::max() / 2);
164 164
165 char* bytes; 165 char* bytes;
166 CString result = CString::newUninitialized(length * 2, bytes); 166 CString result = CString::createUninitialized(length * 2, bytes);
167 167
168 // FIXME: CString is not a reasonable data structure for encoded UTF-16, which 168 // FIXME: CString is not a reasonable data structure for encoded UTF-16, which
169 // will have null characters inside it. Perhaps the result of encode should 169 // will have null characters inside it. Perhaps the result of encode should
170 // not be a CString. 170 // not be a CString.
171 if (m_littleEndian) { 171 if (m_littleEndian) {
172 for (size_t i = 0; i < length; ++i) { 172 for (size_t i = 0; i < length; ++i) {
173 UChar c = characters[i]; 173 UChar c = characters[i];
174 bytes[i * 2] = static_cast<char>(c); 174 bytes[i * 2] = static_cast<char>(c);
175 bytes[i * 2 + 1] = c >> 8; 175 bytes[i * 2 + 1] = c >> 8;
176 } 176 }
177 } else { 177 } else {
178 for (size_t i = 0; i < length; ++i) { 178 for (size_t i = 0; i < length; ++i) {
179 UChar c = characters[i]; 179 UChar c = characters[i];
180 bytes[i * 2] = c >> 8; 180 bytes[i * 2] = c >> 8;
181 bytes[i * 2 + 1] = static_cast<char>(c); 181 bytes[i * 2 + 1] = static_cast<char>(c);
182 } 182 }
183 } 183 }
184 184
185 return result; 185 return result;
186 } 186 }
187 187
188 CString TextCodecUTF16::encode(const LChar* characters, 188 CString TextCodecUTF16::encode(const LChar* characters,
189 size_t length, 189 size_t length,
190 UnencodableHandling) { 190 UnencodableHandling) {
191 // In the LChar case, we do actually need to perform this check in release. :) 191 // In the LChar case, we do actually need to perform this check in release. :)
192 RELEASE_ASSERT(length <= numeric_limits<size_t>::max() / 2); 192 RELEASE_ASSERT(length <= numeric_limits<size_t>::max() / 2);
193 193
194 char* bytes; 194 char* bytes;
195 CString result = CString::newUninitialized(length * 2, bytes); 195 CString result = CString::createUninitialized(length * 2, bytes);
196 196
197 if (m_littleEndian) { 197 if (m_littleEndian) {
198 for (size_t i = 0; i < length; ++i) { 198 for (size_t i = 0; i < length; ++i) {
199 bytes[i * 2] = characters[i]; 199 bytes[i * 2] = characters[i];
200 bytes[i * 2 + 1] = 0; 200 bytes[i * 2 + 1] = 0;
201 } 201 }
202 } else { 202 } else {
203 for (size_t i = 0; i < length; ++i) { 203 for (size_t i = 0; i < length; ++i) {
204 bytes[i * 2] = 0; 204 bytes[i * 2] = 0;
205 bytes[i * 2 + 1] = characters[i]; 205 bytes[i * 2 + 1] = characters[i];
206 } 206 }
207 } 207 }
208 208
209 return result; 209 return result;
210 } 210 }
211 211
212 } // namespace WTF 212 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodecLatin1.cpp ('k') | third_party/WebKit/Source/wtf/text/TextCodecUserDefined.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698