Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing fast float stod conversion according to ST_Number schema specification #339

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ file(GLOB
list(FILTER LIBS_INCLUDE EXCLUDE REGEX "zlib|libzip|libressl")
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBS_INCLUDE})

# allow FASTFLOAT_ALLOWS_LEADING_PLUS
add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Source)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include/API)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include)
Expand Down
8 changes: 7 additions & 1 deletion Source/Common/NMR_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ namespace NMR {
{
throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION);
}

else if (answer.ptr) // Invalidate comma as decimal separator
{
if (answer.ptr[0] == ',')
{
throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION);
}
}
if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL))
throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE);

Expand Down
17 changes: 17 additions & 0 deletions Tests/CPP_Bindings/Source/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,21 @@ namespace Lib3MF
auto reader = model->QueryReader("3mf");
ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "GEN-M-ADA-ITEM-TRANSFORM-0.3mf"), ELib3MFException);
}


TEST_F(Reader, ReadVerticesCommaSeparatedValue) {
// This file N_XXX_0422_01.3mf contains vertices with comma-separated values.
// The 3MFReader should throw an error at NMR_StringUtils::fnStringToDouble when reading this file because
// comma-separated values are not allowed in 3MF files.
auto reader = model->QueryReader("3mf");
ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "N_XXX_0422_01.3mf"), ELib3MFException);
}

TEST_F(Reader, ReadVerticesWithLeadingPLUSSign) {
// This file P_XXM_0519_01.3mf contains vertices with leading + sign e.g +1E+2.
// The 3MFReader allows leading = sign at NMR_StringUtils::fnStringToDouble when reading this file.
auto reader = model->QueryReader("3mf");
reader->ReadFromFile(sTestFilesPath + "/Reader/" + "P_XXM_0519_01.3mf");
CheckReaderWarnings(Reader::reader3MF, 0);
}
}
Binary file added Tests/TestFiles/Reader/N_XXX_0422_01.3mf
Binary file not shown.
Binary file added Tests/TestFiles/Reader/P_XXM_0519_01.3mf
Binary file not shown.
Loading