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

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: for landing 2 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 "public/platform/WebString.h"
10 #include "wtf/text/StringBuilder.h"
11 #include "wtf/text/StringConcatenate.h"
12 #include "wtf/text/StringHash.h"
13 #include "wtf/text/UTF8.h"
14 #include "wtf/text/WTFString.h"
15
16 namespace blink {
17 namespace protocol {
18
19 class String16 {
20 public:
21 String16() { }
22 String16(const String16& other) : m_impl(other.m_impl) { }
23 String16(const UChar* u, unsigned length) : m_impl(u, length) { }
24 String16(const char* characters) : m_impl(characters) { }
25 String16(const char* characters, size_t size) : m_impl(characters, size) { }
26 String16(const WebString& other) : m_impl(other) { }
27 template<typename StringType1, typename StringType2>
28 String16(const WTF::StringAppend<StringType1, StringType2>& impl) : m_impl(i mpl) { }
29 ~String16() { }
30
31 // Integration constructors.
32 String16(const WTF::String& impl) : m_impl(impl) { }
33 String16(const WTF::AtomicString& impl) : m_impl(impl) { }
34 String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue ) { }
35
36 static String16 fromUTF8(const char* characters, size_t length) { return Str ing::fromUTF8(characters, length); }
37 static String16 number(int i) { return String::number(i); }
38 static String16 fromDouble(double number) { return Decimal::fromDouble(numbe r).toString(); }
39 static String16 createUninitialized(unsigned length, UChar*& data) { return String::createUninitialized(length, data); }
40 static bool codePointCompareLessThan(const String16& a, const String16& b)
41 {
42 return codePointCompare(a.impl(), b.impl()) < 0;
43 }
44
45 typedef enum {
46 conversionOK,
47 sourceExhausted,
48 targetExhausted,
49 sourceIllegal
50 } ConversionResult;
51
52 static ConversionResult convertUTF8ToUTF16(const char** sourceStart, const c har* sourceEnd, UChar** targetStart, UChar* targetEnd, bool* isSourceAllASCII = 0, bool strict = true)
53 {
54 return static_cast<ConversionResult>(WTF::Unicode::convertUTF8ToUTF16(so urceStart, sourceEnd, targetStart, targetEnd, isSourceAllASCII, strict));
55 }
56
57 bool validateUTF8()
58 {
59 return !m_impl.utf8(StrictUTF8Conversion).isNull();
60 }
61
62 size_t length() const { return m_impl.length(); }
63 bool isEmpty() const { return m_impl.isEmpty(); }
64 bool isNull() const { return m_impl.isNull(); }
65 UChar operator[](unsigned index) const { return m_impl[index]; }
66
67 bool is8Bit() const { return m_impl.is8Bit(); }
68 unsigned sizeInBytes() const { return m_impl.sizeInBytes(); }
69 const LChar* characters8() const { return m_impl.characters8(); }
70 const UChar* characters16() const { return m_impl.characters16(); }
71 String16 latin1Data()
72 {
73 CString latin1 = m_impl.latin1();
74 // Include terminating zero.
75 return String16(latin1.data(), latin1.length() + 1);
76 }
77
78 operator WTF::String() const { return m_impl; }
79 operator WebString() const { return m_impl; }
80 WTF::String impl() const { return m_impl; }
81
82 static double charactersToDouble(const LChar* characters, size_t length, boo l* ok = 0) { return ::charactersToDouble(characters, length, ok); }
83 static double charactersToDouble(const UChar* characters, size_t length, boo l* ok = 0) { return ::charactersToDouble(characters, length, ok); }
84
85 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_i mpl.substring(pos, len); }
86 String16 left(unsigned len) const { return m_impl.substring(0, len); }
87 String16 stripWhiteSpace() const { return m_impl.stripWhiteSpace(); }
88
89 int toInt(bool* ok = 0) const { return m_impl.toInt(ok); }
90 unsigned toUInt(bool* ok = 0) const { return m_impl.toUInt(ok); }
91
92 size_t find(UChar c, unsigned start = 0) const { return m_impl.find(c, start ); }
93 size_t find(const String16& str) const { return m_impl.find(str.impl()); }
94 size_t find(const String16& str, unsigned start) const { return m_impl.find( str.impl(), start); }
95 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.reverseFind(str.impl(), start); }
96
97 void append(const String16& str) { m_impl.append(str); };
98 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue (); }
99
100 bool startWith(const String16& s) const { return m_impl.startsWith(s); }
101 bool startWith(UChar character) const { return m_impl.startsWith(character); }
102 bool endsWith(const String16& s) const { return m_impl.endsWith(s); }
103 bool endsWith(UChar character) const { return m_impl.endsWith(character); }
104
105 private:
106 WTF::String m_impl;
107 };
108
109 class String16Builder {
110 public:
111 String16Builder() { }
112 void append(const String16& str) { m_impl.append(str); };
113 void append(UChar c) { m_impl.append(c); };
114 void append(LChar c) { m_impl.append(c); };
115 void append(char c) { m_impl.append(c); };
116 void append(const UChar* c, size_t size) { m_impl.append(c, size); };
117 void append(const char* characters, unsigned length) { m_impl.append(charact ers, length); }
118 void appendNumber(int number) { m_impl.appendNumber(number); }
119 String16 toString() { return m_impl.toString(); }
120 void reserveCapacity(unsigned newCapacity) { m_impl.reserveCapacity(newCapac ity); }
121
122 private:
123 WTF::StringBuilder m_impl;
124 };
125
126 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); }
127 inline bool operator!=(const String16& a, const String16& b) { return a.impl() ! = b.impl(); }
128 inline bool operator==(const String16& a, const char* b) { return a.impl() == b; }
129
130 inline String16 operator+(const String16& a, const char* b)
131 {
132 return String(a.impl() + b);
133 }
134
135 inline String16 operator+(const char* a, const String16& b)
136 {
137 return String(a + b.impl());
138 }
139
140 inline String16 operator+(const String16& a, const String16& b)
141 {
142 return String(a.impl() + b.impl());
143 }
144
145 } // namespace protocol
146 } // namespace blink
147
148 using String16 = blink::protocol::String16;
149 using String16Builder = blink::protocol::String16Builder;
150
151 namespace WTF {
152
153 struct String16Hash {
154 static unsigned hash(const String16& key) { return StringHash::hash(key.impl ()); }
155 static bool equal(const String16& a, const String16& b)
156 {
157 return StringHash::equal(a.impl(), b.impl());
158 }
159 static const bool safeToCompareToEmptyOrDeleted = false;
160 };
161
162 template<typename T> struct DefaultHash;
163 template<> struct DefaultHash<String16> {
164 typedef String16Hash Hash;
165 };
166
167 template<>
168 struct HashTraits<String16> : SimpleClassHashTraits<String16> {
169 static const bool hasIsEmptyValueFunction = true;
170 static bool isEmptyValue(const String16& a) { return a.isNull(); }
171 };
172
173 } // namespace WTF
174
175 #endif // !defined(String16WTF_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698