| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 V8_INSPECTOR_STRING16_H_ | 5 #ifndef V8_INSPECTOR_STRING16_H_ |
| 6 #define V8_INSPECTOR_STRING16_H_ | 6 #define V8_INSPECTOR_STRING16_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <cctype> | 9 #include <cctype> |
| 10 #include <climits> | 10 #include <climits> |
| 11 #include <cstring> | 11 #include <cstring> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 namespace v8_inspector { | 15 namespace v8_inspector { |
| 16 | 16 |
| 17 using UChar = uint16_t; | 17 using UChar = uint16_t; |
| 18 | 18 |
| 19 class String16 { | 19 class String16 { |
| 20 public: | 20 public: |
| 21 static const size_t kNotFound = static_cast<size_t>(-1); | 21 static const size_t kNotFound = static_cast<size_t>(-1); |
| 22 | 22 |
| 23 String16() {} | 23 String16(); |
| 24 String16(const String16& other) | 24 String16(const String16& other); |
| 25 : m_impl(other.m_impl), hash_code(other.hash_code) {} | 25 String16(String16&& other); |
| 26 String16(String16&& other) | 26 String16(const UChar* characters, size_t size); |
| 27 : m_impl(std::move(other.m_impl)), hash_code(other.hash_code) {} | 27 String16(const UChar* characters); // NOLINT(runtime/explicit) |
| 28 String16(const UChar* characters, size_t size) : m_impl(characters, size) {} | 28 String16(const char* characters); // NOLINT(runtime/explicit) |
| 29 String16(const UChar* characters) // NOLINT(runtime/explicit) | 29 String16(const char* characters, size_t size); |
| 30 : m_impl(characters) {} | 30 explicit String16(const std::basic_string<UChar>& impl); |
| 31 String16(const char* characters) // NOLINT(runtime/explicit) | |
| 32 : String16(characters, std::strlen(characters)) {} | |
| 33 String16(const char* characters, size_t size) { | |
| 34 m_impl.resize(size); | |
| 35 for (size_t i = 0; i < size; ++i) m_impl[i] = characters[i]; | |
| 36 } | |
| 37 explicit String16(const std::basic_string<UChar>& impl) : m_impl(impl) {} | |
| 38 | 31 |
| 39 String16& operator=(const String16& other) { | 32 String16& operator=(const String16& other); |
| 40 m_impl = other.m_impl; | 33 String16& operator=(String16&& other); |
| 41 hash_code = other.hash_code; | |
| 42 return *this; | |
| 43 } | |
| 44 String16& operator=(String16&& other) { | |
| 45 m_impl = std::move(other.m_impl); | |
| 46 hash_code = other.hash_code; | |
| 47 return *this; | |
| 48 } | |
| 49 | 34 |
| 50 static String16 fromInteger(int); | 35 static String16 fromInteger(int); |
| 51 static String16 fromInteger(size_t); | 36 static String16 fromInteger(size_t); |
| 52 static String16 fromDouble(double); | 37 static String16 fromDouble(double); |
| 53 static String16 fromDouble(double, int precision); | 38 static String16 fromDouble(double, int precision); |
| 54 | 39 |
| 55 int toInteger(bool* ok = nullptr) const; | 40 int toInteger(bool* ok = nullptr) const; |
| 56 String16 stripWhiteSpace() const; | 41 String16 stripWhiteSpace() const; |
| 57 const UChar* characters16() const { return m_impl.c_str(); } | 42 const UChar* characters16() const { return m_impl.c_str(); } |
| 58 size_t length() const { return m_impl.length(); } | 43 size_t length() const { return m_impl.length(); } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 std::size_t operator()(const v8_inspector::String16& string) const { | 142 std::size_t operator()(const v8_inspector::String16& string) const { |
| 158 return string.hash(); | 143 return string.hash(); |
| 159 } | 144 } |
| 160 }; | 145 }; |
| 161 | 146 |
| 162 } // namespace std | 147 } // namespace std |
| 163 | 148 |
| 164 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION) | 149 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION) |
| 165 | 150 |
| 166 #endif // V8_INSPECTOR_STRING16_H_ | 151 #endif // V8_INSPECTOR_STRING16_H_ |
| OLD | NEW |