From 0ecf93553c5148738bbd6d58f47a0067eb98be1e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jul 2011 14:25:53 -0400 Subject: [PATCH] Nibbler - Implemented Nibbler::getN, which allows for faster extraction of compound tokens if the length is known. --- src/Nibbler.cpp | 13 +++++++++++++ src/Nibbler.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index 6dcf9557d..1e7f6b46f 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -216,6 +216,19 @@ bool Nibbler::getUntilEOS (std::string& result) return false; } +//////////////////////////////////////////////////////////////////////////////// +bool Nibbler::getN (const int quantity, std::string& result) +{ + if (mCursor + quantity < mLength) + { + result = mInput.substr (mCursor, quantity); + mCursor += quantity; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getQuoted ( char c, diff --git a/src/Nibbler.h b/src/Nibbler.h index 381eba912..ff40f3e36 100644 --- a/src/Nibbler.h +++ b/src/Nibbler.h @@ -53,6 +53,7 @@ public: bool getAllOneOf (const std::string&, std::string&); */ + bool getN (const int, std::string&); bool getQuoted (char, std::string&, bool quote = false); bool getDigit (int&); bool getInt (int&);