mirror of
https://github.com/nlohmann/json.git
synced 2026-08-02 15:32:17 +00:00
from_chars: use extended locale APIs if available
On Windows, `_strtof_l` et al. are always available. POSIX on the other hand only covers `newlocale` and `freelocale` but the extended locale functions `strtof_l` provided by glibc or `<xlocale.h>` on BSDs cannot be assumed to be universally available. For this reason, the trait `has_extended_locale_support` uses SFINAE to detect whether `strtof_l` is defined and falls back to the locale-dependent standard functions if it isn't. Signed-off-by: Jonas Greitemann <jgreitemann@gmail.com>
This commit is contained in:
@@ -39,9 +39,9 @@ constexpr init_val_t init_val{};
|
||||
template <typename T>
|
||||
void check_result(std::string& str, T& value, std::ptrdiff_t expected_ptr_offset, std::errc expected_ec)
|
||||
{
|
||||
// On platforms where `std::from_chars` is not available, our `strtof`-based implementation is
|
||||
// in fact locale-dependent and might use a different decimal separator, so we need to adapt
|
||||
// the test expectations accordingly.
|
||||
// On platforms where neither `std::from_chars`, nor extended locale support (`strtof_l`) are
|
||||
// available, the `strtof`-based implementation is in fact locale-dependent and might use a
|
||||
// different decimal separator, so we need to adapt the test expectations accordingly.
|
||||
std::replace(str.begin(), str.end(), '.', nlohmann::detail::from_chars_traits<T>::get_decimal_point());
|
||||
|
||||
auto res = nlohmann::detail::from_chars(str.data(), str.data() + str.size(), value);
|
||||
|
||||
Reference in New Issue
Block a user