Skip to content

Commit

Permalink
skipping leading whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gangatp committed Apr 30, 2024
1 parent b203943 commit 3a32a3e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Source/Common/NMR_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ namespace NMR {
__NMRASSERT(pwszValue);
nfDouble dResult = 0.0;

//skip leading whitespaces
for (; *pszValue && *pszValue == ' '; pszValue++);

// Convert to double and make a input and range check!
auto answer = fast_float::from_chars(pszValue, pszValue + strlen(pszValue), dResult);

Expand Down
10 changes: 9 additions & 1 deletion Tests/CPP_Bindings/Source/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ namespace Lib3MF

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.
// 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);
}

TEST_F(Reader, ReadVerticesValueWithLeadingTrialingSpaces) {
// This file cam-51476-test.3mf contains vertices with leading whitespaces.
// The 3MFReader allows leading/trialing whitespaces at NMR_StringUtils::fnStringToDouble when reading this file.
auto reader = model->QueryReader("3mf");
reader->ReadFromFile(sTestFilesPath + "/Reader/" + "cam_51476_test.3mf");
CheckReaderWarnings(Reader::reader3MF, 0);
}
}
Binary file added Tests/TestFiles/Reader/cam_51476_test.3mf
Binary file not shown.

0 comments on commit 3a32a3e

Please sign in to comment.