mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Parsing
- Implemented Nibbler::getUnsignedNumber.
This commit is contained in:
parent
22e9d84074
commit
966501f5da
2 changed files with 71 additions and 2 deletions
|
@ -365,7 +365,7 @@ bool Nibbler::getUnsignedInt (int& result)
|
|||
// int frac? exp?
|
||||
//
|
||||
// int:
|
||||
// -? digit+
|
||||
// (-|+)? digit+
|
||||
//
|
||||
// frac:
|
||||
// . digit+
|
||||
|
@ -381,7 +381,7 @@ bool Nibbler::getNumber (double& result)
|
|||
std::string::size_type i = _cursor;
|
||||
|
||||
// [+-]?
|
||||
if (i < _length && _input[i] == '-')
|
||||
if (i < _length && (_input[i] == '-' || _input[i] == '+'))
|
||||
++i;
|
||||
|
||||
// digit+
|
||||
|
@ -432,6 +432,74 @@ bool Nibbler::getNumber (double& result)
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue