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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/String16WTF.h

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef String16WTF_h
6 #define String16WTF_h
7
8 #include "platform/Decimal.h"
9 #include "wtf/text/StringBuilder.h"
10 #include "wtf/text/StringConcatenate.h"
11 #include "wtf/text/StringHash.h"
12 #include "wtf/text/UTF8.h"
13 #include "wtf/text/WTFString.h"
14
15 namespace blink {
16 namespace protocol {
17
18 class String16 {
19 public:
20 String16() { }
21 String16(const String16& other) : m_impl(other.m_impl) { }
22 String16(const UChar* u, unsigned length) : m_impl(u, length) { }
23 String16(const char* characters) : m_impl(characters) { }
24 String16(const char* characters, size_t size) : m_impl(characters, size) { }
25 ~String16() { }
26
27 // Integration constructors.
28 String16(const WTF::String& impl) : m_impl(impl) { }
29 String16(const WTF::AtomicString& impl) : m_impl(impl) { }
30 String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue ) { }
31
32 static String16 fromUTF8(const char* characters, size_t length) { return Str ing::fromUTF8(characters, length); }
33
34 static String16 number(int i) { return String::number(i); }
35 static String16 createUninitialized(unsigned length, UChar*& data) { return String::createUninitialized(length, data); }
36 static bool codePointCompareLessThan(const String16& a, const String16& b)
37 {
38 return codePointCompare(a.impl(), b.impl()) < 0;
39 }
40
41 size_t length() const { return m_impl.length(); }
42 bool isEmpty() const { return m_impl.isEmpty(); }
43 bool isNull() const { return m_impl.isNull(); }
44 UChar operator[](unsigned index) const { return m_impl[index]; }
45
46 bool is8Bit() const { return m_impl.is8Bit(); }
47 unsigned sizeInBytes() const { return m_impl.sizeInBytes(); }
48 const LChar* characters8() const { return m_impl.characters8(); }
49 const UChar* characters16() const { return m_impl.characters16(); }
50 String16 latin1()
51 {
52 CString latin1 = m_impl.latin1();
53 return String16(latin1.data(), latin1.length());
54 }
55
56 operator WTF::String() const { return m_impl; }
57 WTF::String impl() const { return m_impl; }
58
59 static double charactersToDouble(const LChar* characters, size_t length, boo l* ok = 0) { return ::charactersToDouble(characters, length, ok); }
60 static double charactersToDouble(const UChar* characters, size_t length, boo l* ok = 0) { return ::charactersToDouble(characters, length, ok); }
61
62 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_i mpl.substring(pos, len); }
63 String16 left(unsigned len) const { return m_impl.substring(0, len); }
64 String16 stripWhiteSpace() const { return m_impl.stripWhiteSpace(); }
65
66 int toInt(bool* ok = 0) const { return m_impl.toInt(ok); }
67 unsigned toUInt(bool* ok = 0) const { return m_impl.toUInt(ok); }
68
69 size_t find(UChar c, unsigned start = 0) const { return m_impl.find(c, start ); }
70 size_t find(const String16& str) const { return m_impl.find(str.impl()); }
71 size_t find(const String16& str, unsigned start) const { return m_impl.find( str.impl(), start); }
72 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.reverseFind(str.impl(), start); }
73
74 void append(const String16& str) { m_impl.append(str); };
75 void append(UChar c) { m_impl.append(c); };
76 void append(LChar c) { m_impl.append(c); };
77 void append(char c) { m_impl.append(c); };
78 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue (); }
79
80 bool startWith(const String16& s) const { return m_impl.startsWith(s); }
81 bool startWith(UChar character) const { return m_impl.startsWith(character); }
82 bool endsWith(const String16& s) const { return m_impl.endsWith(s); }
83 bool endsWith(UChar character) const { return m_impl.endsWith(character); }
84
85 private:
86 WTF::String m_impl;
87 };
88
89 class String16Builder {
90 public:
91 String16Builder() { }
92 void append(const String16& str) { m_impl.append(str); };
93 void append(UChar c) { m_impl.append(c); };
94 void append(const UChar* c, size_t size) { m_impl.append(c, size); };
95 void append(char c) { m_impl.append(c); };
96 void append(int i) { m_impl.append(i); };
97 void append(const char* characters, unsigned length) { m_impl.append(charact ers, length); }
98 void appendNumber(int number) { m_impl.append(number); }
99 String16 toString() { return m_impl.toString(); }
100 void reserveCapacity(unsigned newCapacity) { m_impl.reserveCapacity(newCapac ity); }
101
102 private:
103 WTF::StringBuilder m_impl;
104 };
105
106 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); }
107 inline bool operator!=(const String16& a, const String16& b) { return a.impl() ! = b.impl(); }
108 inline bool operator==(const String16& a, const char* b) { return a.impl() == b; }
109
110 inline String16 operator+(const String16& a, const char* b)
111 {
112 return String(a.impl() + b);
113 }
114
115 inline String16 operator+(const char* a, const String16& b)
116 {
117 return String(a + b.impl());
118 }
119
120 inline String16 operator+(const String16& a, const String16& b)
121 {
122 return String(a.impl() + b.impl());
123 }
124
125 } // namespace protocol
126 } // namespace blink
127
128 using String16 = blink::protocol::String16;
129 using String16Builder = blink::protocol::String16Builder;
130
131 namespace WTF {
132
133 struct String16Hash {
134 static unsigned hash(const String16& key) { return StringHash::hash(key.impl ()); }
135 static bool equal(const String16& a, const String16& b)
136 {
137 return StringHash::equal(a.impl(), b.impl());
138 }
139 static const bool safeToCompareToEmptyOrDeleted = false;
140 };
141
142 template<typename T> struct DefaultHash;
143 template<> struct DefaultHash<String16> {
144 typedef String16Hash Hash;
145 };
146
147 template<>
148 struct HashTraits<String16> : SimpleClassHashTraits<String16> {
149 static const bool hasIsEmptyValueFunction = true;
150 static bool isEmptyValue(const String16& a) { return a.isNull(); }
151 };
152
153 } // namespace WTF
154
155 #endif // !defined(String16WTF_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698