From cbae0d35aecf58dd3a7e2899e959b8377b15f6d6 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Thu, 11 Jan 2024 13:53:16 +0100 Subject: Add workaround for limited std::from_chars. --- searchlib/src/vespa/searchlib/query/query_term_simple.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'searchlib/src') 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 #include #include #include @@ -48,12 +49,26 @@ template 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) { + 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::infinity() : std::numeric_limits::infinity(); } *end = err.ptr; +#endif return v; } static T nearestDownwd(T n, T min) noexcept { -- cgit v1.2.3