- Implemented Nibbler::getUnsignedNumber.
This commit is contained in:
Paul Beckingham 2011-09-11 00:47:54 -04:00
parent 22e9d84074
commit 966501f5da
2 changed files with 71 additions and 2 deletions

View file

@ -365,7 +365,7 @@ bool Nibbler::getUnsignedInt (int& result)
// int frac? exp? // int frac? exp?
// //
// int: // int:
// -? digit+ // (-|+)? digit+
// //
// frac: // frac:
// . digit+ // . digit+
@ -381,7 +381,7 @@ bool Nibbler::getNumber (double& result)
std::string::size_type i = _cursor; std::string::size_type i = _cursor;
// [+-]? // [+-]?
if (i < _length && _input[i] == '-') if (i < _length && (_input[i] == '-' || _input[i] == '+'))
++i; ++i;
// digit+ // digit+
@ -432,6 +432,74 @@ bool Nibbler::getNumber (double& result)
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
// number:
// int frac? exp?
//
// int:
// digit+
//
// frac:
// . digit+
//
// exp:
// e digit+
//
// e:
// e|E (+|-)?
//
bool Nibbler::getUnsignedNumber (double& result)
{
std::string::size_type i = _cursor;
// digit+
if (i < _length && isdigit (_input[i]))
{
++i;
while (i < _length && isdigit (_input[i]))
++i;
// ( . digit+ )?
if (i < _length && _input[i] == '.')
{
++i;
while (i < _length && isdigit (_input[i]))
++i;
}
// ( [eE] [+-]? digit+ )?
if (i < _length && (_input[i] == 'e' || _input[i] == 'E'))
{
++i;
if (i < _length && (_input[i] == '+' || _input[i] == '-'))
++i;
if (i < _length && isdigit (_input[i]))
{
++i;
while (i < _length && isdigit (_input[i]))
++i;
result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL);
_cursor = i;
return true;
}
return false;
}
result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL);
_cursor = i;
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Nibbler::getLiteral (const std::string& literal) bool Nibbler::getLiteral (const std::string& literal)
{ {

View file

@ -60,6 +60,7 @@ public:
bool getHex (int&); bool getHex (int&);
bool getUnsignedInt (int&); bool getUnsignedInt (int&);
bool getNumber (double&); bool getNumber (double&);
bool getUnsignedNumber (double&);
bool getLiteral (const std::string&); bool getLiteral (const std::string&);
bool getRx (const std::string&, std::string&); bool getRx (const std::string&, std::string&);
bool getUUID (std::string&); bool getUUID (std::string&);