mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Rules: Improved use of 'const' and 'auto'
This commit is contained in:
parent
549b970e49
commit
88f6872190
1 changed files with 20 additions and 21 deletions
|
@ -53,7 +53,7 @@ void initializeColorRules ()
|
|||
// Load all the configuration values, filter to only the ones that begin with
|
||||
// "color.", then store name/value in gsColor, and name in rules.
|
||||
std::vector <std::string> rules;
|
||||
for (auto& v : context.config)
|
||||
for (const auto& v : context.config)
|
||||
{
|
||||
if (! v.first.compare (0, 6, "color.", 6))
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ void initializeColorRules ()
|
|||
std::vector <std::string> precedence;
|
||||
split (precedence, context.config.get ("rule.precedence.color"), ',');
|
||||
|
||||
for (auto& p : precedence)
|
||||
for (const auto& p : precedence)
|
||||
{
|
||||
// Add the leading "color." string.
|
||||
std::string rule = "color." + p;
|
||||
|
@ -90,13 +90,12 @@ void initializeColorRules ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void applyColor (const Color& base, Color& c, bool merge)
|
||||
{
|
||||
if (merge)
|
||||
c.blend (base);
|
||||
else
|
||||
c = base;
|
||||
if (merge)
|
||||
c.blend (base);
|
||||
else
|
||||
c = base;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeBlocked (Task& task, const Color& base, Color& c, bool merge)
|
||||
{
|
||||
|
@ -154,8 +153,8 @@ static void colorizeProject (Task& task, const std::string& rule, const Color& b
|
|||
// Observe the case sensitivity setting.
|
||||
bool sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||
|
||||
std::string project = task.get ("project");
|
||||
std::string rule_trunc = rule.substr (14);
|
||||
auto project = task.get ("project");
|
||||
auto rule_trunc = rule.substr (14);
|
||||
|
||||
// Match project names leftmost.
|
||||
if (rule_trunc.length () <= project.length ())
|
||||
|
@ -181,7 +180,7 @@ static void colorizeTagNone (Task& task, const Color& base, Color& c, bool merge
|
|||
static void colorizeKeyword (Task& task, const std::string& rule, const Color& base, Color& c, bool merge)
|
||||
{
|
||||
// Observe the case sensitivity setting.
|
||||
bool sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||
auto sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||
|
||||
// The easiest thing to check is the description, because it is just one
|
||||
// attribute.
|
||||
|
@ -192,10 +191,10 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
|
|||
// first match.
|
||||
else
|
||||
{
|
||||
for (auto& it : task.data)
|
||||
for (const auto& att : task.data)
|
||||
{
|
||||
if (! it.first.compare (0, 11, "annotation_", 11) &&
|
||||
find (it.second, rule.substr (14), sensitive) != std::string::npos)
|
||||
if (! att.first.compare (0, 11, "annotation_", 11) &&
|
||||
find (att.second, rule.substr (14), sensitive) != std::string::npos)
|
||||
{
|
||||
applyColor (base, c, merge);
|
||||
return;
|
||||
|
@ -208,7 +207,7 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
|
|||
static void colorizeUDA (Task& task, const std::string& rule, const Color& base, Color& c, bool merge)
|
||||
{
|
||||
// Is the rule color.uda.name.value or color.uda.name?
|
||||
size_t pos = rule.find (".", 10);
|
||||
auto pos = rule.find (".", 10);
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
if (task.has (rule.substr (10)))
|
||||
|
@ -216,8 +215,8 @@ static void colorizeUDA (Task& task, const std::string& rule, const Color& base,
|
|||
}
|
||||
else
|
||||
{
|
||||
const std::string uda = rule.substr (10, pos - 10);
|
||||
const std::string val = rule.substr (pos + 1);
|
||||
auto uda = rule.substr (10, pos - 10);
|
||||
auto val = rule.substr (pos + 1);
|
||||
if ((val == "none" && ! task.has (uda)) ||
|
||||
task.get (uda) == val)
|
||||
applyColor (base, c, merge);
|
||||
|
@ -229,7 +228,7 @@ static void colorizeDue (Task& task, const Color& base, Color& c, bool merge)
|
|||
{
|
||||
if (task.has ("due"))
|
||||
{
|
||||
Task::status status = task.getStatus ();
|
||||
auto status = task.getStatus ();
|
||||
if (status != Task::completed &&
|
||||
status != Task::deleted &&
|
||||
task.getDateState ("due") == Task::dateAfterToday)
|
||||
|
@ -242,8 +241,8 @@ static void colorizeDueToday (Task& task, const Color& base, Color& c, bool merg
|
|||
{
|
||||
if (task.has ("due"))
|
||||
{
|
||||
Task::status status = task.getStatus ();
|
||||
Task::dateState dateState = task.getDateState ("due");
|
||||
auto status = task.getStatus ();
|
||||
auto dateState = task.getDateState ("due");
|
||||
if (status != Task::completed &&
|
||||
status != Task::deleted &&
|
||||
(dateState == Task::dateLaterToday || dateState == Task::dateEarlierToday))
|
||||
|
@ -256,7 +255,7 @@ static void colorizeOverdue (Task& task, const Color& base, Color& c, bool merge
|
|||
{
|
||||
if (task.has ("due"))
|
||||
{
|
||||
Task::status status = task.getStatus ();
|
||||
auto status = task.getStatus ();
|
||||
if (status != Task::completed &&
|
||||
status != Task::deleted &&
|
||||
task.getDateState ("due") == Task::dateBeforeToday)
|
||||
|
@ -296,7 +295,7 @@ void autoColorize (Task& task, Color& c)
|
|||
return;
|
||||
}
|
||||
|
||||
bool merge = context.config.getBoolean ("rule.color.merge");
|
||||
auto merge = context.config.getBoolean ("rule.color.merge");
|
||||
|
||||
// Note: c already contains colors specifically assigned via command.
|
||||
// Note: These rules form a hierarchy - the last rule is King, hence the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue