From ddbf675d40f89d23d96dfe5ca2af2f860f298407 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 29 Dec 2015 15:53:51 -0500 Subject: [PATCH] Pig: Added ::getDigit --- src/Pig.cpp | 15 +++++++++++++++ src/Pig.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/Pig.cpp b/src/Pig.cpp index 8c4e9931..6fb93942 100644 --- a/src/Pig.cpp +++ b/src/Pig.cpp @@ -63,6 +63,21 @@ bool Pig::skipWS () return false; } +//////////////////////////////////////////////////////////////////////////////// +bool Pig::getDigit (int& result) +{ + int c = _text[_cursor]; + if (Lexer::isDigit (c)) + { + result = c - '0'; + ++_cursor; + ++_mark; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// void Pig::debug (bool value) { diff --git a/src/Pig.h b/src/Pig.h index 1527fb83..67bf6472 100644 --- a/src/Pig.h +++ b/src/Pig.h @@ -36,6 +36,8 @@ public: bool skipWS (); + bool getDigit (int&); + void debug (bool); std::string dump () const;