diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd7c36888..4693191a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./build/Test_CPP_Bindings_filtered.info - fail_ci_if_error: true # optional (default = false) + fail_ci_if_error: false # optional (default = false) verbose: true # optional (default = false) build-windows-release: diff --git a/.gitmodules b/.gitmodules index 819e6fce3..b5d5c0dbb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "submodules/googletest"] path = submodules/googletest url = https://github.com/google/googletest.git +[submodule "submodules/fast_float"] + path = submodules/fast_float + url = https://github.com/fastfloat/fast_float.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 784f9b44d..29a1be7b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,9 @@ else() endif() +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/submodules/fast_float/include) + + set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" ) # This makes sure symbols are exported target_compile_options(${PROJECT_NAME} PRIVATE "-D__LIB3MF_EXPORTS") diff --git a/Include/Common/NMR_StringUtils.h b/Include/Common/NMR_StringUtils.h index 99eb31644..b32bc76a1 100644 --- a/Include/Common/NMR_StringUtils.h +++ b/Include/Common/NMR_StringUtils.h @@ -36,6 +36,9 @@ and Exception-safe #include "Common/NMR_Types.h" #include "Common/NMR_Local.h" + +#include + #include #include #include diff --git a/Source/Common/NMR_StringUtils.cpp b/Source/Common/NMR_StringUtils.cpp index a6d37ddca..63166d6e8 100644 --- a/Source/Common/NMR_StringUtils.cpp +++ b/Source/Common/NMR_StringUtils.cpp @@ -154,17 +154,14 @@ namespace NMR { nfDouble dResult = 0.0; // Convert to double and make a input and range check! - nfChar * pEndPtr; - - dResult = strtod(pszValue, &pEndPtr); + auto answer = fast_float::from_chars(pszValue, pszValue + strlen(pszValue), dResult); // Check if any conversion happened - if ((pEndPtr == pszValue) || (!pEndPtr)) + if (answer.ec != std::errc()) + { 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); diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_TextureVertex.cpp index 3f79b9729..96c4e32d0 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); if (std::isnan (m_fU)) throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES); if (fabs (m_fU) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -95,7 +95,7 @@ namespace NMR { } if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TEXTURE_V) == 0) { - m_fV = strtof(pAttributeValue, nullptr); + m_fV = fnStringToFloat(pAttributeValue); if (std::isnan (m_fV)) throw CNMRException(NMR_ERROR_INVALIDMODELTEXTURECOORDINATES); if (fabs(m_fV) > XML_3MF_MAXIMUMCOORDINATEVALUE) diff --git a/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp b/Source/Model/Reader/v093/NMR_ModelReaderNode093_Vertex.cpp index a7502b5c2..5c8d7aeee 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); if (std::isnan (m_fX)) throw CNMRException(NMR_ERROR_INVALIDMODELCOORDINATES); if (fabs (m_fX) > XML_3MF_MAXIMUMCOORDINATEVALUE) @@ -91,7 +91,7 @@ namespace NMR { } 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) @@ -100,7 +100,7 @@ namespace NMR { } 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) 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) diff --git a/submodules/fast_float b/submodules/fast_float new file mode 160000 index 000000000..1dfad243e --- /dev/null +++ b/submodules/fast_float @@ -0,0 +1 @@ +Subproject commit 1dfad243ec42a0459a786a621be0b1f8c8a8287e