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

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: win compile Created 4 years, 3 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 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 int toInteger(bool* ok = nullptr) const;
43 String16 stripWhiteSpace() const;
38 const UChar* characters16() const { return m_impl.c_str(); } 44 const UChar* characters16() const { return m_impl.c_str(); }
39 size_t length() const { return m_impl.length(); } 45 size_t length() const { return m_impl.length(); }
40 bool isEmpty() const { return !m_impl.length(); } 46 bool isEmpty() const { return !m_impl.length(); }
41 UChar operator[](unsigned index) const { return m_impl[index]; } 47 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)); } 48 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); } 49 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); } 50 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.rfind(str.m_impl, start); }
45 void swap(String16& other) { m_impl.swap(other.m_impl); } 51 void swap(String16& other) { m_impl.swap(other.m_impl); }
46 52
47 // Convenience methods. 53 // Convenience methods.
(...skipping 22 matching lines...) Expand all
70 }; 76 };
71 77
72 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); } 78 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(); } 79 inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); }
74 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(); }
75 inline bool operator==(const String16& a, const char* b) { return a.impl() == St ring16(b).impl(); } 81 inline bool operator==(const String16& a, const char* b) { return a.impl() == St ring16(b).impl(); }
76 inline String16 operator+(const String16& a, const char* b) { return String16(a. impl() + String16(b).impl()); } 82 inline String16 operator+(const String16& a, const char* b) { return String16(a. impl() + String16(b).impl()); }
77 inline String16 operator+(const char* a, const String16& b) { return String16(St ring16(a).impl() + b.impl()); } 83 inline String16 operator+(const char* a, const String16& b) { return String16(St ring16(a).impl() + b.impl()); }
78 inline String16 operator+(const String16& a, const String16& b) { return String1 6(a.impl() + b.impl()); } 84 inline String16 operator+(const String16& a, const String16& b) { return String1 6(a.impl() + b.impl()); }
79 85
80 } // namespace protocol 86 class String16Builder {
81 } // namespace blink 87 public:
88 String16Builder();
89 void append(const String16&);
90 void append(UChar);
91 void append(char);
92 void append(const UChar*, size_t);
93 void append(const char*, size_t);
94 String16 toString();
95 void reserveCapacity(size_t);
96
97 private:
98 std::vector<UChar> m_buffer;
99 };
100
101 } // namespace v8_inspector
82 102
83 #if !defined(__APPLE__) || defined(_LIBCPP_VERSION) 103 #if !defined(__APPLE__) || defined(_LIBCPP_VERSION)
84 104
85 namespace std { 105 namespace std {
86 template<> struct hash<blink::protocol::String16> { 106 template<> struct hash<v8_inspector::String16> {
87 std::size_t operator()(const blink::protocol::String16& string) const 107 std::size_t operator()(const v8_inspector::String16& string) const
88 { 108 {
89 return string.hash(); 109 return string.hash();
90 } 110 }
91 }; 111 };
92 112
93 } // namespace std 113 } // namespace std
94 114
95 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION) 115 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
96 116
97 class InspectorProtocolConvenienceStringType { 117 #endif // !defined(String16_h)
98 public:
99 // This class should not be ever instantiated, so we don't implement constru ctors.
100 InspectorProtocolConvenienceStringType();
101 InspectorProtocolConvenienceStringType(const blink::protocol::String16& othe r);
102 operator blink::protocol::String16() const { return blink::protocol::String1 6(); };
103 };
104
105 #endif // !defined(String16STL_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698