mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Eliminated obsolete or unused methods.
This commit is contained in:
parent
4d410972d4
commit
523c4dfcca
2 changed files with 0 additions and 373 deletions
368
src/Att.cpp
368
src/Att.cpp
|
@ -508,19 +508,6 @@ std::string Att::type (const std::string& name) const
|
|||
return "text";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The type of an attribute is useful for modifier evaluation.
|
||||
std::string Att::modType (const std::string& name) const
|
||||
{
|
||||
if (name == "hasnt" ||
|
||||
name == "isnt" ||
|
||||
name == "not" || // TODO Verify this.
|
||||
name == "noword")
|
||||
return "negative";
|
||||
|
||||
return "positive";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ______________
|
||||
// | |
|
||||
|
@ -590,347 +577,6 @@ void Att::parse (Nibbler& n)
|
|||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// "this" is the attribute that has modifiers. "other" is the attribute from a
|
||||
// Record that does not have modifiers, but may have a value.
|
||||
//
|
||||
// In other words, the filter:
|
||||
// task list description.contains:foo
|
||||
//
|
||||
// Is represented with:
|
||||
// this = filter (description.contains:foo)
|
||||
// other = actual task data to be matched
|
||||
//
|
||||
bool Att::match (const Att& other) const
|
||||
{
|
||||
// All matches are assumed to pass, any short-circuit on non-match.
|
||||
bool case_sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||
|
||||
// Are regular expressions being used in place of string comparison?
|
||||
#ifdef FEATURE_REGEX
|
||||
bool regex = context.config.getBoolean ("regex");
|
||||
#endif
|
||||
|
||||
// If there are no mods, just perform a straight compare on value.
|
||||
if (mMod == "")
|
||||
{
|
||||
// Exact matches on dates should only compare m/d/y, not h:m:s. This allows
|
||||
// comparisons like "task list due:today" (bug #405).
|
||||
std::string which = type (mName);
|
||||
if (which == "date")
|
||||
{
|
||||
if (other.mValue == "")
|
||||
return false;
|
||||
|
||||
Date left (mValue);
|
||||
Date right (other.mValue);
|
||||
|
||||
if (! left.sameDay (right))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
std::string pattern = "^" + mValue + "$";
|
||||
RX r (pattern, case_sensitive);
|
||||
if (!r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else if (!compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#else
|
||||
if (!compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// has = contains as a substring.
|
||||
else if (mMod == "has" || mMod == "contains") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
RX r (mValue, case_sensitive);
|
||||
if (!r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos)
|
||||
return false;
|
||||
#else
|
||||
if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// is = equal. Nop.
|
||||
else if (mMod == "is" || mMod == "equals") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
std::string pattern = "^" + mValue + "$";
|
||||
RX r (pattern, case_sensitive);
|
||||
if (!r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else if (!compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#else
|
||||
if (!compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// isnt = not equal.
|
||||
else if (mMod == "isnt" || mMod == "not") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
std::string pattern = "^" + mValue + "$";
|
||||
RX r (pattern, case_sensitive);
|
||||
if (r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else if (compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#else
|
||||
if (compare (mValue, other.mValue, (bool) case_sensitive))
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// any = any value, but not empty value.
|
||||
else if (mMod == "any") // TODO i18n
|
||||
{
|
||||
if (other.mValue == "")
|
||||
return false;
|
||||
}
|
||||
|
||||
// none = must have empty value.
|
||||
else if (mMod == "none") // TODO i18n
|
||||
{
|
||||
if (other.mValue != "")
|
||||
return false;
|
||||
}
|
||||
|
||||
// startswith = first characters must match.
|
||||
else if (mMod == "startswith" || mMod == "left") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
std::string pattern = "^" + mValue;
|
||||
RX r (pattern, case_sensitive);
|
||||
if (!r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
if (other.mValue.length () < mValue.length ())
|
||||
return false;
|
||||
|
||||
if (!compare (mValue, other.mValue.substr (0, mValue.length ()), (bool) case_sensitive))
|
||||
return false;
|
||||
#ifdef FEATURE_REGEX
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// endswith = last characters must match.
|
||||
else if (mMod == "endswith" || mMod == "right") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
std::string pattern = mValue + "$";
|
||||
RX r (pattern, case_sensitive);
|
||||
if (!r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
if (other.mValue.length () < mValue.length ())
|
||||
return false;
|
||||
|
||||
if (!compare (mValue, other.mValue.substr (
|
||||
other.mValue.length () - mValue.length (),
|
||||
std::string::npos), (bool) case_sensitive))
|
||||
return false;
|
||||
#ifdef FEATURE_REGEX
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// hasnt = does not contain as a substring.
|
||||
else if (mMod == "hasnt") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex)
|
||||
{
|
||||
RX r (mValue, case_sensitive);
|
||||
if (r.match (other.mValue))
|
||||
return false;
|
||||
}
|
||||
else if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos)
|
||||
return false;
|
||||
#else
|
||||
if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// before = under = below = <
|
||||
else if (mMod == "before" || mMod == "under" || mMod == "below")
|
||||
{
|
||||
std::string which = type (mName);
|
||||
if (which == "duration")
|
||||
{
|
||||
Duration literal (mValue);
|
||||
Duration variable ((time_t)atoi (other.mValue.c_str ()));
|
||||
if (!(variable < literal))
|
||||
return false;
|
||||
}
|
||||
else if (which == "date")
|
||||
{
|
||||
Date literal (mValue.c_str (), context.config.get ("dateformat"));
|
||||
Date variable ((time_t)atoi (other.mValue.c_str ()));
|
||||
if (other.mValue == "" || ! (variable < literal))
|
||||
return false;
|
||||
}
|
||||
else if (which == "number")
|
||||
{
|
||||
if (atoi (mValue.c_str ()) >= atoi (other.mValue.c_str ()))
|
||||
return false;
|
||||
}
|
||||
else if (which == "text")
|
||||
{
|
||||
if (mValue <= other.mValue)
|
||||
return false;
|
||||
}
|
||||
else if (which == "priority")
|
||||
{
|
||||
if (mValue == "" ||
|
||||
other.mValue == "H" ||
|
||||
mValue == other.mValue ||
|
||||
(mValue == "L" && other.mValue == "M"))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// after = over = above = >
|
||||
else if (mMod == "after" || mMod == "over" || mMod == "above")
|
||||
{
|
||||
std::string which = type (mName);
|
||||
if (which == "duration")
|
||||
{
|
||||
Duration literal (mValue);
|
||||
Duration variable ((time_t)atoi (other.mValue.c_str ()));
|
||||
if (! (variable > literal))
|
||||
return false;
|
||||
}
|
||||
else if (which == "date")
|
||||
{
|
||||
Date literal (mValue.c_str (), context.config.get ("dateformat"));
|
||||
Date variable ((time_t)atoi (other.mValue.c_str ()));
|
||||
if (! (variable > literal))
|
||||
return false;
|
||||
}
|
||||
else if (which == "number")
|
||||
{
|
||||
if (atoi (mValue.c_str ()) <= atoi (other.mValue.c_str ()))
|
||||
return false;
|
||||
}
|
||||
else if (which == "text")
|
||||
{
|
||||
if (mValue >= other.mValue)
|
||||
return false;
|
||||
}
|
||||
else if (which == "priority")
|
||||
{
|
||||
if (mValue == "H" ||
|
||||
other.mValue == "" ||
|
||||
mValue == other.mValue ||
|
||||
(mValue == "M" && other.mValue == "L"))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// word = contains as a substring, with word boundaries.
|
||||
else if (mMod == "word") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex && other.mName != "tags")
|
||||
{
|
||||
std::vector <int> start;
|
||||
std::vector <int> end;
|
||||
RX r (mValue, case_sensitive);
|
||||
if (!r.match (start, end, other.mValue))
|
||||
return false;
|
||||
|
||||
if (!isWordStart (other.mValue, start[0]))
|
||||
return false;
|
||||
|
||||
if (!isWordEnd (other.mValue, end[0]))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
// Fail if the substring is not found.
|
||||
std::string::size_type sub = find (other.mValue, mValue, (bool) case_sensitive);
|
||||
if (sub == std::string::npos)
|
||||
return false;
|
||||
|
||||
// Also fail if there is no word boundary at beginning and end.
|
||||
if (!isWordStart (other.mValue, sub))
|
||||
return false;
|
||||
|
||||
if (!isWordEnd (other.mValue, sub + mValue.length () - 1))
|
||||
return false;
|
||||
#ifdef FEATURE_REGEX
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// noword = does not contain as a substring, with word boundaries.
|
||||
else if (mMod == "noword") // TODO i18n
|
||||
{
|
||||
#ifdef FEATURE_REGEX
|
||||
if (regex && other.mName != "tags")
|
||||
{
|
||||
std::vector <int> start;
|
||||
std::vector <int> end;
|
||||
RX r (mValue, case_sensitive);
|
||||
if (r.match (start, end, other.mValue) &&
|
||||
isWordStart (other.mValue, start[0]) &&
|
||||
isWordEnd (other.mValue, end[0]))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
// Fail if the substring is not found.
|
||||
std::string::size_type sub = find (other.mValue, mValue);
|
||||
if (sub != std::string::npos &&
|
||||
isWordStart (other.mValue, sub) &&
|
||||
isWordEnd (other.mValue, sub + mValue.length () - 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#ifdef FEATURE_REGEX
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// name : " value "
|
||||
std::string Att::composeF4 () const
|
||||
|
@ -988,12 +634,6 @@ void Att::value (const std::string& value)
|
|||
mValue = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Att::value_int () const
|
||||
{
|
||||
return atoi (mValue.c_str ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::allNames (std::vector <std::string>& all)
|
||||
{
|
||||
|
@ -1007,14 +647,6 @@ void Att::allNames (std::vector <std::string>& all)
|
|||
all.push_back (modifiableNames[i]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::value_int (int value)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << value;
|
||||
mValue = s.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Add quotes.
|
||||
void Att::enquote (std::string& value) const
|
||||
|
|
|
@ -54,10 +54,8 @@ public:
|
|||
static bool validNameValue (std::string&, std::string&, std::string&);
|
||||
static bool validMod (const std::string&);
|
||||
std::string type (const std::string&) const;
|
||||
std::string modType (const std::string&) const;
|
||||
void parse (const std::string&);
|
||||
void parse (Nibbler&);
|
||||
bool match (const Att&) const;
|
||||
|
||||
std::string composeF4 () const;
|
||||
|
||||
|
@ -70,9 +68,6 @@ public:
|
|||
std::string value () const;
|
||||
void value (const std::string&);
|
||||
|
||||
int value_int () const;
|
||||
void value_int (int);
|
||||
|
||||
static void allNames (std::vector <std::string>&);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue