5 #ifndef V8_INSPECTOR_STRING_16_H_ 6 #define V8_INSPECTOR_STRING_16_H_ 15 #include "src/base/compiler-specific.h" 19 using UChar = uint16_t;
23 static const size_t kNotFound =
static_cast<size_t>(-1);
28 String16(
const UChar* characters,
size_t size);
31 String16(
const char* characters,
size_t size);
32 explicit String16(
const std::basic_string<UChar>& impl);
40 static String16 fromDouble(
double,
int precision);
42 int64_t toInteger64(
bool* ok =
nullptr)
const;
43 int toInteger(
bool* ok =
nullptr)
const;
45 const UChar* characters16()
const {
return m_impl.c_str(); }
46 size_t length()
const {
return m_impl.length(); }
47 bool isEmpty()
const {
return !m_impl.length(); }
48 UChar operator[](
size_t index)
const {
return m_impl[index]; }
49 String16 substring(
size_t pos,
size_t len = UINT_MAX)
const {
50 return String16(m_impl.substr(pos, len));
52 size_t find(
const String16& str,
size_t start = 0)
const {
53 return m_impl.find(str.m_impl, start);
55 size_t reverseFind(
const String16& str,
size_t start = UINT_MAX)
const {
56 return m_impl.rfind(str.m_impl, start);
58 size_t find(UChar c,
size_t start = 0)
const {
return m_impl.find(c, start); }
59 size_t reverseFind(UChar c,
size_t start = UINT_MAX)
const {
60 return m_impl.rfind(c, start);
63 m_impl.swap(other.m_impl);
64 std::swap(hash_code, other.hash_code);
68 std::string utf8()
const;
69 static String16 fromUTF8(
const char* stringStart,
size_t length);
71 std::size_t hash()
const {
73 for (
char c : m_impl) hash_code = 31 * hash_code + c;
76 if (!hash_code) ++hash_code;
81 inline bool operator==(
const String16& other)
const {
82 return m_impl == other.m_impl;
84 inline bool operator<(
const String16& other)
const {
85 return m_impl < other.m_impl;
87 inline bool operator!=(
const String16& other)
const {
88 return m_impl != other.m_impl;
91 return String16(m_impl + other.m_impl);
95 template <
typename...
T>
99 std::basic_string<UChar> m_impl;
100 mutable std::size_t hash_code = 0;
113 void append(
const UChar*,
size_t);
114 void append(
const char*,
size_t);
115 void appendNumber(
int);
116 void appendNumber(
size_t);
117 void appendUnsignedAsHex(uint64_t);
120 void reserveCapacity(
size_t);
122 template <
typename T,
typename... R>
123 void appendAll(
T first, R... rest) {
130 std::vector<UChar> m_buffer;
133 template <
typename...
T>
136 builder.appendAll(args...);
137 return builder.toString();
142 #if !defined(__APPLE__) || defined(_LIBCPP_VERSION) 148 return string.hash();
154 #endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION) 156 #endif // V8_INSPECTOR_STRING_16_H_