From a52383af1a26be34f4dfafa5c926f3925aeb616c Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:59:13 +0200 Subject: [PATCH] Falling back to strtod for non c++17 complaint platforms --- .github/workflows/build.yml | 8 ++--- Source/Common/NMR_StringUtils.cpp | 29 +++++++++++++++++++ .../NMR_ModelReaderNode093_TextureVertex.cpp | 4 +-- .../v093/NMR_ModelReaderNode093_Vertex.cpp | 6 ++-- .../v100/NMR_ModelReaderNode100_Vertex.cpp | 6 ++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9da09d802..46b119e03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,7 +90,7 @@ jobs: name: lib3mf.lib path: build/Release/lib3mf.lib build-windows-debug: - runs-on: windows-latest + runs-on: windows-2019 steps: - uses: actions/checkout@v2 with: @@ -106,7 +106,7 @@ jobs: name: lib3mf.debug.dll path: build/Debug/lib3mf.dll build-windows-32bit: - runs-on: windows-latest + runs-on: windows-2019 steps: - uses: actions/checkout@v2 with: @@ -127,7 +127,7 @@ jobs: name: lib3mf_32bit.lib path: build_32bit/Release/lib3mf.lib build-mingw-w64: - runs-on: windows-latest + runs-on: windows-2019 steps: - run: choco install mingw -y - uses: actions/checkout@v2 @@ -189,7 +189,7 @@ jobs: cmake --build . ./Example_ExtractInfo ../../Files/Helix.3mf deploy-windows: - runs-on: windows-latest + runs-on: windows-2019 needs: [assemble-sdk] steps: - name: Download lib3mf_sdk artifact diff --git a/Source/Common/NMR_StringUtils.cpp b/Source/Common/NMR_StringUtils.cpp index 56aa5783c..022491aad 100644 --- a/Source/Common/NMR_StringUtils.cpp +++ b/Source/Common/NMR_StringUtils.cpp @@ -153,7 +153,35 @@ namespace NMR { { __NMRASSERT(pszValue); nfDouble dResult = 0.0; +#ifdef __APPLE__ + #define __NO_FROM_CHARS_FP__ +#endif + +//mingw +#ifdef __MINGW32__ + #define __NO_FROM_CHARS_FP__ +#endif + +#ifdef __MINGW64__ + #define __NO_FROM_CHARS_FP__ +#endif + +#ifdef __NO_FROM_CHARS_FP__ + // Convert to double and make a input and range check! + nfChar * pEndPtr; + + dResult = strtod(pszValue, &pEndPtr); + // Check if any conversion happened + if ((pEndPtr == pszValue) || (!pEndPtr)) + throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION); + + if ((*pEndPtr != '\0') && (*pEndPtr != ' ')) + throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION); + + if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL)) + throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE); +#else // Convert to double and make a input and range check! std::from_chars_result result = std::from_chars(pszValue, pszValue + strlen(pszValue), dResult, std::chars_format::general); @@ -164,6 +192,7 @@ namespace NMR { if ((*result.ptr != '\0') && (*result.ptr != ' ')) throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION); +#endif return dResult; } diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp index b4a253ff0..b18f86334 100644 --- a/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp +++ b/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp @@ -86,7 +86,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_U) == 0) { - m_fU = strtof(pAttributeValue, nullptr); + m_fU = fnStringToFloat(pAttributeValue); #ifdef __MINGW32__ if (isNotANumber(m_fU)) #else @@ -99,7 +99,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_V) == 0) { - m_fV = strtof(pAttributeValue, nullptr); + m_fV = fnStringToFloat(pAttributeValue); #ifdef __MINGW32__ if (isNotANumber(m_fV)) #else diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp index b1a3f0439..3828b35d4 100644 --- a/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp +++ b/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp @@ -82,7 +82,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) { - m_fX = strtof(pAttributeValue, nullptr); + m_fX = fnStringToFloat(pAttributeValue); #ifdef __MINGW32__ if (isNotANumber(m_fX)) #else @@ -95,7 +95,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) { - m_fY = strtof(pAttributeValue, nullptr); + m_fY = fnStringToFloat(pAttributeValue); #ifdef __MINGW32__ if (isNotANumber(m_fY)) #else @@ -108,7 +108,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) { - m_fZ = strtof(pAttributeValue, nullptr); + m_fZ = fnStringToFloat(pAttributeValue); #ifdef __MINGW32__ if (isNotANumber(m_fZ)) #else diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp index 797e782e6..a2cc72984 100644 --- a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp @@ -82,7 +82,7 @@ namespace NMR { __NMRASSERT(pAttributeValue); if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_X) == 0) { - m_fX = strtof(pAttributeValue, nullptr); + m_fX = fnStringToFloat(pAttributeValue); if (std::isnan (m_fX)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -90,7 +90,7 @@ namespace NMR { m_bHasX = true; } else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Y) == 0) { - m_fY = strtof(pAttributeValue, nullptr); + m_fY = fnStringToFloat(pAttributeValue); if (std::isnan (m_fY)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fY) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -98,7 +98,7 @@ namespace NMR { m_bHasY = true; } else if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_VERTEX_Z) == 0) { - m_fZ = strtof(pAttributeValue, nullptr); + m_fZ = fnStringToFloat(pAttributeValue); if (std::isnan (m_fZ)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs(m_fZ) > XML_3MF_MAXIMUMCOORDINATEVALUE)