Pig: Added ::getUntilWS

This commit is contained in:
Paul Beckingham 2015-12-29 23:54:22 -05:00
parent bc3289deb8
commit 261b0f5c22
2 changed files with 32 additions and 2 deletions

View file

@ -79,7 +79,7 @@ bool Pig::skipWS ()
////////////////////////////////////////////////////////////////////////////////
bool Pig::skipLiteral (const std::string& literal)
{
if (_text.find (literal) == _cursor)
if (_text.find (literal, _cursor) == _cursor)
{
_cursor += literal.length ();
return true;
@ -88,11 +88,40 @@ bool Pig::skipLiteral (const std::string& literal)
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)
{
int c = _text[_cursor];
if (Lexer::isDigit (c))
if (c &&
Lexer::isDigit (c))
{
result = c - '0';
++_cursor;

View file

@ -38,6 +38,7 @@ public:
bool skipWS ();
bool skipLiteral (const std::string&);
bool getUntilWS (std::string&);
bool getDigit (int&);
bool getDigits (int&);
bool getRemainder (std::string&);