Skip to content

Commit 6da6508

Browse files
committed
Extract new function MathLib::isDec() our of isInt()
1 parent 6be5337 commit 6da6508

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/mathlib.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,8 @@ bool MathLib::isBin(const std::string& s)
397397
return state == DIGITS;
398398
}
399399

400-
bool MathLib::isInt(const std::string & s)
400+
bool MathLib::isDec(const std::string & s)
401401
{
402-
// check for two known types: hexadecimal and octal
403-
if (isHex(s) || isOct(s)) {
404-
return true;
405-
}
406-
407402
enum {START, PLUSMINUS, DIGIT, SUFFIX} state = START;
408403
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
409404
switch (state) {
@@ -434,6 +429,11 @@ bool MathLib::isInt(const std::string & s)
434429
return state == DIGIT;
435430
}
436431

432+
bool MathLib::isInt(const std::string & s)
433+
{
434+
return isDec(s) || isHex(s) || isOct(s);
435+
}
436+
437437
std::string MathLib::add(const std::string & first, const std::string & second)
438438
{
439439
if (MathLib::isInt(first) && MathLib::isInt(second)) {

lib/mathlib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CPPCHECKLIB MathLib {
4747
static bool isFloat(const std::string &str);
4848
static bool isNegative(const std::string &str);
4949
static bool isPositive(const std::string &str);
50+
static bool isDec(const std::string & str);
5051
static bool isHex(const std::string& str);
5152
static bool isOct(const std::string& str);
5253
static bool isBin(const std::string& str);

0 commit comments

Comments
 (0)