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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/String16STL.cpp

Issue 2001893002: DevTools: expose raw pointers in protocol collections, s/ASSERT/DCHECK/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/inspector_protocol/String16STL.h" 5 #include "platform/inspector_protocol/String16STL.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <functional> 9 #include <functional>
10 #include <locale> 10 #include <locale>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac , 0xad, 0xae, 0xaf, 81 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac , 0xad, 0xae, 0xaf,
82 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc , 0xbd, 0xbe, 0xbf, 82 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc , 0xbd, 0xbe, 0xbf,
83 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc , 0xcd, 0xce, 0xcf, 83 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc , 0xcd, 0xce, 0xcf,
84 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc , 0xdd, 0xde, 0xdf, 84 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc , 0xdd, 0xde, 0xdf,
85 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec , 0xed, 0xee, 0xef, 85 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec , 0xed, 0xee, 0xef,
86 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc , 0xfd, 0xfe, 0xff 86 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc , 0xfd, 0xfe, 0xff
87 }; 87 };
88 88
89 template<typename CharType> inline int toASCIIHexValue(CharType c) 89 template<typename CharType> inline int toASCIIHexValue(CharType c)
90 { 90 {
91 ASSERT(isASCIIHexDigit(c)); 91 DCHECK(isASCIIHexDigit(c));
92 return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; 92 return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
93 } 93 }
94 94
95 template<typename CharType> inline int toASCIIHexValue(CharType upperValue, Char Type lowerValue) 95 template<typename CharType> inline int toASCIIHexValue(CharType upperValue, Char Type lowerValue)
96 { 96 {
97 ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue)); 97 DCHECK(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue));
98 return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerVa lue); 98 return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerVa lue);
99 } 99 }
100 100
101 inline char lowerNibbleToASCIIHexDigit(char c) 101 inline char lowerNibbleToASCIIHexDigit(char c)
102 { 102 {
103 char nibble = c & 0xF; 103 char nibble = c & 0xF;
104 return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; 104 return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
105 } 105 }
106 106
107 inline char upperNibbleToASCIIHexDigit(char c) 107 inline char upperNibbleToASCIIHexDigit(char c)
108 { 108 {
109 char nibble = (c >> 4) & 0xF; 109 char nibble = (c >> 4) & 0xF;
110 return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; 110 return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
111 } 111 }
112 112
113 template<typename CharType> inline bool isASCIIAlphaCaselessEqual(CharType cssCh aracter, char character) 113 template<typename CharType> inline bool isASCIIAlphaCaselessEqual(CharType cssCh aracter, char character)
114 { 114 {
115 // This function compares a (preferrably) constant ASCII 115 // This function compares a (preferrably) constant ASCII
116 // lowercase letter to any input character. 116 // lowercase letter to any input character.
117 ASSERT(character >= 'a' && character <= 'z'); 117 DCHECK(character >= 'a' && character <= 'z');
118 return LIKELY(toASCIILowerUnchecked(cssCharacter) == character); 118 return LIKELY(toASCIILowerUnchecked(cssCharacter) == character);
119 } 119 }
120 120
121 inline int inlineUTF8SequenceLengthNonASCII(char b0) 121 inline int inlineUTF8SequenceLengthNonASCII(char b0)
122 { 122 {
123 if ((b0 & 0xC0) != 0xC0) 123 if ((b0 & 0xC0) != 0xC0)
124 return 0; 124 return 0;
125 if ((b0 & 0xE0) == 0xC0) 125 if ((b0 & 0xE0) == 0xC0)
126 return 2; 126 return 2;
127 if ((b0 & 0xF0) == 0xE0) 127 if ((b0 & 0xF0) == 0xE0)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 target += bytesToWrite; 270 target += bytesToWrite;
271 } 271 }
272 *sourceStart = source; 272 *sourceStart = source;
273 *targetStart = target; 273 *targetStart = target;
274 return result; 274 return result;
275 } 275 }
276 276
277 // Helper to write a three-byte UTF-8 code point to the buffer, caller must chec k room is available. 277 // Helper to write a three-byte UTF-8 code point to the buffer, caller must chec k room is available.
278 static inline void putUTF8Triple(char*& buffer, UChar ch) 278 static inline void putUTF8Triple(char*& buffer, UChar ch)
279 { 279 {
280 ASSERT(ch >= 0x0800); 280 DCHECK_GE(ch, 0x0800);
281 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); 281 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0);
282 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); 282 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80);
283 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); 283 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80);
284 } 284 }
285 285
286 // trim from start 286 // trim from start
287 static inline wstring &ltrim(wstring &s) 287 static inline wstring &ltrim(wstring &s)
288 { 288 {
289 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<i nt, int>(std::isspace)))); 289 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<i nt, int>(std::isspace))));
290 return s; 290 return s;
(...skipping 30 matching lines...) Expand all
321 // have a good chance of being able to write the string into the 321 // have a good chance of being able to write the string into the
322 // buffer without reallocing (say, 1.5 x length). 322 // buffer without reallocing (say, 1.5 x length).
323 if (length > std::numeric_limits<unsigned>::max() / 3) 323 if (length > std::numeric_limits<unsigned>::max() / 3)
324 return std::string(); 324 return std::string();
325 std::vector<char> bufferVector(length * 3); 325 std::vector<char> bufferVector(length * 3);
326 char* buffer = bufferVector.data(); 326 char* buffer = bufferVector.data();
327 const UChar* characters = m_impl.data(); 327 const UChar* characters = m_impl.data();
328 328
329 bool strict = false; 329 bool strict = false;
330 ConversionResult result = convertUTF16ToUTF8(&characters, characters + lengt h, &buffer, buffer + bufferVector.size(), strict); 330 ConversionResult result = convertUTF16ToUTF8(&characters, characters + lengt h, &buffer, buffer + bufferVector.size(), strict);
331 ASSERT(result != targetExhausted); // (length * 3) should be sufficient for any conversion 331 DCHECK(result != targetExhausted); // (length * 3) should be sufficient for any conversion
332 332
333 // Only produced from strict conversion. 333 // Only produced from strict conversion.
334 if (result == sourceIllegal) { 334 if (result == sourceIllegal) {
335 ASSERT(strict); 335 DCHECK(strict);
336 return std::string(); 336 return std::string();
337 } 337 }
338 338
339 // Check for an unconverted high surrogate. 339 // Check for an unconverted high surrogate.
340 if (result == sourceExhausted) { 340 if (result == sourceExhausted) {
341 if (strict) 341 if (strict)
342 return std::string(); 342 return std::string();
343 // This should be one unpaired high surrogate. Treat it the same 343 // This should be one unpaired high surrogate. Treat it the same
344 // was as an unpaired high surrogate would have been handled in 344 // was as an unpaired high surrogate would have been handled in
345 // the middle of a string with non-strict conversion - which is 345 // the middle of a string with non-strict conversion - which is
346 // to say, simply encode it to UTF-8. 346 // to say, simply encode it to UTF-8.
347 ASSERT((characters + 1) == (m_impl.data() + length)); 347 DCHECK((characters + 1) == (m_impl.data() + length));
348 ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF)); 348 DCHECK((*characters >= 0xD800) && (*characters <= 0xDBFF));
349 // There should be room left, since one UChar hasn't been 349 // There should be room left, since one UChar hasn't been
350 // converted. 350 // converted.
351 ASSERT((buffer + 3) <= (buffer + bufferVector.size())); 351 DCHECK((buffer + 3) <= (buffer + bufferVector.size()));
352 putUTF8Triple(buffer, *characters); 352 putUTF8Triple(buffer, *characters);
353 } 353 }
354 354
355 return std::string(bufferVector.data(), buffer - bufferVector.data()); 355 return std::string(bufferVector.data(), buffer - bufferVector.data());
356 } 356 }
357 357
358 String16 String16::stripWhiteSpace() const 358 String16 String16::stripWhiteSpace() const
359 { 359 {
360 wstring result(m_impl); 360 wstring result(m_impl);
361 trim(result); 361 trim(result);
362 return result; 362 return result;
363 } 363 }
364 364
365 } // namespace protocol 365 } // namespace protocol
366 } // namespace blink 366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698