Extract new function MathLib::isDec() our of isInt()

This commit is contained in:
Alexander Mai 2014-04-11 22:15:25 +02:00
parent 6be53376f4
commit 6da6508913
2 changed files with 7 additions and 6 deletions

View File

@ -397,13 +397,8 @@ bool MathLib::isBin(const std::string& s)
return state == DIGITS; 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; enum {START, PLUSMINUS, DIGIT, SUFFIX} state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
switch (state) { switch (state) {
@ -434,6 +429,11 @@ bool MathLib::isInt(const std::string & s)
return state == DIGIT; 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) std::string MathLib::add(const std::string & first, const std::string & second)
{ {
if (MathLib::isInt(first) && MathLib::isInt(second)) { if (MathLib::isInt(first) && MathLib::isInt(second)) {

View File

@ -47,6 +47,7 @@ public:
static bool isFloat(const std::string &str); static bool isFloat(const std::string &str);
static bool isNegative(const std::string &str); static bool isNegative(const std::string &str);
static bool isPositive(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 isHex(const std::string& str);
static bool isOct(const std::string& str); static bool isOct(const std::string& str);
static bool isBin(const std::string& str); static bool isBin(const std::string& str);