| OLD | NEW |
| 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 String16WTF_h | 5 #ifndef String16WTF_h |
| 6 #define String16WTF_h | 6 #define String16WTF_h |
| 7 | 7 |
| 8 #include "platform/Decimal.h" | 8 #include "platform/Decimal.h" |
| 9 #include "public/platform/WebString.h" | 9 #include "public/platform/WebString.h" |
| 10 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
| 11 #include "wtf/text/StringConcatenate.h" | 11 #include "wtf/text/StringConcatenate.h" |
| 12 #include "wtf/text/StringHash.h" | 12 #include "wtf/text/StringHash.h" |
| 13 #include "wtf/text/UTF8.h" | |
| 14 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 namespace protocol { | 16 namespace protocol { |
| 18 | 17 |
| 19 class String16 { | 18 class PLATFORM_EXPORT String16 { |
| 20 public: | 19 public: |
| 21 String16() { } | 20 String16() { } |
| 22 String16(const String16& other) : m_impl(other.m_impl) { } | 21 String16(const String16& other); |
| 23 String16(const UChar* u, unsigned length) : m_impl(u, length) { } | 22 String16(const UChar*, unsigned); |
| 24 String16(const char* characters) : m_impl(characters) { } | 23 String16(const char*); |
| 25 String16(const char* characters, size_t size) : m_impl(characters, size) { } | 24 String16(const char*, size_t); |
| 26 String16(const WebString& other) : m_impl(other) { } | 25 static String16 createUninitialized(unsigned length, UChar*& data); |
| 26 |
| 27 // WTF convenience constructors and helper methods. |
| 28 String16(const WebString& other) : String16(String(other)) { } |
| 27 template<typename StringType1, typename StringType2> | 29 template<typename StringType1, typename StringType2> |
| 28 String16(const WTF::StringAppend<StringType1, StringType2>& impl) : m_impl(i
mpl) { } | 30 String16(const WTF::StringAppend<StringType1, StringType2>& impl) : String16
(String(impl)) { } |
| 31 String16(const WTF::AtomicString& impl) : String16(String(impl)) { } |
| 32 String16(const WTF::String& impl); |
| 33 String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue
) { } |
| 34 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue
(); } |
| 35 operator WTF::String() const { return m_impl; } |
| 36 operator WebString() { return m_impl; } |
| 37 const WTF::String& impl() const { return m_impl; } |
| 38 |
| 29 ~String16() { } | 39 ~String16() { } |
| 30 | 40 |
| 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); } | 41 static String16 number(int i) { return String::number(i); } |
| 38 static String16 fromDouble(double number) { return Decimal::fromDouble(numbe
r).toString(); } | 42 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 | 43 |
| 62 size_t length() const { return m_impl.length(); } | 44 size_t length() const { return m_impl.length(); } |
| 63 bool isEmpty() const { return m_impl.isEmpty(); } | 45 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]; } | 46 UChar operator[](unsigned index) const { return m_impl[index]; } |
| 66 | 47 |
| 67 bool is8Bit() const { return m_impl.is8Bit(); } | |
| 68 unsigned sizeInBytes() const { return m_impl.sizeInBytes(); } | 48 unsigned sizeInBytes() const { return m_impl.sizeInBytes(); } |
| 69 const LChar* characters8() const { return m_impl.characters8(); } | 49 const UChar* characters16() const { return m_impl.isEmpty() ? nullptr : m_im
pl.characters16(); } |
| 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 | 50 |
| 82 static double charactersToDouble(const LChar* characters, size_t length, boo
l* ok = 0) { return ::charactersToDouble(characters, length, ok); } | 51 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); } | 52 static double charactersToDouble(const UChar* characters, size_t length, boo
l* ok = 0) { return ::charactersToDouble(characters, length, ok); } |
| 84 | 53 |
| 85 String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_i
mpl.substring(pos, len); } | 54 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(); } | 55 String16 stripWhiteSpace() const { return m_impl.stripWhiteSpace(); } |
| 88 | 56 |
| 89 int toInt(bool* ok = 0) const { return m_impl.toInt(ok); } | 57 int toInt(bool* ok = 0) const { return m_impl.toInt(ok); } |
| 90 unsigned toUInt(bool* ok = 0) const { return m_impl.toUInt(ok); } | |
| 91 | 58 |
| 92 size_t find(UChar c, unsigned start = 0) const { return m_impl.find(c, start
); } | 59 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()); } | 60 size_t find(const String16& str, unsigned start = 0) const { return m_impl.f
ind(str.impl(), start); } |
| 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); } | 61 size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { r
eturn m_impl.reverseFind(str.impl(), start); } |
| 96 | 62 |
| 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); } | 63 bool startWith(const String16& s) const { return m_impl.startsWith(s); } |
| 101 bool startWith(UChar character) const { return m_impl.startsWith(character);
} | 64 bool startWith(UChar character) const { return m_impl.startsWith(character);
} |
| 102 bool endsWith(const String16& s) const { return m_impl.endsWith(s); } | 65 bool endsWith(const String16& s) const { return m_impl.endsWith(s); } |
| 103 bool endsWith(UChar character) const { return m_impl.endsWith(character); } | 66 bool endsWith(UChar character) const { return m_impl.endsWith(character); } |
| 104 | 67 |
| 105 private: | 68 private: |
| 106 WTF::String m_impl; | 69 WTF::String m_impl; |
| 107 }; | 70 }; |
| 108 | 71 |
| 109 class String16Builder { | 72 class String16Builder { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 }; | 123 }; |
| 161 | 124 |
| 162 template<typename T> struct DefaultHash; | 125 template<typename T> struct DefaultHash; |
| 163 template<> struct DefaultHash<String16> { | 126 template<> struct DefaultHash<String16> { |
| 164 typedef String16Hash Hash; | 127 typedef String16Hash Hash; |
| 165 }; | 128 }; |
| 166 | 129 |
| 167 template<> | 130 template<> |
| 168 struct HashTraits<String16> : SimpleClassHashTraits<String16> { | 131 struct HashTraits<String16> : SimpleClassHashTraits<String16> { |
| 169 static const bool hasIsEmptyValueFunction = true; | 132 static const bool hasIsEmptyValueFunction = true; |
| 170 static bool isEmptyValue(const String16& a) { return a.isNull(); } | 133 static bool isEmptyValue(const String16& a) { return a.impl().isNull(); } |
| 171 }; | 134 }; |
| 172 | 135 |
| 173 } // namespace WTF | 136 } // namespace WTF |
| 174 | 137 |
| 175 #endif // !defined(String16WTF_h) | 138 #endif // !defined(String16WTF_h) |
| OLD | NEW |