aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-02-11 17:37:51 +0100
committerTor Egge <Tor.Egge@online.no>2023-02-11 17:37:51 +0100
commit3f96604c25a88f4a818e877424693ac63146c8e3 (patch)
tree186b31775bba52c78022fa914a8c90e314c59f6d /document
parent37eaedacf0426fe4b16a00a6f7874b11af809df8 (diff)
Add workaround for std::from_chars for double in libc++.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/select/parse_utils.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/document/src/vespa/document/select/parse_utils.cpp b/document/src/vespa/document/select/parse_utils.cpp
index 2e85f81f089..95461442349 100644
--- a/document/src/vespa/document/select/parse_utils.cpp
+++ b/document/src/vespa/document/select/parse_utils.cpp
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "parse_utils.h"
+#include <vespa/vespalib/locale/c.h>
#include <charconv>
#include <limits>
@@ -23,6 +24,17 @@ parse_i64(const char* str, size_t len, int64_t& out) {
}
bool
parse_double(const char* str, size_t len, double& out) {
+#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
+ // Temporary workaround that also handles underflow (cf. issue 3081)
+ // until libc++ supports std::from_chars for double
+ char *str_end = const_cast<char*>(str) + len;
+ double out0 = vespalib::locale::c::strtod_au(str, &str_end);
+ if (str_end != str + len) {
+ return false;
+ }
+ out = out0;
+ return true;
+#else
auto res = std::from_chars(str, str+len, out);
if (res.ec == std::errc::result_out_of_range) {
out = (str[0] == '-')
@@ -31,6 +43,7 @@ parse_double(const char* str, size_t len, double& out) {
return true;
}
return (res.ec == std::errc()) && (res.ptr == str+len);
+#endif
}
}