From 2c3259320d12006ea4be644e86475455625e7003 Mon Sep 17 00:00:00 2001 From: Niels Date: Tue, 4 Aug 2015 18:12:11 +0200 Subject: [PATCH] addressed locale-issues #107 --- src/json.hpp | 17 +++++++++-------- src/json.hpp.re2c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 79df1f78..2f48639f 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -49,6 +49,7 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation. #include #include #include +#include #include #include #include @@ -6932,18 +6933,18 @@ basic_json_parser_59: read past the current token. The latter case needs to be treated by the caller function. + @note This function is locale-independent, see + http://stackoverflow.com/a/1333899/266378 + @throw std::range_error if passed value is out of range */ long double get_number() const { - // conversion - typename string_t::value_type* endptr; - const auto float_val = std::strtold(reinterpret_cast(m_start), - &endptr); - - // return float_val if the whole number was translated and NAN - // otherwise - return (reinterpret_cast(endptr) == m_cursor) ? float_val : NAN; + long double f = NAN; + std::stringstream ss(get_token()); + ss.imbue(std::locale("C")); + ss >> f; + return f; } private: diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 585aa205..708124e3 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -49,6 +49,7 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation. #include #include #include +#include #include #include #include @@ -6238,18 +6239,18 @@ class basic_json read past the current token. The latter case needs to be treated by the caller function. + @note This function is locale-independent, see + http://stackoverflow.com/a/1333899/266378 + @throw std::range_error if passed value is out of range */ long double get_number() const { - // conversion - typename string_t::value_type* endptr; - const auto float_val = std::strtold(reinterpret_cast(m_start), - &endptr); - - // return float_val if the whole number was translated and NAN - // otherwise - return (reinterpret_cast(endptr) == m_cursor) ? float_val : NAN; + long double f = NAN; + std::stringstream ss(get_token()); + ss.imbue(std::locale("C")); + ss >> f; + return f; } private: