Rules: Improved use of 'const' and 'auto'

This commit is contained in:
Paul Beckingham 2016-02-24 23:55:46 -05:00
parent 549b970e49
commit 88f6872190

View file

@ -53,7 +53,7 @@ void initializeColorRules ()
// Load all the configuration values, filter to only the ones that begin with // Load all the configuration values, filter to only the ones that begin with
// "color.", then store name/value in gsColor, and name in rules. // "color.", then store name/value in gsColor, and name in rules.
std::vector <std::string> 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)) if (! v.first.compare (0, 6, "color.", 6))
{ {
@ -70,7 +70,7 @@ void initializeColorRules ()
std::vector <std::string> precedence; std::vector <std::string> precedence;
split (precedence, context.config.get ("rule.precedence.color"), ','); split (precedence, context.config.get ("rule.precedence.color"), ',');
for (auto& p : precedence) for (const auto& p : precedence)
{ {
// Add the leading "color." string. // Add the leading "color." string.
std::string rule = "color." + p; std::string rule = "color." + p;
@ -96,7 +96,6 @@ static void applyColor (const Color& base, Color& c, bool merge)
c = base; c = base;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeBlocked (Task& task, const Color& base, Color& c, bool merge) 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. // Observe the case sensitivity setting.
bool sensitive = context.config.getBoolean ("search.case.sensitive"); bool sensitive = context.config.getBoolean ("search.case.sensitive");
std::string project = task.get ("project"); auto project = task.get ("project");
std::string rule_trunc = rule.substr (14); auto rule_trunc = rule.substr (14);
// Match project names leftmost. // Match project names leftmost.
if (rule_trunc.length () <= project.length ()) 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) static void colorizeKeyword (Task& task, const std::string& rule, const Color& base, Color& c, bool merge)
{ {
// Observe the case sensitivity setting. // 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 // The easiest thing to check is the description, because it is just one
// attribute. // attribute.
@ -192,10 +191,10 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
// first match. // first match.
else else
{ {
for (auto& it : task.data) for (const auto& att : task.data)
{ {
if (! it.first.compare (0, 11, "annotation_", 11) && if (! att.first.compare (0, 11, "annotation_", 11) &&
find (it.second, rule.substr (14), sensitive) != std::string::npos) find (att.second, rule.substr (14), sensitive) != std::string::npos)
{ {
applyColor (base, c, merge); applyColor (base, c, merge);
return; 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) 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? // 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 (pos == std::string::npos)
{ {
if (task.has (rule.substr (10))) if (task.has (rule.substr (10)))
@ -216,8 +215,8 @@ static void colorizeUDA (Task& task, const std::string& rule, const Color& base,
} }
else else
{ {
const std::string uda = rule.substr (10, pos - 10); auto uda = rule.substr (10, pos - 10);
const std::string val = rule.substr (pos + 1); auto val = rule.substr (pos + 1);
if ((val == "none" && ! task.has (uda)) || if ((val == "none" && ! task.has (uda)) ||
task.get (uda) == val) task.get (uda) == val)
applyColor (base, c, merge); applyColor (base, c, merge);
@ -229,7 +228,7 @@ static void colorizeDue (Task& task, const Color& base, Color& c, bool merge)
{ {
if (task.has ("due")) if (task.has ("due"))
{ {
Task::status status = task.getStatus (); auto status = task.getStatus ();
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted && status != Task::deleted &&
task.getDateState ("due") == Task::dateAfterToday) 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")) if (task.has ("due"))
{ {
Task::status status = task.getStatus (); auto status = task.getStatus ();
Task::dateState dateState = task.getDateState ("due"); auto dateState = task.getDateState ("due");
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted && status != Task::deleted &&
(dateState == Task::dateLaterToday || dateState == Task::dateEarlierToday)) (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")) if (task.has ("due"))
{ {
Task::status status = task.getStatus (); auto status = task.getStatus ();
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted && status != Task::deleted &&
task.getDateState ("due") == Task::dateBeforeToday) task.getDateState ("due") == Task::dateBeforeToday)
@ -296,7 +295,7 @@ void autoColorize (Task& task, Color& c)
return; 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: c already contains colors specifically assigned via command.
// Note: These rules form a hierarchy - the last rule is King, hence the // Note: These rules form a hierarchy - the last rule is King, hence the