@@ -251,10 +251,6 @@ bool MathLib::isOct(const std::string& s)
251251
252252bool MathLib::isHex (const std::string& s)
253253{
254- // return false, in case an empty string is provided
255- if (s.empty ())
256- return false ;
257-
258254 enum {START , PLUSMINUS , HEX_PREFIX , DIGIT , DIGITS } state = START ;
259255 for (std::string::const_iterator it = s.begin (); it != s.end (); ++it) {
260256 switch (state) {
@@ -403,45 +399,39 @@ bool MathLib::isBin(const std::string& s)
403399
404400bool MathLib::isInt (const std::string & s)
405401{
406- // perform prechecks:
407- // ------------------
408- // first check, if a point is found, it is an floating point value
409- const std::string charsToIndicateAFloat=" .eE" ;
410- if (s.find_last_of (charsToIndicateAFloat) != std::string::npos)
411- return false ;
412-
413- // remember position
414- unsigned long n = 0 ;
415- // eat up whitespace
416- while (std::isspace (s[n])) ++n;
417-
418- // determine type
402+ // check for two known types: hexadecimal and octal
419403 if (isHex (s) || isOct (s)) {
420404 return true ;
421405 }
422406
423- // check sign
424- if (s[n] == ' -' || s[n] == ' +' ) ++n;
425-
426- // starts with digit
427- bool bStartsWithDigit=false ;
428- while (std::isdigit (s[n])) {
429- bStartsWithDigit=true ;
430- ++n;
407+ enum {START , PLUSMINUS , DIGIT , SUFFIX } state = START ;
408+ for (std::string::const_iterator it = s.begin (); it != s.end (); ++it) {
409+ switch (state) {
410+ case START :
411+ if (*it == ' +' || *it == ' -' )
412+ state = PLUSMINUS ;
413+ else if (isdigit (*it))
414+ state = DIGIT ;
415+ else
416+ return false ;
417+ break ;
418+ case PLUSMINUS :
419+ if (isdigit (*it))
420+ state = DIGIT ;
421+ else
422+ return false ;
423+ break ;
424+ case DIGIT :
425+ if (isdigit (*it))
426+ state = DIGIT ;
427+ else
428+ return isValidSuffix (it,s.end ());
429+ break ;
430+ case SUFFIX :
431+ break ;
432+ }
431433 }
432-
433- while (std::tolower (s[n]) == ' u' || std::tolower (s[n]) == ' l' ) ++n; // unsigned or long (long)
434-
435- if (!bStartsWithDigit)
436- return false ;
437-
438- // eat up whitespace
439- while (std::isspace (s[n]))
440- ++n;
441-
442- // if everything goes good, we are at the end of the string and no digits/character
443- // is here --> return true, but if something was found e.g. 12E+12AA return false
444- return (n >= s.length ());
434+ return state == DIGIT ;
445435}
446436
447437std::string MathLib::add (const std::string & first, const std::string & second)
0 commit comments