12 #include "boost/regex.hpp"
27 boost::regex number(
"[-\\.\\d]+");
28 bool debugFlag = !boost::regex_match(input, number);
29 std::string parsedString(input);
31 boost::regex squareRoot(
"sqrt\\(([\\.\\d]+)\\)");
32 boost::regex multDiv(
"([\\.\\d]+)([\\*/])([\\.\\d]+)");
34 std::stringstream replacement;
35 replacement << std::fixed << std::setprecision(20);
37 while (boost::regex_search(parsedString, match, squareRoot))
40 replacement << match.prefix() << sqrt(std::stod(match.str(1))) << match.suffix();
41 parsedString = replacement.str();
44 while (boost::regex_search(parsedString, match, multDiv))
47 replacement << match.prefix();
48 if (match.str(2) ==
"*") replacement << std::stod(match.str(1)) * std::stod(match.str(3));
49 else replacement << std::stod(match.str(1)) / std::stod(match.str(3));
50 replacement << match.suffix();
51 parsedString = replacement.str();
54 if (debugFlag) Log::log << Log::LogLevel::Debug <<
"parsed input string " << input <<
" to " << parsedString << Log::endl;
55 return std::stod(parsedString);