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 WS_STRINGUTIL_H_ |
| 6 #define WS_STRINGUTIL_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() : s_("") {} |
| 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*, unsigned int length) { return; } |
| 34 String toString() { return s_; } |
| 35 }; |
| 36 |
| 37 using StringBuilder = CustomStringBuilder; |
| 38 |
| 39 class StringUtil { |
| 40 public: |
| 41 static String substring(const String& s, unsigned pos, unsigned len) { |
| 42 return s.substr(pos, len); |
| 43 } |
| 44 static String fromInteger(int number) { return base::IntToString(number); } |
| 45 static String fromDouble(double number) { |
| 46 return base::DoubleToString(number); |
| 47 } |
| 48 static void builderReserve(StringBuilder& builder, unsigned capacity) { |
| 49 builder.reserveCapacity(capacity); |
| 50 } |
| 51 static const size_t kNotFound = -1; |
| 52 }; |
| 53 |
| 54 } // namespace protocol |
| 55 } // namespace devtools |
| 56 } // namespace ui |
| 57 |
| 58 #endif // WS_STRINGUTIL_H_ |
OLD | NEW |