This commit is contained in:
Gilles Vollant 2023-03-29 23:09:17 -07:00 committed by GitHub
commit 7755967270
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,16 @@
// For placement new // For placement new
#include <new> #include <new>
// c++17 and more detection for std::from_chars
#if (!defined(PUGIXML_HAS_CXX17)) && ((__cplusplus >= 201703L) || \
(defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L))
# define PUGIXML_HAS_CXX17
#endif
#if defined(PUGIXML_HAS_CXX17)
# include <charconv>
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) # pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4127) // conditional expression is constant
@ -4611,6 +4621,10 @@ PUGI_IMPL_NS_BEGIN
{ {
#ifdef PUGIXML_WCHAR_MODE #ifdef PUGIXML_WCHAR_MODE
return wcstod(value, 0); return wcstod(value, 0);
#elif defined(PUGIXML_HAS_CXX17)
double result_double = 0.0;
std::from_chars(value, (value + strlen(value)), result_double);
return result_double;
#else #else
return strtod(value, 0); return strtod(value, 0);
#endif #endif
@ -4620,6 +4634,10 @@ PUGI_IMPL_NS_BEGIN
{ {
#ifdef PUGIXML_WCHAR_MODE #ifdef PUGIXML_WCHAR_MODE
return static_cast<float>(wcstod(value, 0)); return static_cast<float>(wcstod(value, 0));
#elif defined(PUGIXML_HAS_CXX17)
double result_double = 0.0;
std::from_chars(value, value + strlen(value), result_double);
return static_cast<float>(result_double);
#else #else
return static_cast<float>(strtod(value, 0)); return static_cast<float>(strtod(value, 0));
#endif #endif
@ -8554,6 +8572,10 @@ PUGI_IMPL_NS_BEGIN
// parse string // parse string
#ifdef PUGIXML_WCHAR_MODE #ifdef PUGIXML_WCHAR_MODE
return wcstod(string, 0); return wcstod(string, 0);
#elif defined(PUGIXML_HAS_CXX17)
double result_double = 0.0;
std::from_chars(string, string + strlen(string), result_double);
return static_cast<float>(result_double);
#else #else
return strtod(string, 0); return strtod(string, 0);
#endif #endif