mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Nibbler
- Implemented Nibbler::getName to parse an alpha-numeric name. - Added appropriate unit tests.
This commit is contained in:
parent
91225d808f
commit
3fd83ca400
3 changed files with 55 additions and 1 deletions
|
@ -987,6 +987,36 @@ bool Nibbler::getDOM (std::string& result)
|
||||||
return false;
|
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.
|
// A word is a contiguous string of non-space, non-digit, non-punct characters.
|
||||||
bool Nibbler::getWord (std::string& result)
|
bool Nibbler::getWord (std::string& result)
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
bool getDate (const std::string&, time_t&);
|
bool getDate (const std::string&, time_t&);
|
||||||
bool getOneOf (const std::vector <std::string>&, std::string&);
|
bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||||
bool getDOM (std::string&);
|
bool getDOM (std::string&);
|
||||||
|
bool getName (std::string&);
|
||||||
bool getWord (std::string&);
|
bool getWord (std::string&);
|
||||||
|
|
||||||
bool skipN (const int quantity = 1);
|
bool skipN (const int quantity = 1);
|
||||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (277);
|
UnitTest t (292);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -439,6 +439,29 @@ int main (int argc, char** argv)
|
||||||
n = Nibbler ("..foo ");
|
n = Nibbler ("..foo ");
|
||||||
t.notok (n.getDOM (s), "'..foo' getDOM -> notok");
|
t.notok (n.getDOM (s), "'..foo' getDOM -> notok");
|
||||||
|
|
||||||
|
// bool getName (std::string&);
|
||||||
|
t.diag ("Nibbler::getName");
|
||||||
|
n = Nibbler ("a1 one one.two 9");
|
||||||
|
t.ok (n.getName (s), "'a1 one one.two 9' getName -> ok");
|
||||||
|
t.is (s, "a1", " ' one one.two 9' getName -> 'a1'");
|
||||||
|
t.ok (n.skipWS (), " 'one one.two 9' skipWS -> ok");
|
||||||
|
|
||||||
|
t.ok (n.getName (s), " 'one one.two 9' getName -> ok");
|
||||||
|
t.is (s, "one", " ' one.two 9' getName -> 'one'");
|
||||||
|
t.ok (n.skipWS (), " 'one.two 9' skipWS -> ok");
|
||||||
|
|
||||||
|
t.ok (n.getName (s), " 'one.two 9' getName -> ok");
|
||||||
|
t.is (s, "one", " '.two 9' getName -> 'one'");
|
||||||
|
t.ok (n.skip ('.'), " 'two 9' skip . -> ok");
|
||||||
|
|
||||||
|
t.ok (n.getName (s), " 'two 9' getName -> ok");
|
||||||
|
t.is (s, "two", " ' 9' getName -> 'two'");
|
||||||
|
t.ok (n.skipWS (), " '9' skipWS -> ok");
|
||||||
|
|
||||||
|
t.notok (n.getName (s), " '9' getName -> not ok");
|
||||||
|
t.ok (n.skip ('9'), " '' skip 9 -> ok");
|
||||||
|
t.ok (n.depleted (), "depleted");
|
||||||
|
|
||||||
// bool getWord (std::string&);
|
// bool getWord (std::string&);
|
||||||
t.diag ("Nibbler::getWord");
|
t.diag ("Nibbler::getWord");
|
||||||
n = Nibbler ("one two th3ee");
|
n = Nibbler ("one two th3ee");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue