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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/String16.h

Issue 2251343003: [DevTools] Generate separate copies of inspector_protocol. (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 #ifndef String16STL_h 5 #ifndef String16_h
6 #define String16STL_h 6 #define String16_h
7
8 #include "platform/PlatformExport.h"
7 9
8 #include <cctype> 10 #include <cctype>
9 #include <climits> 11 #include <climits>
10 #include <cstdlib>
11 #include <cstring> 12 #include <cstring>
12 #include <stdint.h> 13 #include <stdint.h>
13 #include <string> 14 #include <string>
14 #include <vector> 15 #include <vector>
15 16
17 namespace v8_inspector {
18
16 using UChar = uint16_t; 19 using UChar = uint16_t;
17 20
18 namespace blink { 21 class PLATFORM_EXPORT String16 {
19 namespace protocol {
20
21 class String16 : public String16Base<String16, UChar> {
22 public: 22 public:
23 static const size_t kNotFound = static_cast<size_t>(-1); 23 static const size_t kNotFound = static_cast<size_t>(-1);
24 24
25 String16() { } 25 String16() { }
26 String16(const String16& other) : m_impl(other.m_impl) { } 26 String16(const String16& other) : m_impl(other.m_impl) { }
27 String16(const UChar* characters, size_t size) : m_impl(characters, size) { } 27 String16(const UChar* characters, size_t size) : m_impl(characters, size) { }
28 String16(const UChar* characters) : m_impl(characters) { } 28 String16(const UChar* characters) : m_impl(characters) { }
29 String16(const char* characters) : String16(characters, std::strlen(characte rs)) { } 29 String16(const char* characters) : String16(characters, std::strlen(characte rs)) { }
30 String16(const char* characters, size_t size) 30 String16(const char* characters, size_t size)
31 { 31 {
32 m_impl.resize(size); 32 m_impl.resize(size);
33 for (size_t i = 0; i < size; ++i) 33 for (size_t i = 0; i < size; ++i)
34 m_impl[i] = characters[i]; 34 m_impl[i] = characters[i];
35 } 35 }
36 36
37 String16 isolatedCopy() const { return String16(m_impl); } 37 static String16 fromInteger(int);
38 static String16 fromDouble(double);
39 static String16 fromDoublePrecision3(double);
40 static String16 fromDoublePrecision6(double);
41
42 double toDouble(bool* ok = nullptr) const;
43 int toInteger(bool* ok = nullptr) const;
44 String16 stripWhiteSpace() const;
45 bool startsWith(const char* prefix) const;
38 const UChar* characters16() const { return m_impl.c_str(); } 46 const UChar* characters16() const { return m_impl.c_str(); }
39 size_t length() const { return m_impl.length(); } 47 size_t length() const { return m_impl.length(); }
40 bool isEmpty() const { return !m_impl.length(); } 48 bool isEmpty() const { return !m_impl.length(); }
41 UChar operator[](unsigned index) const { return m_impl[index]; } 49 UChar operator[](unsigned index) const { return m_impl[index]; }
42 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return Str ing16(m_impl.substr(pos, len)); } 50 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return Str ing16(m_impl.substr(pos, len)); }
43 size_t find(const String16& str, unsigned start = 0) const { return m_impl.f ind(str.m_impl, start); } 51 size_t find(const String16& str, unsigned start = 0) const { return m_impl.f ind(str.m_impl, start); }
44 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.rfind(str.m_impl, start); } 52 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.rfind(str.m_impl, start); }
45 53
46 // Convenience methods. 54 // Convenience methods.
47 std::string utf8() const; 55 std::string utf8() const;
(...skipping 21 matching lines...) Expand all
69 }; 77 };
70 78
71 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); } 79 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); }
72 inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); } 80 inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); }
73 inline bool operator!=(const String16& a, const String16& b) { return a.impl() ! = b.impl(); } 81 inline bool operator!=(const String16& a, const String16& b) { return a.impl() ! = b.impl(); }
74 inline bool operator==(const String16& a, const char* b) { return a.impl() == St ring16(b).impl(); } 82 inline bool operator==(const String16& a, const char* b) { return a.impl() == St ring16(b).impl(); }
75 inline String16 operator+(const String16& a, const char* b) { return String16(a. impl() + String16(b).impl()); } 83 inline String16 operator+(const String16& a, const char* b) { return String16(a. impl() + String16(b).impl()); }
76 inline String16 operator+(const char* a, const String16& b) { return String16(St ring16(a).impl() + b.impl()); } 84 inline String16 operator+(const char* a, const String16& b) { return String16(St ring16(a).impl() + b.impl()); }
77 inline String16 operator+(const String16& a, const String16& b) { return String1 6(a.impl() + b.impl()); } 85 inline String16 operator+(const String16& a, const String16& b) { return String1 6(a.impl() + b.impl()); }
78 86
79 } // namespace protocol 87 class PLATFORM_EXPORT String16Builder {
80 } // namespace blink 88 public:
89 String16Builder();
90 void append(const String16&);
91 void append(UChar);
92 void append(char);
93 void append(const UChar*, size_t);
94 void append(const char*, size_t);
95 String16 toString();
96 void reserveCapacity(size_t);
97
98 private:
99 std::vector<UChar> m_buffer;
100 };
101
102 } // namespace v8_inspector
81 103
82 #if !defined(__APPLE__) || defined(_LIBCPP_VERSION) 104 #if !defined(__APPLE__) || defined(_LIBCPP_VERSION)
83 105
84 namespace std { 106 namespace std {
85 template<> struct hash<blink::protocol::String16> { 107 template<> struct hash<v8_inspector::String16> {
86 std::size_t operator()(const blink::protocol::String16& string) const 108 std::size_t operator()(const v8_inspector::String16& string) const
87 { 109 {
88 return string.hash(); 110 return string.hash();
89 } 111 }
90 }; 112 };
91 113
92 } // namespace std 114 } // namespace std
93 115
94 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION) 116 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
95 117
96 class InspectorProtocolConvenienceStringType { 118 #endif // !defined(String16_h)
97 public:
98 // This class should not be ever instantiated, so we don't implement constru ctors.
99 InspectorProtocolConvenienceStringType();
100 InspectorProtocolConvenienceStringType(const blink::protocol::String16& othe r);
101 operator blink::protocol::String16() const { return blink::protocol::String1 6(); };
102 };
103
104 #endif // !defined(String16STL_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698