Pig: Added ::skipWS

This commit is contained in:
Paul Beckingham 2015-12-29 15:38:30 -05:00
parent 26693a50b5
commit b382bcba1e
2 changed files with 28 additions and 1 deletions

View file

@ -26,18 +26,43 @@
#include <cmake.h>
#include <Pig.h>
#include <Lexer.h>
#include <utf8.h>
#include <sstream>
////////////////////////////////////////////////////////////////////////////////
Pig::Pig (const std::string& text)
: _text (text)
, _mark (std::string::npos)
, _mark (0)
, _cursor (0)
, _debug (false)
{
}
////////////////////////////////////////////////////////////////////////////////
bool Pig::skipWS ()
{
int c;
auto prev = _cursor;
while ((c = utf8_next_char (_text, _cursor)))
{
if (! Lexer::isWhitespace (c))
{
_cursor = prev;
break;
}
prev = _cursor;
}
if (_cursor > _mark)
{
_mark = _cursor;
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
void Pig::debug (bool value)
{

View file

@ -34,6 +34,8 @@ class Pig
public:
Pig (const std::string&);
bool skipWS ();
void debug (bool);
std::string dump () const;