From c18935d8051e89da09a9a3135d4e39d0d9ae3d79 Mon Sep 17 00:00:00 2001 From: Gilles Vollant Date: Sat, 22 Jan 2022 15:47:04 +0100 Subject: [PATCH] Fix pugixml float parsing local dependency https://github.com/zeux/pugixml/issues/469 https://github.com/troldal/OpenXLSX/issues/133 --- OpenXLSX/external/pugixml/pugixml.cpp | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/OpenXLSX/external/pugixml/pugixml.cpp b/OpenXLSX/external/pugixml/pugixml.cpp index 11733a13..62b65593 100644 --- a/OpenXLSX/external/pugixml/pugixml.cpp +++ b/OpenXLSX/external/pugixml/pugixml.cpp @@ -22,6 +22,15 @@ #include #include +#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 +#endif + #ifdef PUGIXML_WCHAR_MODE # include #endif @@ -4591,7 +4600,13 @@ class xml_buffered_writer #ifdef PUGIXML_WCHAR_MODE return wcstod(value, 0); #else + #if 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 #endif } @@ -4600,7 +4615,13 @@ class xml_buffered_writer #ifdef PUGIXML_WCHAR_MODE return static_cast(wcstod(value, 0)); #else + #if defined(PUGIXML_HAS_CXX17) + double result_double = 0.0; + std::from_chars(value, value + strlen(value), result_double); + return static_cast(result_double); + #else return static_cast(strtod(value, 0)); + #endif #endif } @@ -8415,7 +8436,13 @@ PUGI__FN double convert_string_to_number(const char_t* string) #ifdef PUGIXML_WCHAR_MODE return wcstod(string, 0); #else - return strtod(string, 0); + #if defined(PUGIXML_HAS_CXX17) + double result_double = 0.0; + std::from_chars(string, string + strlen(string), result_double); + return static_cast(result_double); + #else + return strtod(string, 0); + #endif #endif }