mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-24 18:06:42 +02:00
Nibbler::backN
- Added a method to support multi-byte backstep through a string. - Added unit tests.
This commit is contained in:
parent
2281c5a6bf
commit
663c82837c
3 changed files with 28 additions and 4 deletions
|
@ -1077,6 +1077,18 @@ bool Nibbler::skipRx (const std::string& regex)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Nibbler::backN (const int quantity /*= 1*/)
|
||||||
|
{
|
||||||
|
if (_cursor >= quantity)
|
||||||
|
{
|
||||||
|
_cursor -= quantity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Nibbler::getRemainder (std::string& result)
|
void Nibbler::getRemainder (std::string& result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,6 +93,8 @@ public:
|
||||||
bool skipRx (const std::string&);
|
bool skipRx (const std::string&);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool backN (const int quantity = 1);
|
||||||
|
|
||||||
void getRemainder (std::string&);
|
void getRemainder (std::string&);
|
||||||
|
|
||||||
char next ();
|
char next ();
|
||||||
|
|
|
@ -39,15 +39,15 @@ int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
#ifdef NIBBLER_FEATURE_DATE
|
#ifdef NIBBLER_FEATURE_DATE
|
||||||
#ifdef NIBBLER_FEATURE_REGEX
|
#ifdef NIBBLER_FEATURE_REGEX
|
||||||
UnitTest t (396);
|
UnitTest t (402);
|
||||||
#else
|
#else
|
||||||
UnitTest t (372);
|
UnitTest t (378);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifdef NIBBLER_FEATURE_REGEX
|
#ifdef NIBBLER_FEATURE_REGEX
|
||||||
UnitTest t (346);
|
UnitTest t (352);
|
||||||
#else
|
#else
|
||||||
UnitTest t (322);
|
UnitTest t (328);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ int main (int argc, char** argv)
|
||||||
t.notok (n.skip ('x'), "trivial: skip");
|
t.notok (n.skip ('x'), "trivial: skip");
|
||||||
t.notok (n.skipAll ('x'), "trivial: skipAll");
|
t.notok (n.skipAll ('x'), "trivial: skipAll");
|
||||||
t.notok (n.skipAllOneOf ("abc"), "trivial: skipAllOneOf");
|
t.notok (n.skipAllOneOf ("abc"), "trivial: skipAllOneOf");
|
||||||
|
t.notok (n.backN (1), "trivial: backN");
|
||||||
t.notok (n.getQuoted ('"', s), "trivial: getQuoted");
|
t.notok (n.getQuoted ('"', s), "trivial: getQuoted");
|
||||||
t.notok (n.getDigit (i), "trivial: getDigit");
|
t.notok (n.getDigit (i), "trivial: getDigit");
|
||||||
t.notok (n.getInt (i), "trivial: getInt"); // 10
|
t.notok (n.getInt (i), "trivial: getInt"); // 10
|
||||||
|
@ -202,6 +203,15 @@ int main (int argc, char** argv)
|
||||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||||
#endif
|
#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&);
|
// bool getQuoted (char, std::string&);
|
||||||
t.diag ("Nibbler::getQuoted");
|
t.diag ("Nibbler::getQuoted");
|
||||||
n = Nibbler ("''");
|
n = Nibbler ("''");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue