summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-11 14:45:56 +0100
committerGitHub <noreply@github.com>2024-01-11 14:45:56 +0100
commitde695ea71660d46bbbe7231034f1e5a4489d6f5f (patch)
tree6d2f5b2d17796b38ac8cd4c9c1c67772e87c035e /searchlib
parent39a20ab8d87568091ae38d5bd0299b605294f250 (diff)
parentcbae0d35aecf58dd3a7e2899e959b8377b15f6d6 (diff)
Merge pull request #29853 from vespa-engine/toregge/add-workaround-for-limited-std-from-chars
Add workaround for limited std::from_chars.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/query/query_term_simple.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/query/query_term_simple.cpp b/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
index e6cea9c752b..ab3bd512d1d 100644
--- a/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
+++ b/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
@@ -2,6 +2,7 @@
#include "query_term_simple.h"
#include "base.h"
+#include <vespa/vespalib/locale/c.h>
#include <vespa/vespalib/objects/visit.h>
#include <vespa/vespalib/util/classname.h>
#include <cmath>
@@ -48,12 +49,26 @@ template <typename T>
struct FloatDecoder {
static T fromstr(const char * q, const char * qend, const char ** end) noexcept {
T v(0);
+#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 180000
+ vespalib::string tmp(q, qend - q);
+ char* tmp_end = nullptr;
+ const char *tmp_cstring = tmp.c_str();
+ if constexpr (std::is_same_v<T, float>) {
+ v = vespalib::locale::c::strtof_au(tmp_cstring, &tmp_end);
+ } else {
+ v = vespalib::locale::c::strtod_au(tmp_cstring, &tmp_end);
+ }
+ if (end != nullptr) {
+ *end = (tmp_end != nullptr) ? (q + (tmp_end - tmp_cstring)) : nullptr;
+ }
+#else
for (;q < qend && (isspace(*q) || (*q == '+')); q++);
std::from_chars_result err = std::from_chars(q, qend, v);
if (err.ec == std::errc::result_out_of_range) {
v = (*q == '-') ? -std::numeric_limits<T>::infinity() : std::numeric_limits<T>::infinity();
}
*end = err.ptr;
+#endif
return v;
}
static T nearestDownwd(T n, T min) noexcept {