mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Pig: Added ::getDigits
This commit is contained in:
parent
b19496b63d
commit
5d844b9b32
2 changed files with 28 additions and 0 deletions
27
src/Pig.cpp
27
src/Pig.cpp
|
@ -29,6 +29,7 @@
|
||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
#include <utf8.h>
|
#include <utf8.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cinttypes>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Pig::Pig (const std::string& text)
|
Pig::Pig (const std::string& text)
|
||||||
|
@ -71,6 +72,32 @@ bool Pig::getDigit (int& result)
|
||||||
return false;
|
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
|
std::string Pig::dump () const
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
bool skipWS ();
|
bool skipWS ();
|
||||||
|
|
||||||
bool getDigit (int&);
|
bool getDigit (int&);
|
||||||
|
bool getDigits (int&);
|
||||||
|
|
||||||
std::string dump () const;
|
std::string dump () const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue