| 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 COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ | 5 #ifndef COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
| 6 #define COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ | 6 #define COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui_devtools { |
| 14 namespace devtools { | |
| 15 | 14 |
| 16 using String = std::string; | 15 using String = std::string; |
| 17 | 16 |
| 18 namespace protocol { | 17 namespace protocol { |
| 19 | 18 |
| 20 class Value; | 19 class Value; |
| 21 | 20 |
| 22 class CustomStringBuilder { | 21 class CustomStringBuilder { |
| 23 String s_; | 22 String s_; |
| 24 | 23 |
| 25 public: | 24 public: |
| 26 CustomStringBuilder() {} | 25 CustomStringBuilder() {} |
| 27 CustomStringBuilder(String& s) : s_(s) {} | 26 CustomStringBuilder(String& s) : s_(s) {} |
| 28 void reserveCapacity(std::size_t size) { s_.reserve(size); } | 27 void reserveCapacity(std::size_t size) { s_.reserve(size); } |
| 29 void append(const String& s) { s_ += s; } | 28 void append(const String& s) { s_ += s; } |
| 30 void append(char c) { s_ += c; } | 29 void append(char c) { s_ += c; } |
| 31 void append(const char* data, unsigned int length) { | 30 void append(const char* data, size_t length) { s_.append(data, length); } |
| 32 s_.append(data, length); | |
| 33 } | |
| 34 String toString() { return s_; } | 31 String toString() { return s_; } |
| 35 }; | 32 }; |
| 36 | 33 |
| 37 using StringBuilder = CustomStringBuilder; | 34 using StringBuilder = CustomStringBuilder; |
| 38 | 35 |
| 39 class StringUtil { | 36 class StringUtil { |
| 40 public: | 37 public: |
| 41 static String substring(const String& s, unsigned pos, unsigned len) { | 38 static String substring(const String& s, unsigned pos, unsigned len) { |
| 42 return s.substr(pos, len); | 39 return s.substr(pos, len); |
| 43 } | 40 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 69 return s.find(needle); | 66 return s.find(needle); |
| 70 } | 67 } |
| 71 static size_t find(const String& s, const String& needle) { | 68 static size_t find(const String& s, const String& needle) { |
| 72 return s.find(needle); | 69 return s.find(needle); |
| 73 } | 70 } |
| 74 static const size_t kNotFound = static_cast<size_t>(-1); | 71 static const size_t kNotFound = static_cast<size_t>(-1); |
| 75 static std::unique_ptr<Value> parseJSON(const String& string); | 72 static std::unique_ptr<Value> parseJSON(const String& string); |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 } // namespace protocol | 75 } // namespace protocol |
| 79 } // namespace devtools | 76 } // namespace ui_devtools |
| 80 } // namespace ui | |
| 81 | 77 |
| 82 #endif // COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ | 78 #endif // COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
| OLD | NEW |