OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
| 6 #define COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/json/json_reader.h" |
| 11 #include "base/strings/string_number_conversions.h" |
| 12 |
| 13 namespace ui { |
| 14 namespace devtools { |
| 15 |
| 16 using String = std::string; |
| 17 |
| 18 namespace protocol { |
| 19 |
| 20 class Value; |
| 21 |
| 22 std::unique_ptr<Value> parseJSON(const String& string); |
| 23 |
| 24 class CustomStringBuilder { |
| 25 String s_; |
| 26 |
| 27 public: |
| 28 CustomStringBuilder() {} |
| 29 CustomStringBuilder(String& s) : s_(s) {} |
| 30 void reserveCapacity(std::size_t size) { s_.reserve(size); } |
| 31 void append(const String& s) { s_ += s; } |
| 32 void append(char c) { s_ += c; } |
| 33 void append(const char* data, unsigned int length) { |
| 34 s_.append(data, length); |
| 35 } |
| 36 String toString() { return s_; } |
| 37 }; |
| 38 |
| 39 using StringBuilder = CustomStringBuilder; |
| 40 |
| 41 class StringUtil { |
| 42 public: |
| 43 static String substring(const String& s, unsigned pos, unsigned len) { |
| 44 return s.substr(pos, len); |
| 45 } |
| 46 static String fromInteger(int number) { return base::IntToString(number); } |
| 47 static String fromDouble(double number) { |
| 48 return base::DoubleToString(number); |
| 49 } |
| 50 static void builderReserve(StringBuilder& builder, unsigned capacity) { |
| 51 builder.reserveCapacity(capacity); |
| 52 } |
| 53 static const size_t kNotFound = static_cast<size_t>(-1); |
| 54 }; |
| 55 |
| 56 } // namespace protocol |
| 57 } // namespace devtools |
| 58 } // namespace ui |
| 59 |
| 60 #endif // COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
OLD | NEW |