Code Cleaup

- Reimplemented Nibbler::getQuoted.
- Reimplemented Nibbler::skipN.
This commit is contained in:
Paul Beckingham 2010-06-26 20:14:45 -04:00
parent f1a0b842dc
commit 05fd9278a6

View file

@ -212,22 +212,16 @@ bool Nibbler::getUntilEOS (std::string& result)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Nibbler::getQuoted (char c, std::string& result) bool Nibbler::getQuoted (char c, std::string& result)
{ {
std::string::size_type start = mCursor; std::string::size_type backup = mCursor;
if (start < mLength && mInput[start] == c)
if (skip (c) &&
getUntil (c, result) &&
skip (c))
{ {
++start; return true;
if (start < mLength)
{
std::string::size_type end = mInput.find (c, start);
if (end != std::string::npos)
{
result = mInput.substr (start, end - start);
mCursor = end + 1;
return true;
}
}
} }
mCursor = backup;
return false; return false;
} }
@ -317,10 +311,8 @@ bool Nibbler::getRx (const std::string& regex, std::string& result)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Nibbler::skipN (const int quantity /* = 1 */) bool Nibbler::skipN (const int quantity /* = 1 */)
{ {
if (mCursor >= mLength) if (mCursor < mLength &&
return false; mCursor <= mLength - quantity)
if (mCursor <= mLength - quantity)
{ {
mCursor += quantity; mCursor += quantity;
return true; return true;