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

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

Issue 2226863003: [DevTools] Reduce API surface of String16. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 "platform/inspector_protocol/Platform.h" 7 #include "platform/inspector_protocol/Platform.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 template<typename CharType> inline bool isASCIIOctalDigit(CharType c) 45 template<typename CharType> inline bool isASCIIOctalDigit(CharType c)
46 { 46 {
47 return (c >= '0') & (c <= '7'); 47 return (c >= '0') & (c <= '7');
48 } 48 }
49 49
50 template<typename CharType> inline bool isASCIIPrintable(CharType c) 50 template<typename CharType> inline bool isASCIIPrintable(CharType c)
51 { 51 {
52 return c >= ' ' && c <= '~'; 52 return c >= ' ' && c <= '~';
53 } 53 }
54 54
55 /*
56 Statistics from a run of Apple's page load test for callers of isASCIISpace:
57
58 character count
59 --------- -----
60 non-spaces 689383
61 20 space 294720
62 0A \n 89059
63 09 \t 28320
64 0D \r 0
65 0C \f 0
66 0B \v 0
67 */
68 template<typename CharType> inline bool isASCIISpace(CharType c)
69 {
70 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
71 }
72
73 extern const LChar ASCIICaseFoldTable[256] = { 55 extern const LChar ASCIICaseFoldTable[256] = {
74 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c , 0x0d, 0x0e, 0x0f, 56 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c , 0x0d, 0x0e, 0x0f,
75 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c , 0x1d, 0x1e, 0x1f, 57 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c , 0x1d, 0x1e, 0x1f,
76 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c , 0x2d, 0x2e, 0x2f, 58 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c , 0x2d, 0x2e, 0x2f,
77 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c , 0x3d, 0x3e, 0x3f, 59 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c , 0x3d, 0x3e, 0x3f,
78 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f, 60 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f,
79 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c , 0x5d, 0x5e, 0x5f, 61 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c , 0x5d, 0x5e, 0x5f,
80 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f, 62 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c , 0x6d, 0x6e, 0x6f,
81 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c , 0x7d, 0x7e, 0x7f, 63 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c , 0x7d, 0x7e, 0x7f,
82 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c , 0x8d, 0x8e, 0x8f, 64 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c , 0x8d, 0x8e, 0x8f,
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 478
497 UChar* bufferCurrent = bufferStart; 479 UChar* bufferCurrent = bufferStart;
498 const char* stringCurrent = stringStart; 480 const char* stringCurrent = stringStart;
499 if (convertUTF8ToUTF16(&stringCurrent, stringStart + length, &bufferCurrent, bufferCurrent + buffer.size(), 0, true) != conversionOK) 481 if (convertUTF8ToUTF16(&stringCurrent, stringStart + length, &bufferCurrent, bufferCurrent + buffer.size(), 0, true) != conversionOK)
500 return String16(); 482 return String16();
501 483
502 unsigned utf16Length = bufferCurrent - bufferStart; 484 unsigned utf16Length = bufferCurrent - bufferStart;
503 return String16(bufferStart, utf16Length); 485 return String16(bufferStart, utf16Length);
504 } 486 }
505 487
506 // trim from start
507 static inline wstring &ltrim(wstring &s)
508 {
509 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<i nt, int>(std::isspace))));
510 return s;
511 }
512
513 // trim from end
514 static inline wstring &rtrim(wstring &s)
515 {
516 s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>( std::isspace))).base(), s.end());
517 return s;
518 }
519
520 // trim from both ends
521 static inline wstring &trim(wstring &s)
522 {
523 return ltrim(rtrim(s));
524 }
525
526 // static
527 std::string String16::intToString(int i)
528 {
529 char buffer[50];
530 std::sprintf(buffer, "%d", i);
531 return std::string(buffer);
532 }
533
534 // static
535 std::string String16::doubleToString(double d)
536 {
537 char buffer[100];
538 std::sprintf(buffer, "%f", d);
539 return std::string(buffer);
540 }
541
542 std::string String16::utf8() const 488 std::string String16::utf8() const
543 { 489 {
544 unsigned length = this->length(); 490 unsigned length = this->length();
545 491
546 if (!length) 492 if (!length)
547 return std::string(""); 493 return std::string("");
548 494
549 // Allocate a buffer big enough to hold all the characters 495 // Allocate a buffer big enough to hold all the characters
550 // (an individual UTF-16 UChar can only expand to 3 UTF-8 bytes). 496 // (an individual UTF-16 UChar can only expand to 3 UTF-8 bytes).
551 // Optimization ideas, if we find this function is hot: 497 // Optimization ideas, if we find this function is hot:
(...skipping 26 matching lines...) Expand all
578 DCHECK((*characters >= 0xD800) && (*characters <= 0xDBFF)); 524 DCHECK((*characters >= 0xD800) && (*characters <= 0xDBFF));
579 // There should be room left, since one UChar hasn't been 525 // There should be room left, since one UChar hasn't been
580 // converted. 526 // converted.
581 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); 527 DCHECK((buffer + 3) <= (buffer + bufferVector.size()));
582 putUTF8Triple(buffer, *characters); 528 putUTF8Triple(buffer, *characters);
583 } 529 }
584 530
585 return std::string(bufferVector.data(), buffer - bufferVector.data()); 531 return std::string(bufferVector.data(), buffer - bufferVector.data());
586 } 532 }
587 533
588 String16 String16::stripWhiteSpace() const
589 {
590 wstring result(m_impl);
591 trim(result);
592 return result;
593 }
594
595 } // namespace protocol 534 } // namespace protocol
596 } // namespace blink 535 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698