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 {% for namespace in config.protocol.namespace %} | 5 {% for namespace in config.protocol.namespace %} |
6 namespace {{namespace}} { | 6 namespace {{namespace}} { |
7 {% endfor %} | 7 {% endfor %} |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 std::vector<char> buffer; | 44 std::vector<char> buffer; |
45 buffer.reserve(length + 1); | 45 buffer.reserve(length + 1); |
46 for (size_t i = 0; i < length; ++i) { | 46 for (size_t i = 0; i < length; ++i) { |
47 if (!isASCII(characters[i])) { | 47 if (!isASCII(characters[i])) { |
48 *ok = false; | 48 *ok = false; |
49 return 0; | 49 return 0; |
50 } | 50 } |
51 buffer.push_back(static_cast<char>(characters[i])); | 51 buffer.push_back(static_cast<char>(characters[i])); |
52 } | 52 } |
53 buffer.push_back('\0'); | 53 buffer.push_back('\0'); |
54 char* endptr; | 54 return StringUtil::toDouble(buffer.data(), length, ok); |
55 double result = std::strtod(buffer.data(), &endptr); | |
56 *ok = !(*endptr); | |
57 return result; | |
58 } | 55 } |
59 | 56 |
60 double charactersToDouble(const uint8_t* characters, size_t length, bool* ok) | 57 double charactersToDouble(const uint8_t* characters, size_t length, bool* ok) |
61 { | 58 { |
62 std::string buffer(reinterpret_cast<const char*>(characters), length); | 59 std::string buffer(reinterpret_cast<const char*>(characters), length); |
63 char* endptr; | 60 return StringUtil::toDouble(buffer.data(), length, ok); |
64 double result = std::strtod(buffer.data(), &endptr); | |
65 *ok = !(*endptr); | |
66 return result; | |
67 } | 61 } |
68 | 62 |
69 template<typename Char> | 63 template<typename Char> |
70 bool parseConstToken(const Char* start, const Char* end, const Char** tokenEnd,
const char* token) | 64 bool parseConstToken(const Char* start, const Char* end, const Char** tokenEnd,
const char* token) |
71 { | 65 { |
72 while (start < end && *token != '\0' && *start++ == *token++) { } | 66 while (start < end && *token != '\0' && *start++ == *token++) { } |
73 if (*token != '\0') | 67 if (*token != '\0') |
74 return false; | 68 return false; |
75 *tokenEnd = start; | 69 *tokenEnd = start; |
76 return true; | 70 return true; |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 538 } |
545 | 539 |
546 std::unique_ptr<Value> parseJSONCharacters(const uint8_t* characters, unsigned l
ength) | 540 std::unique_ptr<Value> parseJSONCharacters(const uint8_t* characters, unsigned l
ength) |
547 { | 541 { |
548 return parseJSONInternal<uint8_t>(characters, length); | 542 return parseJSONInternal<uint8_t>(characters, length); |
549 } | 543 } |
550 | 544 |
551 {% for namespace in config.protocol.namespace %} | 545 {% for namespace in config.protocol.namespace %} |
552 } // namespace {{namespace}} | 546 } // namespace {{namespace}} |
553 {% endfor %} | 547 {% endfor %} |
OLD | NEW |