From 6da650891391c9c67a633bb3b5a05cc9adf83abf Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Fri, 11 Apr 2014 22:15:25 +0200 Subject: [PATCH] Extract new function MathLib::isDec() our of isInt() --- lib/mathlib.cpp | 12 ++++++------ lib/mathlib.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index bc5c76b1d..ec40a37ba 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -397,13 +397,8 @@ bool MathLib::isBin(const std::string& s) return state == DIGITS; } -bool MathLib::isInt(const std::string & s) +bool MathLib::isDec(const std::string & s) { - // check for two known types: hexadecimal and octal - if (isHex(s) || isOct(s)) { - return true; - } - enum {START, PLUSMINUS, DIGIT, SUFFIX} state = START; for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { switch (state) { @@ -434,6 +429,11 @@ bool MathLib::isInt(const std::string & s) return state == DIGIT; } +bool MathLib::isInt(const std::string & s) +{ + return isDec(s) || isHex(s) || isOct(s); +} + std::string MathLib::add(const std::string & first, const std::string & second) { if (MathLib::isInt(first) && MathLib::isInt(second)) { diff --git a/lib/mathlib.h b/lib/mathlib.h index 246baa05f..4e66f748c 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -47,6 +47,7 @@ public: static bool isFloat(const std::string &str); static bool isNegative(const std::string &str); static bool isPositive(const std::string &str); + static bool isDec(const std::string & str); static bool isHex(const std::string& str); static bool isOct(const std::string& str); static bool isBin(const std::string& str);