aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-02-03 20:47:27 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-02-03 20:47:27 +0000
commit07ea74a57ab1b78b84c792ac2310734c19a71d8c (patch)
treec517ae9961c69f6c4ce795ce0ccbe0c27bec0566
parent1697aab52283cef8bc71530460d543ea5e2f52eb (diff)
No boost spirit qi
-rw-r--r--document/src/vespa/document/select/parse_utils.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/document/src/vespa/document/select/parse_utils.cpp b/document/src/vespa/document/select/parse_utils.cpp
index 477b956527d..90112ac9c23 100644
--- a/document/src/vespa/document/select/parse_utils.cpp
+++ b/document/src/vespa/document/select/parse_utils.cpp
@@ -1,37 +1,32 @@
// 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 = std::numeric_limits<double>::infinity();
+ return true;
+ }
+ return (res.ec == std::errc()) && (res.ptr == str+len);
}
}