Skip to content

Commit

Permalink
Some additional checks for the MacOS workaround for Issue beltoforion…
Browse files Browse the repository at this point in the history
  • Loading branch information
nalinigans committed Feb 28, 2023
1 parent 739fcc9 commit 46d69f9
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions parser/mpValReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,32 @@ bool DblValReader::IsValue(const char_type* a_szExpr, int& a_iPos, Value& a_Val)
if (stream.fail())
{
#ifdef __APPLE__
// Workaround for clang not parsing strings like 3i with std::stringstream(imaginary numbers)
// Workaround for MacOS/clang not parsing strings like 3i with std::stringstream
// See https://discourse.llvm.org/t/different-behavior-from-stringstream-operator-in-libc-vs-libstdc/57482
// yields 3 groups if successful. The 2nd and 3rd groups when present together as in 3i or 2n is what
// clang does differently compared to gcc and visual studio
// 1 2 3
// The regexp yields 3 groups if successful. The 2nd and 3rd groups when present together as in
// 3i or 2n is what clang does differently compared to gcc and visual studio
// GROUP: 1 2 3
std::regex pattern("(\\s*)(\\d+\\.*\\d*)(\\w+).*");
std::smatch match;
std::string str(a_szExpr+ a_iPos);
std::string str(a_szExpr + a_iPos);
if (std::regex_match(str, match, pattern) && match.size() == 4 && match[3].length() == 1)
{
float_type fVal = std::stof(match[2]);
bool is_imaginary = match[3] == "i";
if (is_imaginary)
stringstream_type stream(match[2]);
stream >> fVal;
if (!stream.fail())
{
a_Val = cmplx_type(0.0, fVal);
}
else
{
a_Val = cmplx_type(fVal, 0.0);
bool is_imaginary = (match[3] == "i");
if (is_imaginary)
{
a_Val = cmplx_type(0.0, fVal);
}
else
{
a_Val = cmplx_type(fVal, 0.0);
}
a_iPos += match[1].length()+match[2].length()+(is_imaginary?1:0);
return true;
}
a_iPos += match[1].length()+match[2].length()+(is_imaginary?1:0);
return true;
}
#endif
return false;
Expand Down

0 comments on commit 46d69f9

Please sign in to comment.