- ::operator_match and ::operator_nomatch now take a 'const Task&' argument to
  use for description/annotation matching.
- Updated unit tests.
This commit is contained in:
Paul Beckingham
2014-06-03 01:27:02 -04:00
parent ca6940ba2e
commit 512fe2f6c7
5 changed files with 149 additions and 128 deletions

View File

@@ -287,8 +287,8 @@ void Eval::evaluatePostfixStack (
else if (token->first == "^") left ^= right;
else if (token->first == "%") left %= right;
else if (token->first == "xor") left = left.operator_xor (right);
else if (token->first == "~") left = left.operator_match (right);
else if (token->first == "!~") left = left.operator_nomatch (right);
else if (token->first == "~") left = left.operator_match (right, contextTask);
else if (token->first == "!~") left = left.operator_nomatch (right, contextTask);
else if (token->first == "_hastag_") left = left.operator_hastag (right, contextTask);
else if (token->first == "_notag_") left = left.operator_notag (right, contextTask);
else

View File

@@ -766,8 +766,9 @@ bool Variant::operator!= (const Variant& other) const
}
////////////////////////////////////////////////////////////////////////////////
bool Variant::operator_match (const Variant& other) const
bool Variant::operator_match (const Variant& other, const Task& task) const
{
// Simple matching case first.
Variant left (*this);
Variant right (other);
@@ -775,13 +776,29 @@ bool Variant::operator_match (const Variant& other) const
right.cast (type_string);
RX r (right._string, searchCaseSensitive);
return r.match (left._string);
if (r.match (left._string))
return true;
// If the above did not match, and the left source is "description", then
// in the annotations.
if (left.source () == "description")
{
std::map <std::string, std::string> annotations;
task.getAnnotations (annotations);
std::map <std::string, std::string>::iterator a;
for (a = annotations.begin (); a != annotations.end (); ++a)
if (r.match (a->second))
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Variant::operator_nomatch (const Variant& other) const
bool Variant::operator_nomatch (const Variant& other, const Task& task) const
{
return ! operator_match (other);
return ! operator_match (other, task);
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -64,8 +64,8 @@ public:
bool operator>= (const Variant&) const;
bool operator== (const Variant&) const;
bool operator!= (const Variant&) const;
bool operator_match (const Variant&) const;
bool operator_nomatch (const Variant&) const;
bool operator_match (const Variant&, const Task&) const;
bool operator_nomatch (const Variant&, const Task&) const;
bool operator_partial (const Variant&) const;
bool operator_nopartial (const Variant&) const;
bool operator_hastag (const Variant&, const Task&) const;