diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-04 01:10:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-04 01:10:52 +0100 |
commit | f064fca059cfbab773c61893a39d34602d3616e2 (patch) | |
tree | ab7e10465277f3de6d5d1970674b7789ea52fc16 | |
parent | 730d3e0d462fcc69aaa47c30f1ed868471ce10ad (diff) | |
parent | 2c5865f60af213d7f447005e47d313e2f01373c0 (diff) |
Merge pull request #25869 from vespa-engine/balder/no-boost-spirit
No boost spirit qi
-rw-r--r-- | document/src/tests/documentselectparsertest.cpp | 1 | ||||
-rw-r--r-- | document/src/vespa/document/select/parse_utils.cpp | 47 |
2 files changed, 23 insertions, 25 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 464d3c66a7a..ce4b69419a3 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -1655,6 +1655,7 @@ TEST_F(DocumentSelectParserTest, test_parse_utilities_handle_malformed_input) // TODO double outside representable range returns Inf, but we probably would // like this to trigger a parse failure? check_parse_double("1.79769e+309", true, std::numeric_limits<double>::infinity()); + check_parse_double("-1.79769e+309", true, -std::numeric_limits<double>::infinity()); } TEST_F(DocumentSelectParserTest, imported_field_references_are_treated_as_valid_field_with_missing_value) { diff --git a/document/src/vespa/document/select/parse_utils.cpp b/document/src/vespa/document/select/parse_utils.cpp index 477b956527d..80ee4ef9dfb 100644 --- a/document/src/vespa/document/select/parse_utils.cpp +++ b/document/src/vespa/document/select/parse_utils.cpp @@ -1,37 +1,34 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "parse_utils.h" -#include <boost/spirit/include/qi.hpp> +#include <charconv> +#include <limits> namespace document::select::util { -namespace qi = boost::spirit::qi; - -// TODO replace use of Spirit.Qi with std::from_string when available. // Note: these parsers are all pure, reentrant and without locking. -bool parse_hex_i64(const char* str, size_t len, int64_t& out) { - const char* iter = str; - const char* end = str + len; - // Legacy parser parses hex numbers as u64 rather than i64 (then implicitly - // converts), so we do the same thing here to avoid change of semantics. - using u64_hex_parser = qi::uint_parser<uint64_t, 16, 1, 16>; - u64_hex_parser u64_hex; - uint64_t tmp = 0; - const bool ok = qi::parse(iter, end, u64_hex, tmp); - out = static_cast<int64_t>(tmp); - return (ok && (iter == end)); +bool +parse_hex_i64(const char* str, size_t len, int64_t& out) { + uint64_t val = out; + auto res = std::from_chars(str, str+len, val, 16); + out = val; + return (res.ec == std::errc()) && (res.ptr == str+len); } -bool parse_i64(const char* str, size_t len, int64_t& out) { - const char* iter = str; - const char* end = str + len; - const bool ok = qi::parse(iter, end, qi::long_long, out); - return (ok && (iter == end)); +bool +parse_i64(const char* str, size_t len, int64_t& out) { + auto res = std::from_chars(str, str+len, out, 10); + return (res.ec == std::errc()) && (res.ptr == str+len); } -bool parse_double(const char* str, size_t len, double& out) { - const char* iter = str; - const char* end = str + len; - const bool ok = qi::parse(iter, end, qi::double_, out); - return (ok && (iter == end)); +bool +parse_double(const char* str, size_t len, double& out) { + auto res = std::from_chars(str, str+len, out); + if (res.ec == std::errc::result_out_of_range) { + out = (str[0] == '-') + ? -std::numeric_limits<double>::infinity() + : std::numeric_limits<double>::infinity(); + return true; + } + return (res.ec == std::errc()) && (res.ptr == str+len); } } |