| 321 | } |
| 322 | |
| 323 | QStringList ExpressionParser::getParameter(const QString& expr, const QStringList& vars) { |
| 324 | QDEBUG(Q_FUNC_INFO << ", variables:" << vars); |
| 325 | QStringList parameters; |
| 326 | |
| 327 | QStringList strings = expr.split(QRegularExpression(QStringLiteral("\\W+")), Qt::SkipEmptyParts); |
| 328 | QDEBUG(Q_FUNC_INFO << ", found strings:" << strings); |
| 329 | // RE for any number |
| 330 | const QRegularExpression re(QRegularExpression::anchoredPattern(QStringLiteral("[0-9]*"))); |
| 331 | for (const QString& string : strings) { |
| 332 | QDEBUG(string << ':' << constants().indexOf(string) << ' ' << functions().indexOf(string) << ' ' << vars.indexOf(string) << ' ' |
| 333 | << re.match(string).hasMatch()); |
| 334 | // check if token is not a known constant/function/variable or number |
| 335 | if (constants().indexOf(string) == -1 && functions().indexOf(string) == -1 && vars.indexOf(string) == -1 && re.match(string).hasMatch() == false) |
| 336 | parameters << string; |
| 337 | } |
| 338 | parameters.removeDuplicates(); |
| 339 | QDEBUG(Q_FUNC_INFO << ", parameters found:" << parameters); |
| 340 | |
| 341 | return parameters; |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Evaluate cartesian expression returning true on success and false if parsing fails |
no test coverage detected