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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/String16WTF.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
(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/StringToNumber.h"
14 #include "wtf/text/WTFString.h"
15
16 namespace blink {
17 namespace protocol {
18
19 class PLATFORM_EXPORT String16 : public String16Base<String16, UChar> {
20 public:
21 static const size_t kNotFound = WTF::kNotFound;
22
23 String16() { }
24 String16(const String16& other) : m_impl(other.m_impl) { }
25 String16(const UChar* characters, unsigned length) : m_impl(characters, leng th) { }
26 String16(const char* characters) : String16(characters, strlen(characters)) { }
27 String16(const char* characters, size_t length)
28 {
29 UChar* data;
30 m_impl = WTF::String::createUninitialized(length, data);
31 for (size_t i = 0; i < length; ++i)
32 data[i] = characters[i];
33 }
34
35 ~String16() { }
36
37 String16 isolatedCopy() const { return String16(m_impl.isolatedCopy()); }
38 const UChar* characters16() const { return m_impl.isEmpty() ? nullptr : m_im pl.characters16(); }
39 size_t length() const { return m_impl.length(); }
40 bool isEmpty() const { return m_impl.isEmpty(); }
41 UChar operator[](unsigned index) const { return m_impl[index]; }
42 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_i mpl.substring(pos, len); }
43 size_t find(const String16& str, unsigned start = 0) const { return m_impl.f ind(str.impl(), start); }
44 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r eturn m_impl.reverseFind(str.impl(), start); }
45 void swap(String16& other) { m_impl.swap(other.m_impl); }
46
47 // WTF convenience constructors and helper methods.
48 String16(const WebString& other) : String16(String(other)) { }
49 template<typename StringType1, typename StringType2>
50 String16(const WTF::StringAppend<StringType1, StringType2>& impl) : String16 (String(impl)) { }
51 String16(const WTF::AtomicString& impl) : String16(String(impl)) { }
52 String16(const WTF::String& impl) : m_impl(impl) { m_impl.ensure16Bit(); }
53 String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue ) { }
54 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue (); }
55 operator WTF::String() const { return m_impl; }
56 operator WebString() { return m_impl; }
57 const WTF::String& impl() const { return m_impl; }
58
59 private:
60 WTF::String m_impl;
61 };
62
63 inline bool operator==(const String16& a, const String16& b) { return a.impl() = = b.impl(); }
64 inline bool operator!=(const String16& a, const String16& b) { return a.impl() ! = b.impl(); }
65 inline bool operator==(const String16& a, const char* b) { return a.impl() == b; }
66 inline String16 operator+(const String16& a, const char* b) { return String16(a. impl() + b); }
67 inline String16 operator+(const char* a, const String16& b) { return String16(a + b.impl()); }
68 inline String16 operator+(const String16& a, const String16& b) { return String1 6(a.impl() + b.impl()); }
69
70 } // namespace protocol
71 } // namespace blink
72
73 namespace std {
74 template<> struct hash<blink::protocol::String16> {
75 std::size_t operator()(const blink::protocol::String16& string) const
76 {
77 return StringHash::hash(string.impl());
78 }
79 };
80 } // namespace std
81
82 using InspectorProtocolConvenienceStringType = WTF::String;
83
84 // WTF helpers below this line.
85
86 namespace WTF {
87
88 struct String16Hash {
89 static unsigned hash(const blink::protocol::String16& key) { return StringHa sh::hash(key.impl()); }
90 static bool equal(const blink::protocol::String16& a, const blink::protocol: :String16& b)
91 {
92 return StringHash::equal(a.impl(), b.impl());
93 }
94 static const bool safeToCompareToEmptyOrDeleted = false;
95 };
96
97 template<typename T> struct DefaultHash;
98 template<> struct DefaultHash<blink::protocol::String16> {
99 typedef String16Hash Hash;
100 };
101
102 template<>
103 struct HashTraits<blink::protocol::String16> : SimpleClassHashTraits<blink::prot ocol::String16> {
104 static const bool hasIsEmptyValueFunction = true;
105 static bool isEmptyValue(const blink::protocol::String16& a) { return a.impl ().isNull(); }
106 };
107
108 } // namespace WTF
109
110 #endif // !defined(String16WTF_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698