Skip to content

Commit

Permalink
Falling back to strtod for non c++17 complaint platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
3dJan committed Oct 20, 2023
1 parent 74cbbd6 commit a52383a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions Source/Common/NMR_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -164,6 +192,7 @@ namespace NMR {
if ((*result.ptr != '\0') && (*result.ptr != ' '))
throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION);

#endif
return dResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ 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)
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
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)
throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES);
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)
Expand Down

0 comments on commit a52383a

Please sign in to comment.