Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
// For placement 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
# pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant
Expand Down Expand Up @@ -4591,6 +4601,10 @@ PUGI__NS_BEGIN
{
#ifdef PUGIXML_WCHAR_MODE
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
return strtod(value, 0);
#endif
Expand All @@ -4600,6 +4614,10 @@ PUGI__NS_BEGIN
{
#ifdef PUGIXML_WCHAR_MODE
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
return static_cast<float>(strtod(value, 0));
#endif
Expand Down Expand Up @@ -8419,6 +8437,10 @@ PUGI__NS_BEGIN
// parse string
#ifdef PUGIXML_WCHAR_MODE
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
return strtod(string, 0);
#endif
Expand Down