Pig: Added ::getDigits

This commit is contained in:
Paul Beckingham 2015-12-29 16:11:02 -05:00
parent b19496b63d
commit 5d844b9b32
2 changed files with 28 additions and 0 deletions

View file

@ -29,6 +29,7 @@
#include <Lexer.h>
#include <utf8.h>
#include <sstream>
#include <cinttypes>
////////////////////////////////////////////////////////////////////////////////
Pig::Pig (const std::string& text)
@ -71,6 +72,32 @@ bool Pig::getDigit (int& result)
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Pig::getDigits (int& result)
{
auto save = _cursor;
int c;
auto prev = _cursor;
while ((c = utf8_next_char (_text, _cursor)))
{
if (! Lexer::isDigit (c))
{
_cursor = prev;
break;
}
prev = _cursor;
}
if (_cursor > save)
{
result = std::strtoimax (_text.substr (save, _cursor - save).c_str (), NULL, 10);
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
std::string Pig::dump () const
{

View file

@ -37,6 +37,7 @@ public:
bool skipWS ();
bool getDigit (int&);
bool getDigits (int&);
std::string dump () const;