diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index bc0c5d8af..83f1b6e89 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -1077,6 +1077,18 @@ bool Nibbler::skipRx (const std::string& regex) } #endif +//////////////////////////////////////////////////////////////////////////////// +bool Nibbler::backN (const int quantity /*= 1*/) +{ + if (_cursor >= quantity) + { + _cursor -= quantity; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// void Nibbler::getRemainder (std::string& result) { diff --git a/src/Nibbler.h b/src/Nibbler.h index eeb6bf276..fa04a824f 100644 --- a/src/Nibbler.h +++ b/src/Nibbler.h @@ -93,6 +93,8 @@ public: bool skipRx (const std::string&); #endif + bool backN (const int quantity = 1); + void getRemainder (std::string&); char next (); diff --git a/test/nibbler.t.cpp b/test/nibbler.t.cpp index 68bb9431f..727b9b94a 100644 --- a/test/nibbler.t.cpp +++ b/test/nibbler.t.cpp @@ -39,15 +39,15 @@ int main (int argc, char** argv) { #ifdef NIBBLER_FEATURE_DATE #ifdef NIBBLER_FEATURE_REGEX - UnitTest t (396); + UnitTest t (402); #else - UnitTest t (372); + UnitTest t (378); #endif #else #ifdef NIBBLER_FEATURE_REGEX - UnitTest t (346); + UnitTest t (352); #else - UnitTest t (322); + UnitTest t (328); #endif #endif @@ -74,6 +74,7 @@ int main (int argc, char** argv) t.notok (n.skip ('x'), "trivial: skip"); t.notok (n.skipAll ('x'), "trivial: skipAll"); t.notok (n.skipAllOneOf ("abc"), "trivial: skipAllOneOf"); + t.notok (n.backN (1), "trivial: backN"); t.notok (n.getQuoted ('"', s), "trivial: getQuoted"); t.notok (n.getDigit (i), "trivial: getDigit"); t.notok (n.getInt (i), "trivial: getInt"); // 10 @@ -202,6 +203,15 @@ int main (int argc, char** argv) t.ok (n.depleted (), " '' : depleted () -> true"); #endif + // bool backN (const int quantity = 1); + t.diag ("Nibbler::backN"); + n = Nibbler ("/a/b/"); + t.ok (n.getQuoted ('/', s), " '/a/b/' : getQuoted ('/') -> true"); + t.is (s, "a", " 'b/' : getQuoted ('/') -> 'a'"); + t.ok (n.backN (), " 'b/' : backN () -> true"); + t.ok (n.getQuoted ('/', s), " '/b/' : getQuoted ('/') -> true"); + t.is (s, "b", " '/b/' : getQuoted ('/') -> 'b'"); + // bool getQuoted (char, std::string&); t.diag ("Nibbler::getQuoted"); n = Nibbler ("''");