| Index: third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
|
| diff --git a/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h b/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
|
| index 73b541a0f36f9a2711c3e7335e302fb847b6db07..e76e9775fb9ebc60e76deddfaeda0fa4a9273458 100644
|
| --- a/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
|
| +++ b/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
|
| @@ -5,7 +5,9 @@
|
| #ifndef String16STL_h
|
| #define String16STL_h
|
|
|
| +#include <cstdlib>
|
| #include <cstring>
|
| +#include <stdint.h>
|
| #include <string>
|
| #include <vector>
|
|
|
| @@ -35,25 +37,27 @@ public:
|
| }
|
| String16(const UChar* characters, size_t size) : m_impl(characters, size) { }
|
| String16 isolatedCopy() const { return String16(m_impl); }
|
| - ~String16() { }
|
|
|
| unsigned sizeInBytes() const { return m_impl.size() * sizeof(UChar); }
|
| const UChar* characters16() const { return m_impl.c_str(); }
|
| std::string utf8() const;
|
| - static String16 number(int i) { return String16(std::to_string(i).c_str()); }
|
| - static String16 fromDouble(double d) { return String16(std::to_string(d).c_str()); }
|
| - static String16 fromDoubleFixedPrecision(double d, int len) { return String16(std::to_string(d).c_str()); }
|
| + static String16 fromUTF8(const char* stringStart, size_t length);
|
| + static String16 number(int i) { return String16(String16::intToString(i).c_str()); }
|
| + static String16 fromDouble(double d) { return String16(String16::doubleToString(d).c_str()); }
|
| + static String16 fromDoubleFixedPrecision(double d, int len) { return String16(String16::doubleToString(d).c_str()); }
|
|
|
| static double charactersToDouble(const UChar* characters, size_t length, bool* ok = 0)
|
| {
|
| - size_t idx;
|
| std::string str;
|
| str.resize(length);
|
| for (size_t i = 0; i < length; ++i)
|
| str[i] = static_cast<char>(characters[i]);
|
| - double result = stod(str, &idx);
|
| +
|
| + const char* buffer = str.c_str();
|
| + char* endptr;
|
| + double result = strtod(buffer, &endptr);
|
| if (ok)
|
| - *ok = idx == length;
|
| + *ok = buffer + length == endptr;
|
| return result;
|
| }
|
|
|
| @@ -67,14 +71,16 @@ public:
|
| int toInt(bool* ok = 0) const
|
| {
|
| size_t length = m_impl.length();
|
| - size_t idx;
|
| std::string str;
|
| str.resize(length);
|
| for (size_t i = 0; i < length; ++i)
|
| str[i] = static_cast<char>(m_impl[i]);
|
| - int result = stoi(str, &idx);
|
| +
|
| + const char* buffer = str.c_str();
|
| + char* endptr;
|
| + int result = strtol(buffer, &endptr, 10);
|
| if (ok)
|
| - *ok = idx == length;
|
| + *ok = buffer + length == endptr;
|
| return result;
|
| }
|
|
|
| @@ -97,6 +103,13 @@ public:
|
| return m_impl.rfind(str.m_impl, start);
|
| }
|
|
|
| + bool startWith(const String16& s) const
|
| + {
|
| + if (m_impl.length() < s.m_impl.length())
|
| + return false;
|
| + return m_impl.substr(0, s.m_impl.length()) == s.m_impl;
|
| + }
|
| +
|
| bool endsWith(UChar character) const
|
| {
|
| return m_impl.length() && m_impl[m_impl.length() - 1] == character;
|
| @@ -118,6 +131,8 @@ public:
|
| }
|
|
|
| private:
|
| + static std::string intToString(int);
|
| + static std::string doubleToString(double);
|
| // presubmit: allow wstring
|
| wstring m_impl;
|
| mutable bool has_hash = false;
|
| @@ -155,7 +170,7 @@ public:
|
|
|
| void appendNumber(int i)
|
| {
|
| - m_impl = m_impl + String16(std::to_string(i).c_str()).impl();
|
| + m_impl = m_impl + String16::number(i).impl();
|
| }
|
|
|
| void append(const UChar* c, size_t length)
|
| @@ -186,6 +201,7 @@ private:
|
| inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); }
|
| inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); }
|
| inline bool operator==(const String16& a, const char* b) { return a.impl() == String16(b).impl(); }
|
| +inline bool operator<(const String16& a, const String16& b) { return a.impl() < b.impl(); }
|
|
|
| inline String16 operator+(const String16& a, const char* b)
|
| {
|
| @@ -224,14 +240,4 @@ public:
|
|
|
| using String = WTF::String;
|
|
|
| -namespace std {
|
| -template<>
|
| -struct hash<String16> {
|
| -std::size_t operator()(const String16& k) const
|
| -{
|
| - return k.hash();
|
| -}
|
| -};
|
| -}
|
| -
|
| #endif // !defined(String16STL_h)
|
|
|