Support 0B... syntax for binary numbers.
This commit is contained in:
parent
95f4bb3e97
commit
77b5175ec3
|
@ -116,7 +116,7 @@ bool MathLib::isHex(const std::string& str)
|
|||
bool MathLib::isBin(const std::string& str)
|
||||
{
|
||||
bool sign = str[0]=='-' || str[0]=='+';
|
||||
return(str.compare(sign?1:0, 2, "0b") == 0 && str.find_first_not_of("10b", 1) == std::string::npos);
|
||||
return((str.compare(sign?1:0, 2, "0b") == 0 || str.compare(sign?1:0, 2, "0B") == 0) && str.find_first_not_of("10bB", 1) == std::string::npos);
|
||||
}
|
||||
|
||||
bool MathLib::isInt(const std::string & s)
|
||||
|
|
|
@ -171,6 +171,7 @@ private:
|
|||
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-0b1"));
|
||||
ASSERT_EQUALS(215 , MathLib::toLongNumber("0b11010111"));
|
||||
ASSERT_EQUALS(-215 , MathLib::toLongNumber("-0b11010111"));
|
||||
ASSERT_EQUALS(215 , MathLib::toLongNumber("0B11010111"));
|
||||
|
||||
// from base 10
|
||||
ASSERT_EQUALS(10 , MathLib::toLongNumber("10"));
|
||||
|
|
Loading…
Reference in New Issue