- Implemented Nibbler::getName to parse an alpha-numeric name.
- Added appropriate unit tests.
This commit is contained in:
Paul Beckingham 2011-07-24 01:00:24 -04:00
parent 91225d808f
commit 3fd83ca400
3 changed files with 55 additions and 1 deletions

View file

@ -987,6 +987,36 @@ bool Nibbler::getDOM (std::string& result)
return false;
}
////////////////////////////////////////////////////////////////////////////////
// A name is a string of alpha-numeric characters.
bool Nibbler::getName (std::string& result)
{
std::string::size_type i = mCursor;
if (i < mLength)
{
if (isalpha (mInput[i]))
{
++i;
while (i < mLength &&
(isalpha (mInput[i]) ||
isdigit (mInput[i])))
{
++i;
}
}
if (i > mCursor)
{
result = mInput.substr (mCursor, i - mCursor);
mCursor = i;
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// A word is a contiguous string of non-space, non-digit, non-punct characters.
bool Nibbler::getWord (std::string& result)

View file

@ -66,6 +66,7 @@ public:
bool getDate (const std::string&, time_t&);
bool getOneOf (const std::vector <std::string>&, std::string&);
bool getDOM (std::string&);
bool getName (std::string&);
bool getWord (std::string&);
bool skipN (const int quantity = 1);