mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Pig: Added ::getNumber
This commit is contained in:
parent
b81fab4f32
commit
dacff48165
2 changed files with 80 additions and 0 deletions
79
src/Pig.cpp
79
src/Pig.cpp
|
@ -157,6 +157,85 @@ bool Pig::getDigits (int& result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// number:
|
||||||
|
// int frac? exp?
|
||||||
|
//
|
||||||
|
// int:
|
||||||
|
// (-|+)? digit+
|
||||||
|
//
|
||||||
|
// frac:
|
||||||
|
// . digit+
|
||||||
|
//
|
||||||
|
// exp:
|
||||||
|
// e digit+
|
||||||
|
//
|
||||||
|
// e:
|
||||||
|
// e|E (+|-)?
|
||||||
|
//
|
||||||
|
bool Pig::getNumber (std::string& result)
|
||||||
|
{
|
||||||
|
auto i = _cursor;
|
||||||
|
|
||||||
|
// [+-]?
|
||||||
|
if (_text[i] &&
|
||||||
|
(_text[i] == '-' ||
|
||||||
|
_text[i] == '+'))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
// digit+
|
||||||
|
if (_text[i] &&
|
||||||
|
Lexer::isDigit (_text[i]))
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
|
||||||
|
while (_text[i] && Lexer::isDigit (_text[i]))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
// ( . digit+ )?
|
||||||
|
if (_text[i] && _text[i] == '.')
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
|
||||||
|
while (_text[i] && Lexer::isDigit (_text[i]))
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ( [eE] [+-]? digit+ )?
|
||||||
|
if (_text[i] &&
|
||||||
|
(_text[i] == 'e' ||
|
||||||
|
_text[i] == 'E'))
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
|
||||||
|
if (_text[i] &&
|
||||||
|
(_text[i] == '+' ||
|
||||||
|
_text[i] == '-'))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
if (_text[i] && Lexer::isDigit (_text[i]))
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
|
||||||
|
while (_text[i] && Lexer::isDigit (_text[i]))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
result = _text.substr (_cursor, i - _cursor);
|
||||||
|
_cursor = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = _text.substr (_cursor, i - _cursor);
|
||||||
|
_cursor = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Pig::getRemainder (std::string& result)
|
bool Pig::getRemainder (std::string& result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
bool getUntilWS (std::string&);
|
bool getUntilWS (std::string&);
|
||||||
bool getDigit (int&);
|
bool getDigit (int&);
|
||||||
bool getDigits (int&);
|
bool getDigits (int&);
|
||||||
|
bool getNumber (std::string&);
|
||||||
bool getRemainder (std::string&);
|
bool getRemainder (std::string&);
|
||||||
|
|
||||||
bool eos () const;
|
bool eos () const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue