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