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