Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Unified Diff: third_party/WebKit/Source/platform/inspector_protocol/String16STL.h

Issue 2226863003: [DevTools] Reduce API surface of String16. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4dd4369ebdd7888b927c871869553d9a4119b22d..92429fe6541ea5fc7b0403f2738527f2e21b2122 100644
--- a/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
+++ b/third_party/WebKit/Source/platform/inspector_protocol/String16STL.h
@@ -26,8 +26,7 @@ class String16 {
public:
String16() { }
String16(const String16& other) : m_impl(other.m_impl) { }
- // presubmit: allow wstring
- String16(const wstring& impl) : m_impl(impl) { }
+ String16(const UChar* characters, size_t size) : m_impl(characters, size) { }
String16(const UChar* characters) : m_impl(characters) { }
String16(const char* characters) : String16(characters, std::strlen(characters)) { }
String16(const char* characters, size_t size)
@@ -36,88 +35,24 @@ public:
for (size_t i = 0; i < size; ++i)
m_impl[i] = characters[i];
}
- String16(const UChar* characters, size_t size) : m_impl(characters, size) { }
- String16 isolatedCopy() const { return String16(m_impl); }
- unsigned sizeInBytes() const { return m_impl.size() * sizeof(UChar); }
+ String16 isolatedCopy() const { return String16(m_impl); }
const UChar* characters16() const { return m_impl.c_str(); }
- std::string utf8() const;
- static String16 fromUTF8(const char* stringStart, size_t length);
- static String16 fromInteger(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)
- {
- std::string str;
- str.resize(length);
- for (size_t i = 0; i < length; ++i)
- str[i] = static_cast<char>(characters[i]);
-
- const char* buffer = str.c_str();
- char* endptr;
- double result = strtod(buffer, &endptr);
- if (ok)
- *ok = buffer + length == endptr;
- return result;
- }
-
- String16 substring(unsigned pos, unsigned len = 0xFFFFFFFF) const
- {
- return String16(m_impl.substr(pos, len));
- }
-
- String16 stripWhiteSpace() const;
-
- int toInt(bool* ok = 0) const
- {
- size_t length = m_impl.length();
- std::string str;
- str.resize(length);
- for (size_t i = 0; i < length; ++i)
- str[i] = static_cast<char>(m_impl[i]);
-
- const char* buffer = str.c_str();
- char* endptr;
- int result = strtol(buffer, &endptr, 10);
- if (ok)
- *ok = buffer + length == endptr;
- return result;
- }
-
size_t length() const { return m_impl.length(); }
bool isEmpty() const { return !m_impl.length(); }
UChar operator[](unsigned index) const { return m_impl[index]; }
+ String16 substring(unsigned pos, unsigned len = 0xFFFFFFFF) const { return String16(m_impl.substr(pos, len)); }
+ size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.m_impl, start); }
+ size_t reverseFind(const String16& str, unsigned start = 0xFFFFFFFF) const { return m_impl.rfind(str.m_impl, start); }
- size_t find(UChar c, unsigned start = 0) const
- {
- return m_impl.find(c, start);
- }
-
- size_t find(const String16& str, unsigned start = 0) const
- {
- return m_impl.find(str.m_impl, start);
- }
-
- size_t reverseFind(const String16& str, unsigned start = 0xFFFFFFFF) const
- {
- 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;
- }
+ // Convenience methods.
+ std::string utf8() const;
+ static String16 fromUTF8(const char* stringStart, size_t length);
// presubmit: allow wstring
const wstring& impl() const { return m_impl; }
+ // presubmit: allow wstring
+ String16(const wstring& impl) : m_impl(impl) { }
std::size_t hash() const
pfeldman 2016/08/09 17:20:38 Could this also move out?
{
@@ -132,78 +67,12 @@ public:
}
private:
- static std::string intToString(int);
- static std::string doubleToString(double);
// presubmit: allow wstring
wstring m_impl;
mutable bool has_hash = false;
mutable std::size_t hash_code = 0;
};
-static inline bool isSpaceOrNewline(UChar c)
-{
- return std::isspace(c); // NOLINT
-}
-
-class String16Builder {
-public:
- String16Builder() { }
-
- void append(const String16& str)
- {
- m_impl += str.impl();
- }
-
- void append(UChar c)
- {
- m_impl += c;
- }
-
- void append(LChar c)
- {
- m_impl += c;
- }
-
- void append(char c)
- {
- m_impl += c;
- }
-
- void appendNumber(int i)
- {
- m_impl = m_impl + String16::fromInteger(i).impl();
- }
-
- void appendNumber(double d)
- {
- m_impl = m_impl + String16::fromDoubleFixedPrecision(d, 6).impl();
- }
-
- void append(const UChar* c, size_t length)
- {
- // presubmit: allow wstring
- m_impl += wstring(c, length);
- }
-
- void append(const char* c, size_t length)
- {
- m_impl += String16(c, length).impl();
- }
-
- String16 toString()
- {
- return String16(m_impl);
- }
-
- void reserveCapacity(unsigned newCapacity)
- {
- }
-
-private:
- // presubmit: allow wstring
- wstring m_impl;
-};
-
inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); }
pfeldman 2016/08/09 17:20:38 Same if you make base a template with pre-defined
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(); }
@@ -227,28 +96,11 @@ inline String16 operator+(const String16& a, const String16& b)
} // namespace protocol
} // namespace blink
-using String16 = blink::protocol::String16;
-using String16Builder = blink::protocol::String16Builder;
-
-
-namespace WTF {
-// Interim solution for those headers that reference WTF::String for overrides.
-// It does nothing. If the code actually relies on WTF:String, it will not
-// compile!
-// TODO(eostroukhov): Eradicate
-class String {
-public:
- String() {};
- String(const String16& other) {};
- operator String16() const { return String16(); };
-};
-} // namespace WTF
-
#if !defined(__APPLE__) || defined(_LIBCPP_VERSION)
namespace std {
-template<> struct hash<String16> {
- std::size_t operator()(const String16& string) const
+template<> struct hash<blink::protocol::String16> {
+ std::size_t operator()(const blink::protocol::String16& string) const
{
return string.hash();
}
@@ -258,6 +110,12 @@ template<> struct hash<String16> {
#endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
-using String = WTF::String;
+class InspectorProtocolConvenienceStringType {
+public:
+ // This class should not be ever instantiated, so we don't implement constructors.
kozy 2016/08/09 16:40:37 Can we make constructor private?
+ InspectorProtocolConvenienceStringType();
+ InspectorProtocolConvenienceStringType(const blink::protocol::String16& other);
+ operator blink::protocol::String16() const { return blink::protocol::String16(); };
+};
#endif // !defined(String16STL_h)

Powered by Google App Engine
This is Rietveld 408576698