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" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 class StringUtil { | 39 class StringUtil { |
40 public: | 40 public: |
41 static String substring(const String& s, unsigned pos, unsigned len) { | 41 static String substring(const String& s, unsigned pos, unsigned len) { |
42 return s.substr(pos, len); | 42 return s.substr(pos, len); |
43 } | 43 } |
44 static String fromInteger(int number) { return base::IntToString(number); } | 44 static String fromInteger(int number) { return base::IntToString(number); } |
45 static String fromDouble(double number) { | 45 static String fromDouble(double number) { |
46 return base::DoubleToString(number); | 46 return base::DoubleToString(number); |
47 } | 47 } |
48 static double toDouble(const char* s, size_t len, bool* ok) { | |
49 double v = 0.0; | |
50 *ok = base::StringToDouble(std::string(s, len), &v); | |
51 if (!*ok) | |
52 v = 0.0; | |
dgozman
2017/04/27 23:06:31
nit: return *ok ? v : 0.0;
kozy
2017/04/28 00:16:45
Done.
| |
53 return v; | |
54 } | |
48 static void builderAppend(StringBuilder& builder, const String& s) { | 55 static void builderAppend(StringBuilder& builder, const String& s) { |
49 builder.append(s); | 56 builder.append(s); |
50 } | 57 } |
51 static void builderAppend(StringBuilder& builder, char c) { | 58 static void builderAppend(StringBuilder& builder, char c) { |
52 builder.append(c); | 59 builder.append(c); |
53 } | 60 } |
54 static void builderAppend(StringBuilder& builder, const char* s, size_t len) { | 61 static void builderAppend(StringBuilder& builder, const char* s, size_t len) { |
55 builder.append(s, len); | 62 builder.append(s, len); |
56 } | 63 } |
57 static void builderReserve(StringBuilder& builder, unsigned capacity) { | 64 static void builderReserve(StringBuilder& builder, unsigned capacity) { |
(...skipping 10 matching lines...) Expand all Loading... | |
68 } | 75 } |
69 static const size_t kNotFound = static_cast<size_t>(-1); | 76 static const size_t kNotFound = static_cast<size_t>(-1); |
70 static std::unique_ptr<Value> parseJSON(const String& string); | 77 static std::unique_ptr<Value> parseJSON(const String& string); |
71 }; | 78 }; |
72 | 79 |
73 } // namespace protocol | 80 } // namespace protocol |
74 } // namespace devtools | 81 } // namespace devtools |
75 } // namespace ui | 82 } // namespace ui |
76 | 83 |
77 #endif // COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ | 84 #endif // COMPONENTS_UI_DEVTOOLS_STRING_UTIL_H_ |
OLD | NEW |