Enhancement - Sequence integration
- Sequence object fully integrated.
This commit is contained in:
@@ -259,25 +259,15 @@ void Context::parse ()
|
|||||||
|
|
||||||
// Sequence
|
// Sequence
|
||||||
// Note: "add" doesn't require an ID
|
// Note: "add" doesn't require an ID
|
||||||
else if (command != "add" &&
|
else if (command != "add" &&
|
||||||
validSequence (*arg, sequence) &&
|
sequence.valid (*arg) &&
|
||||||
! foundSomethingAfterSequence)
|
! foundSomethingAfterSequence)
|
||||||
{
|
{
|
||||||
std::cout << "# found sequence" << std::endl;
|
std::cout << "# found sequence" << std::endl;
|
||||||
|
sequence.parse (*arg);
|
||||||
foundSequence = true;
|
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.
|
// Tags begin with + or - and contain arbitrary text.
|
||||||
else if (validTag (arg))
|
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)
|
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)
|
if (input.length () == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -39,11 +39,12 @@ public:
|
|||||||
Sequence (const std::string&); // Parse
|
Sequence (const std::string&); // Parse
|
||||||
~Sequence (); // Destructor
|
~Sequence (); // Destructor
|
||||||
|
|
||||||
|
bool valid (const std::string&) const;
|
||||||
void parse (const std::string&);
|
void parse (const std::string&);
|
||||||
void combine (const Sequence&);
|
void combine (const Sequence&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool validId (const std::string&);
|
bool validId (const std::string&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -302,18 +302,6 @@ static bool validId (const std::string& input)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// 1,2-4,6
|
// 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 (
|
static bool validSequence (
|
||||||
const std::string& input,
|
const std::string& input,
|
||||||
std::vector <int>& ids)
|
std::vector <int>& ids)
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ bool validPriority (const std::string&);
|
|||||||
bool validDate (std::string&);
|
bool validDate (std::string&);
|
||||||
bool validDuration (std::string&);
|
bool validDuration (std::string&);
|
||||||
bool validDescription (const std::string&);
|
bool validDescription (const std::string&);
|
||||||
bool validSequence (const std::string&, Sequence&);
|
|
||||||
void loadCustomReports ();
|
void loadCustomReports ();
|
||||||
bool isCustomReport (const std::string&);
|
bool isCustomReport (const std::string&);
|
||||||
void allCustomReports (std::vector <std::string>&);
|
void allCustomReports (std::vector <std::string>&);
|
||||||
|
|||||||
@@ -41,10 +41,26 @@ Sequence parseSequence (const std::string& input)
|
|||||||
|
|
||||||
int main (int argc, char** argv)
|
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
|
// 1
|
||||||
Sequence seq = parseSequence ("1");
|
seq = parseSequence ("1");
|
||||||
t.is (seq.size (), (size_t)1, "seq '1' -> 1 item");
|
t.is (seq.size (), (size_t)1, "seq '1' -> 1 item");
|
||||||
if (seq.size () == 1)
|
if (seq.size () == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user