From 11ae6da6d9ae0642977260c9c3c08e40c911ee00 Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 6 Aug 2015 22:35:56 +0200 Subject: [PATCH] =?UTF-8?q?reverted=20=E2=80=9Cfix=E2=80=9D=20for=20issue?= =?UTF-8?q?=20#107?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json.hpp | 17 ++++++++--------- src/json.hpp.re2c | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 2f48639ff..79df1f782 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -49,7 +49,6 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation. #include #include #include -#include #include #include #include @@ -6933,18 +6932,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 { - long double f = NAN; - std::stringstream ss(get_token()); - ss.imbue(std::locale("C")); - ss >> f; - return f; + // 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; } private: diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 708124e33..585aa2056 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -49,7 +49,6 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation. #include #include #include -#include #include #include #include @@ -6239,18 +6238,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 { - long double f = NAN; - std::stringstream ss(get_token()); - ss.imbue(std::locale("C")); - ss >> f; - return f; + // 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; } private: