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 #include <cstdlib> | 5 #include <cstdlib> |
6 #include <cstring> | 6 #include <cstring> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 namespace protocol { | 10 namespace protocol { |
(...skipping 13 matching lines...) Expand all Loading... |
24 void doubleToStr3(double number, char* buffer, size_t length) | 24 void doubleToStr3(double number, char* buffer, size_t length) |
25 { | 25 { |
26 std::snprintf(buffer, length, "%.3g", number); | 26 std::snprintf(buffer, length, "%.3g", number); |
27 } | 27 } |
28 | 28 |
29 void doubleToStr6(double number, char* buffer, size_t length) | 29 void doubleToStr6(double number, char* buffer, size_t length) |
30 { | 30 { |
31 std::snprintf(buffer, length, "%.6g", number); | 31 std::snprintf(buffer, length, "%.6g", number); |
32 } | 32 } |
33 | 33 |
34 double strToDouble(const char* buffer, bool* ok) | |
35 { | |
36 char* endptr; | |
37 double result = std::strtod(buffer, &endptr); | |
38 if (ok) | |
39 *ok = !(*endptr); | |
40 return result; | |
41 } | |
42 | |
43 int strToInt(const char* buffer, bool* ok) | 34 int strToInt(const char* buffer, bool* ok) |
44 { | 35 { |
45 char* endptr; | 36 char* endptr; |
46 int result = std::strtol(buffer, &endptr, 10); | 37 int result = std::strtol(buffer, &endptr, 10); |
47 if (ok) | 38 if (ok) |
48 *ok = !(*endptr); | 39 *ok = !(*endptr); |
49 return result; | 40 return result; |
50 } | 41 } |
51 | 42 |
52 } // namespace internal | 43 } // namespace internal |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return String16(m_buffer.data(), m_buffer.size()); | 81 return String16(m_buffer.data(), m_buffer.size()); |
91 } | 82 } |
92 | 83 |
93 void String16Builder::reserveCapacity(size_t capacity) | 84 void String16Builder::reserveCapacity(size_t capacity) |
94 { | 85 { |
95 m_buffer.reserve(capacity); | 86 m_buffer.reserve(capacity); |
96 } | 87 } |
97 | 88 |
98 } // namespace protocol | 89 } // namespace protocol |
99 } // namespace blink | 90 } // namespace blink |
OLD | NEW |