Changeset View
Changeset View
Standalone View
Standalone View
runners/calculator/calculatorrunner.cpp
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 169 | while (cmd.contains(QLatin1String("0x"))) { | |||
---|---|---|---|---|---|
182 | } | 182 | } | ||
183 | cmd = cmd.replace(pos, 2+hex.length(), QString::number(hex.toInt(&ok,16))); //replace hex with decimal | 183 | cmd = cmd.replace(pos, 2+hex.length(), QString::number(hex.toInt(&ok,16))); //replace hex with decimal | ||
184 | } | 184 | } | ||
185 | } | 185 | } | ||
186 | } | 186 | } | ||
187 | 187 | | |||
188 | void CalculatorRunner::userFriendlySubstitutions(QString& cmd) | 188 | void CalculatorRunner::userFriendlySubstitutions(QString& cmd) | ||
189 | { | 189 | { | ||
190 | if (cmd.contains(QLocale().decimalPoint(), Qt::CaseInsensitive)) { | | |||
191 | cmd.replace(QLocale().decimalPoint(), QLatin1Char('.'), Qt::CaseInsensitive); | 190 | cmd.replace(QLocale().decimalPoint(), QLatin1Char('.'), Qt::CaseInsensitive); | ||
192 | } | | |||
193 | 191 | | |||
194 | // the following substitutions are not needed with libqalculate | 192 | // the following substitutions are not needed with libqalculate | ||
195 | #ifndef ENABLE_QALCULATE | 193 | #ifndef ENABLE_QALCULATE | ||
196 | hexSubstitutions(cmd); | 194 | hexSubstitutions(cmd); | ||
197 | powSubstitutions(cmd); | 195 | powSubstitutions(cmd); | ||
198 | 196 | | |||
199 | if (cmd.contains(QRegularExpression(QStringLiteral("\\d+and\\d+")))) { | 197 | QRegularExpression re(QStringLiteral("(\\d+)and(\\d+)")); | ||
200 | cmd.replace(QRegularExpression(QStringLiteral("(\\d+)and(\\d+)")), QStringLiteral("\\1&\\2")); | 198 | cmd.replace(re, QStringLiteral("\\1&\\2")); | ||
201 | } | 199 | | ||
202 | if (cmd.contains(QRegularExpression(QStringLiteral("\\d+or\\d+")))) { | 200 | re.setPattern(QStringLiteral("(\\d+)or(\\d+)")); | ||
203 | cmd.replace(QRegularExpression(QStringLiteral("(\\d+)or(\\d+)")), QStringLiteral("\\1|\\2")); | 201 | cmd.replace(re, QStringLiteral("\\1|\\2")); | ||
204 | } | 202 | | ||
205 | if (cmd.contains(QRegularExpression(QStringLiteral("\\d+xor\\d+")))) { | 203 | re.setPattern(QStringLiteral("(\\d+)xor(\\d+)")); | ||
206 | cmd.replace(QRegularExpression(QStringLiteral("(\\d+)xor(\\d+)")), QStringLiteral("\\1^\\2")); | 204 | cmd.replace(re, QStringLiteral("\\1^\\2")); | ||
207 | } | | |||
208 | #endif | 205 | #endif | ||
209 | } | 206 | } | ||
210 | 207 | | |||
211 | 208 | | |||
212 | void CalculatorRunner::match(Plasma::RunnerContext &context) | 209 | void CalculatorRunner::match(Plasma::RunnerContext &context) | ||
213 | { | 210 | { | ||
214 | const QString term = context.query(); | 211 | const QString term = context.query(); | ||
215 | QString cmd = term; | 212 | QString cmd = term; | ||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |