Commit cd37cc69 authored by Ahmad Samir's avatar Ahmad Samir

[Calculator Runner] Minor code optimisation

Summary:
Remove redunant QString::contains() checks.

Create one QRegularExpression object and use setPattern().

Test Plan: make && ctest

Reviewers: #plasma, apol, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28132
parent f444ebe5
......@@ -187,25 +187,22 @@ void CalculatorRunner::hexSubstitutions(QString& cmd)
void CalculatorRunner::userFriendlySubstitutions(QString& cmd)
{
if (cmd.contains(QLocale().decimalPoint(), Qt::CaseInsensitive)) {
cmd.replace(QLocale().decimalPoint(), QLatin1Char('.'), Qt::CaseInsensitive);
}
cmd.replace(QLocale().decimalPoint(), QLatin1Char('.'), Qt::CaseInsensitive);
// the following substitutions are not needed with libqalculate
#ifndef ENABLE_QALCULATE
#ifndef ENABLE_QALCULATE
hexSubstitutions(cmd);
powSubstitutions(cmd);
if (cmd.contains(QRegularExpression(QStringLiteral("\\d+and\\d+")))) {
cmd.replace(QRegularExpression(QStringLiteral("(\\d+)and(\\d+)")), QStringLiteral("\\1&\\2"));
}
if (cmd.contains(QRegularExpression(QStringLiteral("\\d+or\\d+")))) {
cmd.replace(QRegularExpression(QStringLiteral("(\\d+)or(\\d+)")), QStringLiteral("\\1|\\2"));
}
if (cmd.contains(QRegularExpression(QStringLiteral("\\d+xor\\d+")))) {
cmd.replace(QRegularExpression(QStringLiteral("(\\d+)xor(\\d+)")), QStringLiteral("\\1^\\2"));
}
#endif
QRegularExpression re(QStringLiteral("(\\d+)and(\\d+)"));
cmd.replace(re, QStringLiteral("\\1&\\2"));
re.setPattern(QStringLiteral("(\\d+)or(\\d+)"));
cmd.replace(re, QStringLiteral("\\1|\\2"));
re.setPattern(QStringLiteral("(\\d+)xor(\\d+)"));
cmd.replace(re, QStringLiteral("\\1^\\2"));
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment