mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Pig: Added ::getUntilWS
This commit is contained in:
parent
bc3289deb8
commit
261b0f5c22
2 changed files with 32 additions and 2 deletions
33
src/Pig.cpp
33
src/Pig.cpp
|
@ -79,7 +79,7 @@ bool Pig::skipWS ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Pig::skipLiteral (const std::string& literal)
|
bool Pig::skipLiteral (const std::string& literal)
|
||||||
{
|
{
|
||||||
if (_text.find (literal) == _cursor)
|
if (_text.find (literal, _cursor) == _cursor)
|
||||||
{
|
{
|
||||||
_cursor += literal.length ();
|
_cursor += literal.length ();
|
||||||
return true;
|
return true;
|
||||||
|
@ -88,11 +88,40 @@ bool Pig::skipLiteral (const std::string& literal)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Pig::getUntilWS (std::string& result)
|
||||||
|
{
|
||||||
|
auto save = _cursor;
|
||||||
|
|
||||||
|
int c;
|
||||||
|
auto prev = _cursor;
|
||||||
|
while ((c = utf8_next_char (_text, _cursor)))
|
||||||
|
{
|
||||||
|
if (eos ())
|
||||||
|
{
|
||||||
|
result = _text.substr (save, _cursor - save);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (Lexer::isWhitespace (c))
|
||||||
|
{
|
||||||
|
_cursor = prev;
|
||||||
|
result = _text.substr (save, _cursor - save);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = _cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _cursor > save;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Pig::getDigit (int& result)
|
bool Pig::getDigit (int& result)
|
||||||
{
|
{
|
||||||
int c = _text[_cursor];
|
int c = _text[_cursor];
|
||||||
if (Lexer::isDigit (c))
|
if (c &&
|
||||||
|
Lexer::isDigit (c))
|
||||||
{
|
{
|
||||||
result = c - '0';
|
result = c - '0';
|
||||||
++_cursor;
|
++_cursor;
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
bool skipWS ();
|
bool skipWS ();
|
||||||
bool skipLiteral (const std::string&);
|
bool skipLiteral (const std::string&);
|
||||||
|
|
||||||
|
bool getUntilWS (std::string&);
|
||||||
bool getDigit (int&);
|
bool getDigit (int&);
|
||||||
bool getDigits (int&);
|
bool getDigits (int&);
|
||||||
bool getRemainder (std::string&);
|
bool getRemainder (std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue