Extract new function MathLib::isDec() our of isInt()
This commit is contained in:
parent
6be53376f4
commit
6da6508913
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue