summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2017-12-02 13:09:12 +0100
committerSlávek Banko <slavek.banko@axis.cz>2017-12-02 13:09:27 +0100
commitea60bbc014b6ecaa2e408c114f1b57d169aadaeb (patch)
tree5ab0dd87c14004b6145bb41cfce27080405b2576
parent792207bf14d54e25f87320fdfc42ddf4a31763c4 (diff)
downloadtdebase-ea60bbc014b6ecaa2e408c114f1b57d169aadaeb.tar.gz
tdebase-ea60bbc014b6ecaa2e408c114f1b57d169aadaeb.zip
Fix calculations in mini-cli
+ add the leading zero to the calculated results + support for calculations that starts with a negative number Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 7f55022fcfa6abe19b893889b01cfddb75fc870c)
-rw-r--r--kdesktop/minicli.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/kdesktop/minicli.cpp b/kdesktop/minicli.cpp
index 45816da08..afc28f3b0 100644
--- a/kdesktop/minicli.cpp
+++ b/kdesktop/minicli.cpp
@@ -294,7 +294,8 @@ void Minicli::clearHistory()
void Minicli::accept()
{
TQString cmd = m_dlg->cbCommand->currentText().stripWhiteSpace();
- if (!cmd.isEmpty() && (cmd[0].isNumber() || (cmd[0] == '(')) &&
+ if (!cmd.isEmpty() && (cmd[0].isNumber() || (cmd[0] == '(') ||
+ ((cmd[0] == '-') && cmd[1].isNumber())) &&
(TQRegExp("[a-zA-Z\\]\\[]").search(cmd) == -1))
{
TQString result = calculate(cmd);
@@ -1082,7 +1083,7 @@ TQString Minicli::calculate(const TQString &exp)
{
{ // scope for QTextStream
TQTextStream ts(fs, IO_ReadOnly);
- result = ts.read().stripWhiteSpace();
+ result = ts.read().stripWhiteSpace().replace( TQRegExp( "^(-?)(\\.[0-9])" ), "\\10\\2" );
}
pclose(fs);
}