mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Sequence integration
- Sequence object fully integrated.
This commit is contained in:
parent
7965bd5b4f
commit
9b78631e6f
6 changed files with 44 additions and 30 deletions
|
@ -259,25 +259,15 @@ void Context::parse ()
|
|||
|
||||
// Sequence
|
||||
// Note: "add" doesn't require an ID
|
||||
else if (command != "add" &&
|
||||
validSequence (*arg, sequence) &&
|
||||
else if (command != "add" &&
|
||||
sequence.valid (*arg) &&
|
||||
! foundSomethingAfterSequence)
|
||||
{
|
||||
std::cout << "# found sequence" << std::endl;
|
||||
sequence.parse (*arg);
|
||||
foundSequence = true;
|
||||
}
|
||||
|
||||
/*
|
||||
else if (lowerCase (command) != "add" && // "add" doesn't require an ID
|
||||
validSequence (arg, sequence) &&
|
||||
! foundSomethingAfterSequence)
|
||||
{
|
||||
foundSequence = true;
|
||||
foreach (id, sequence)
|
||||
task.addId (*id);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Tags begin with + or - and contain arbitrary text.
|
||||
else if (validTag (arg))
|
||||
|
|
|
@ -53,6 +53,26 @@ Sequence::~Sequence ()
|
|||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Sequence::valid (const std::string& input) const
|
||||
{
|
||||
std::vector <std::string> ranges;
|
||||
split (ranges, input, ',');
|
||||
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = ranges.begin (); it != ranges.end (); ++it)
|
||||
{
|
||||
std::vector <std::string> range;
|
||||
split (range, *it, '-');
|
||||
|
||||
if (range.size () < 1 ||
|
||||
range.size () > 2)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Sequence::parse (const std::string& input)
|
||||
{
|
||||
|
@ -121,7 +141,7 @@ void Sequence::combine (const Sequence& other)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Sequence::validId (const std::string& input)
|
||||
bool Sequence::validId (const std::string& input) const
|
||||
{
|
||||
if (input.length () == 0)
|
||||
return false;
|
||||
|
|
|
@ -39,11 +39,12 @@ public:
|
|||
Sequence (const std::string&); // Parse
|
||||
~Sequence (); // Destructor
|
||||
|
||||
bool valid (const std::string&) const;
|
||||
void parse (const std::string&);
|
||||
void combine (const Sequence&);
|
||||
|
||||
private:
|
||||
bool validId (const std::string&);
|
||||
bool validId (const std::string&) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -302,18 +302,6 @@ static bool validId (const std::string& input)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 1,2-4,6
|
||||
bool validSequence (
|
||||
const std::string& input,
|
||||
Sequence& sequence)
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
try { sequence.parse (input); }
|
||||
catch (...) { valid = false; }
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
static bool validSequence (
|
||||
const std::string& input,
|
||||
std::vector <int>& ids)
|
||||
|
|
|
@ -43,7 +43,6 @@ bool validPriority (const std::string&);
|
|||
bool validDate (std::string&);
|
||||
bool validDuration (std::string&);
|
||||
bool validDescription (const std::string&);
|
||||
bool validSequence (const std::string&, Sequence&);
|
||||
void loadCustomReports ();
|
||||
bool isCustomReport (const std::string&);
|
||||
void allCustomReports (std::vector <std::string>&);
|
||||
|
|
|
@ -41,10 +41,26 @@ Sequence parseSequence (const std::string& input)
|
|||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (18);
|
||||
UnitTest t (30);
|
||||
|
||||
// Test for validity.
|
||||
Sequence seq;
|
||||
t.notok (seq.valid ("1--2"), "not valid 1--2");
|
||||
t.notok (seq.valid ("1-2-3"), "not valid 1-2-3");
|
||||
t.notok (seq.valid ("-1-2"), "not valid -1-2");
|
||||
|
||||
t.ok (seq.valid ("1"), "valid 1");
|
||||
t.ok (seq.valid ("1,3"), "valid 1,3");
|
||||
t.ok (seq.valid ("3,1"), "valid 3,1");
|
||||
t.ok (seq.valid ("1,3-5,7"), "valid 1,3-5,7");
|
||||
t.ok (seq.valid ("1-1000"), "valid 1-1000");
|
||||
t.ok (seq.valid ("1-1001"), "valid 1-1001");
|
||||
t.ok (seq.valid ("1-two"), "valid 1-two");
|
||||
t.ok (seq.valid ("one-2"), "valid one-2");
|
||||
t.ok (seq.valid ("1-5,3-7"), "valid 1-5,3-7");
|
||||
|
||||
// 1
|
||||
Sequence seq = parseSequence ("1");
|
||||
seq = parseSequence ("1");
|
||||
t.is (seq.size (), (size_t)1, "seq '1' -> 1 item");
|
||||
if (seq.size () == 1)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue