From e74c6963a9cc761f9abe2c635fbc7bd92defd0e4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 11 May 2015 17:50:53 -0400 Subject: [PATCH] C++11: Cleaned up program framework with range-based for --- src/CLI.cpp | 502 ++++++++++++++++++++------------------------- src/Color.cpp | 15 +- src/Config.cpp | 10 +- src/Context.cpp | 162 ++++++--------- src/DOM.cpp | 14 +- src/Date.cpp | 7 +- src/Eval.cpp | 127 ++++++------ src/Eval.h | 4 +- src/File.cpp | 20 +- src/Filter.cpp | 70 +++---- src/Hooks.cpp | 142 ++++++------- src/JSON.cpp | 24 +-- src/JSON.h | 3 - src/Msg.cpp | 24 +-- src/Nibbler.cpp | 7 +- src/TDB2.cpp | 300 +++++++++++---------------- src/Task.cpp | 322 +++++++++++++---------------- src/Variant.cpp | 10 +- src/ViewTask.cpp | 11 +- src/ViewText.cpp | 14 +- src/calc.cpp | 5 +- src/dependency.cpp | 67 +++--- src/feedback.cpp | 146 +++++++------ src/legacy.cpp | 46 ++--- src/recur.cpp | 57 +++-- src/rules.cpp | 31 ++- src/sort.cpp | 5 +- src/util.cpp | 13 +- 28 files changed, 937 insertions(+), 1221 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 451aa7467..3b278d1d0 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -116,8 +116,7 @@ void A::tag (const std::string& tag) //////////////////////////////////////////////////////////////////////////////// void A::unTag (const std::string& tag) { - std::vector ::iterator i; - for (i = _tags.begin (); i != _tags.end (); ++i) + for (auto i = _tags.begin (); i != _tags.end (); ++i) { if (*i == tag) { @@ -159,7 +158,7 @@ void A::attribute (const std::string& name, const double value) const std::string A::attribute (const std::string& name) const { // Prevent autovivification. - std::map::const_iterator i = _attributes.find (name); + auto i = _attributes.find (name); if (i != _attributes.end ()) return i->second; @@ -179,8 +178,7 @@ const std::string A::dump () const // Dump attributes. std::string atts; - std::map ::const_iterator a; - for (a = _attributes.begin (); a != _attributes.end (); ++a) + for (auto a = _attributes.begin (); a != _attributes.end (); ++a) { if (a != _attributes.begin ()) atts += " "; @@ -193,21 +191,20 @@ const std::string A::dump () const // Dump tags. std::string tags; - std::vector ::const_iterator tag; - for (tag = _tags.begin (); tag != _tags.end (); ++tag) + for (auto& tag : _tags) { if (tags.length ()) tags += ' '; - if (*tag == "BINARY") tags += "\033[1;37;44m" + *tag + "\033[0m"; - else if (*tag == "CMD") tags += "\033[1;37;46m" + *tag + "\033[0m"; - else if (*tag == "FILTER") tags += "\033[1;37;42m" + *tag + "\033[0m"; - else if (*tag == "MODIFICATION") tags += "\033[1;37;43m" + *tag + "\033[0m"; - else if (*tag == "RC") tags += "\033[1;37;41m" + *tag + "\033[0m"; - else if (*tag == "CONFIG") tags += "\033[1;37;101m" + *tag + "\033[0m"; - else if (*tag == "PSEUDO") tags += "\033[1;37;45m" + *tag + "\033[0m"; - else if (*tag == "?") tags += "\033[38;5;255;48;5;232m" + *tag + "\033[0m"; - else tags += "\033[32m" + *tag + "\033[0m"; + if (tag == "BINARY") tags += "\033[1;37;44m" + tag + "\033[0m"; + else if (tag == "CMD") tags += "\033[1;37;46m" + tag + "\033[0m"; + else if (tag == "FILTER") tags += "\033[1;37;42m" + tag + "\033[0m"; + else if (tag == "MODIFICATION") tags += "\033[1;37;43m" + tag + "\033[0m"; + else if (tag == "RC") tags += "\033[1;37;41m" + tag + "\033[0m"; + else if (tag == "CONFIG") tags += "\033[1;37;101m" + tag + "\033[0m"; + else if (tag == "PSEUDO") tags += "\033[1;37;45m" + tag + "\033[0m"; + else if (tag == "?") tags += "\033[38;5;255;48;5;232m" + tag + "\033[0m"; + else tags += "\033[32m" + tag + "\033[0m"; } if (tags.length ()) @@ -324,13 +321,9 @@ void CLI::alias (const std::string& name, const std::string& value) //////////////////////////////////////////////////////////////////////////////// void CLI::entity (const std::string& category, const std::string& name) { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range (category); - // Walk the list of entities for category. - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range (category); + for (auto e = c.first; e != c.second; ++e) if (e->second == name) return; @@ -385,17 +378,16 @@ void CLI::addContextFilter () // Detect if UUID or ID is set, and bail out if (_args.size ()) { - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { // TODO This looks wrong. - if (a->hasTag ("FILTER") && - a->hasTag ("ATTRIBUTE") && - ! a->hasTag ("TERMINATED") && - ! a->hasTag ("WORD") && - (a->attribute ("raw") == "id" || a->attribute ("raw") == "uuid")) + if (a.hasTag ("FILTER") && + a.hasTag ("ATTRIBUTE") && + ! a.hasTag ("TERMINATED") && + ! a.hasTag ("WORD") && + (a.attribute ("raw") == "id" || a.attribute ("raw") == "uuid")) { - context.debug (format ("UUID/ID lexeme found '{1}', not applying context.", a->attribute ("raw"))); + context.debug (format ("UUID/ID lexeme found '{1}', not applying context.", a.attribute ("raw"))); return; } } @@ -513,13 +505,12 @@ void CLI::analyze (bool parse /* = true */, bool strict /* = false */) //////////////////////////////////////////////////////////////////////////////// void CLI::applyOverrides () { - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("CONFIG")) + if (a.hasTag ("CONFIG")) { - std::string name = a->attribute ("name"); - std::string value = a->attribute ("value"); + std::string name = a.attribute ("name"); + std::string value = a.attribute ("value"); context.config.set (name, value); context.footnote (format (STRING_PARSER_OVERRIDE_RC, name, value)); } @@ -539,17 +530,16 @@ const std::string CLI::getFilter (bool applyContext /* = true */) std::string filter = ""; if (_args.size ()) { - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { if (filter != "") filter += ' '; - std::string term = a->attribute ("name"); + std::string term = a.attribute ("name"); if (term == "") - term = a->attribute ("raw"); + term = a.attribute ("raw"); filter += term; } @@ -572,16 +562,15 @@ const std::vector CLI::getWords () analyze (false); std::vector words; - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (! a->hasTag ("BINARY") && - ! a->hasTag ("RC") && - ! a->hasTag ("CONFIG") && - ! a->hasTag ("CMD") && - ! a->hasTag ("TERMINATOR")) + if (! a.hasTag ("BINARY") && + ! a.hasTag ("RC") && + ! a.hasTag ("CONFIG") && + ! a.hasTag ("CMD") && + ! a.hasTag ("TERMINATOR")) { - words.push_back (a->attribute ("raw")); + words.push_back (a.attribute ("raw")); } } @@ -595,14 +584,10 @@ bool CLI::canonicalize ( const std::string& category, const std::string& value) const { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range (category); - // Extract a list of entities for category. std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range (category); + for (auto e = c.first; e != c.second; ++e) { // Shortcut: if an exact match is found, success. if (value == e->second) @@ -637,10 +622,9 @@ std::string CLI::getBinary () const //////////////////////////////////////////////////////////////////////////////// std::string CLI::getCommand () const { - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) - if (a->hasTag ("CMD")) - return a->attribute ("canonical"); + for (auto& a : _args) + if (a.hasTag ("CMD")) + return a.attribute ("canonical"); return ""; } @@ -648,11 +632,10 @@ std::string CLI::getCommand () const //////////////////////////////////////////////////////////////////////////////// std::string CLI::getLimit () const { - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) - if (a->hasTag ("PSEUDO") && - a->attribute ("canonical") == "limit") - return a->attribute ("value"); + for (auto& a : _args) + if (a.hasTag ("PSEUDO") && + a.attribute ("canonical") == "limit") + return a.attribute ("value"); return "0"; } @@ -665,8 +648,7 @@ const std::string CLI::dump (const std::string& title /* = "CLI Parser" */) cons out << "\033[1m" << title << "\033[0m\n" << " _original_args\n "; Color colorOrigArgs ("gray10 on gray4"); - std::vector ::const_iterator i; - for (i = _original_args.begin (); i != _original_args.end (); ++i) + for (auto i = _original_args.begin (); i != _original_args.end (); ++i) { if (i != _original_args.begin ()) out << ' '; @@ -675,9 +657,8 @@ const std::string CLI::dump (const std::string& title /* = "CLI Parser" */) cons out << "\n"; out << " _args\n"; - std::vector ::const_iterator a; - for (a = _args.begin (); a != _args.end (); ++a) - out << " " << a->dump () << "\n"; + for (auto& a : _args) + out << " " << a.dump () << "\n"; return out.str (); } @@ -742,9 +723,8 @@ void CLI::addArg (const std::string& arg, Lexer::Type type /* = Lexer::Type::wor { // How often have I said to you that when you have eliminated the // impossible, whatever remains, however improbable, must be the truth? - std::vector >::iterator l; - for (l = lexemes.begin (); l != lexemes.end (); ++l) - _original_args.push_back (l->first); + for (auto& l : lexemes) + _original_args.push_back (l.first); } } } @@ -762,10 +742,9 @@ void CLI::aliasExpansion () bool terminated = false; std::string raw; - std::vector ::iterator i; - for (i = _args.begin (); i != _args.end (); ++i) + for (auto& i : _args) { - raw = i->attribute ("raw"); + raw = i.attribute ("raw"); if (raw == "--") terminated = true; @@ -774,11 +753,10 @@ void CLI::aliasExpansion () { if (_aliases.find (raw) != _aliases.end ()) { - std::vector lexed = Lexer::split (_aliases[raw]); - std::vector ::iterator l; - for (l = lexed.begin (); l != lexed.end (); ++l) + auto lexed = Lexer::split (_aliases[raw]); + for (auto& l : lexed) { - A a ("argLex", *l); + A a ("argLex", l); a.tag ("ALIAS"); a.tag ("LEX"); reconstructed.push_back (a); @@ -788,10 +766,10 @@ void CLI::aliasExpansion () changes = true; } else - reconstructed.push_back (*i); + reconstructed.push_back (i); } else - reconstructed.push_back (*i); + reconstructed.push_back (i); } _args = reconstructed; @@ -812,10 +790,9 @@ void CLI::findOverrides () bool changes = false; std::string raw; bool terminated = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - raw = a->attribute ("raw"); + raw = a.attribute ("raw"); if (raw == "--") terminated = true; @@ -825,8 +802,8 @@ void CLI::findOverrides () if (isRCOverride (raw)) { - a->tag ("RC"); - a->attribute ("file", raw.substr (3)); + a.tag ("RC"); + a.attribute ("file", raw.substr (3)); changes = true; } else if (isConfigOverride (raw)) @@ -836,9 +813,9 @@ void CLI::findOverrides () sep = raw.find (':', 3); if (sep != std::string::npos) { - a->tag ("CONFIG"); - a->attribute ("name", raw.substr (3, sep - 3)); - a->attribute ("value", raw.substr (sep + 1)); + a.tag ("CONFIG"); + a.attribute ("name", raw.substr (3, sep - 3)); + a.attribute ("value", raw.substr (sep + 1)); changes = true; } } @@ -857,15 +834,14 @@ void CLI::categorize () bool readOnly = false; bool terminated = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - std::string raw = a->attribute ("raw"); + std::string raw = a.attribute ("raw"); if (! terminated && raw == "--") { - a->tag ("ORIGINAL"); - a->tag ("TERMINATOR"); + a.tag ("ORIGINAL"); + a.tag ("TERMINATOR"); terminated = true; changes = true; continue; @@ -873,15 +849,15 @@ void CLI::categorize () else if (terminated) { - a->tag ("ORIGINAL"); - a->tag ("TERMINATED"); - a->tag ("WORD"); + a.tag ("ORIGINAL"); + a.tag ("TERMINATED"); + a.tag ("WORD"); changes = true; } if (raw.find (' ') != std::string::npos) { - a->tag ("QUOTED"); + a.tag ("QUOTED"); changes = true; } @@ -892,36 +868,36 @@ void CLI::categorize () { readOnly = ! exactMatch ("writecmd", canonical); - a->tag ("CMD"); - a->tag (readOnly ? "READCMD" : "WRITECMD"); - a->attribute ("canonical", canonical); + a.tag ("CMD"); + a.tag (readOnly ? "READCMD" : "WRITECMD"); + a.attribute ("canonical", canonical); foundCommand = true; changes = true; } - else if (a->hasTag ("TERMINATOR") || - a->hasTag ("BINARY") || - a->hasTag ("CONFIG") || - a->hasTag ("RC")) + else if (a.hasTag ("TERMINATOR") || + a.hasTag ("BINARY") || + a.hasTag ("CONFIG") || + a.hasTag ("RC")) { // NOP } else if (foundCommand && ! readOnly) { - a->tag ("MODIFICATION"); + a.tag ("MODIFICATION"); // If the argument contains a space, it was quoted. Record that. if (! Lexer::isOneWord (raw)) - a->tag ("QUOTED"); + a.tag ("QUOTED"); changes = true; } else if (!foundCommand || (foundCommand && readOnly)) { - a->tag ("FILTER"); + a.tag ("FILTER"); // If the argument contains a space, it was quoted. Record that. if (! Lexer::isOneWord (raw)) - a->tag ("QUOTED"); + a.tag ("QUOTED"); changes = true; } @@ -938,14 +914,10 @@ bool CLI::exactMatch ( const std::string& category, const std::string& value) const { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range (category); - // Extract a list of entities for category. std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range (category); + for (auto e = c.first; e != c.second; ++e) { // Shortcut: if an exact match is found, success. if (value == e->second) @@ -962,12 +934,11 @@ void CLI::desugarFilterTags () { bool changes = false; std::vector reconstructed; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string tag; std::string sign; @@ -994,10 +965,10 @@ void CLI::desugarFilterTags () changes = true; } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } if (changes) @@ -1018,13 +989,12 @@ void CLI::findStrayModifications () if (command == "add" || command == "log") { - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { - a->unTag ("FILTER"); - a->tag ("MODIFICATION"); + a.unTag ("FILTER"); + a.tag ("MODIFICATION"); changes = true; } } @@ -1041,14 +1011,13 @@ void CLI::desugarFilterAttributes () { bool changes = false; std::vector reconstructed; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { // Look for a valid attribute name. bool found = false; - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string name; if (n.getName (name) && name.length ()) @@ -1090,7 +1059,7 @@ void CLI::desugarFilterAttributes () else if (canonicalize (canonical, "pseudo", name)) { - A lhs ("argPseudo", a->attribute ("raw")); + A lhs ("argPseudo", a.attribute ("raw")); lhs.attribute ("canonical", canonical); lhs.attribute ("value", value); lhs.tag ("PSEUDO"); @@ -1129,10 +1098,10 @@ void CLI::desugarFilterAttributes () if (found) changes = true; else - reconstructed.push_back (*a); + reconstructed.push_back (a); } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } if (changes) @@ -1150,14 +1119,13 @@ void CLI::desugarFilterAttributeModifiers () { bool changes = false; std::vector reconstructed; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { // Look for a valid attribute name. bool found = false; - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string name; if (n.getUntil (".", name) && name.length ()) @@ -1302,10 +1270,10 @@ void CLI::desugarFilterAttributeModifiers () if (found) changes = true; else - reconstructed.push_back (*a); + reconstructed.push_back (a); } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } if (changes) @@ -1323,12 +1291,11 @@ void CLI::desugarFilterPatterns () { bool changes = false; std::vector reconstructed; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string pattern; if (n.getQuoted ('/', pattern) && @@ -1352,10 +1319,10 @@ void CLI::desugarFilterPatterns () changes = true; } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } if (changes) @@ -1378,13 +1345,12 @@ void CLI::desugarFilterPatterns () // void CLI::findIDs () { - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { // IDs have a limited character set. - std::string raw = a->attribute ("raw"); + std::string raw = a.attribute ("raw"); if (raw.find_first_not_of ("0123456789,-") == std::string::npos) { // Container for min/max ID ranges. @@ -1395,12 +1361,11 @@ void CLI::findIDs () split (elements, raw, ','); bool is_an_id = true; - std::vector ::iterator e; - for (e = elements.begin (); e != elements.end (); ++e) + for (auto& e : elements) { // Split the ID range into min/max. std::vector terms; - split (terms, *e, '-'); + split (terms, e, '-'); if (terms.size () == 1) { @@ -1464,12 +1429,11 @@ void CLI::findIDs () if (is_an_id) { - a->tag ("ID"); + a.tag ("ID"); // Save the ranges. - std::vector >::iterator r; - for (r = ranges.begin (); r != ranges.end (); ++r) - _id_ranges.push_back (*r); + for (auto& r : ranges) + _id_ranges.push_back (r); } } } @@ -1479,13 +1443,12 @@ void CLI::findIDs () //////////////////////////////////////////////////////////////////////////////// void CLI::findUUIDs () { - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { // UUIDs have a limited character set. - std::string raw = a->attribute ("raw"); + std::string raw = a.attribute ("raw"); if (raw.find_first_not_of ("0123456789abcdefABCDEF-,") == std::string::npos) { Nibbler n (raw); @@ -1507,12 +1470,11 @@ void CLI::findUUIDs () if (n.depleted ()) { - a->tag ("UUID"); + a.tag ("UUID"); // Save the list. - std::vector ::iterator u; - for (u = uuidList.begin (); u != uuidList.end (); ++u) - _uuid_list.push_back (*u); + for (auto& uuid : uuidList) + _uuid_list.push_back (uuid); } } } @@ -1528,12 +1490,11 @@ void CLI::insertIDExpr () bool changes = false; bool foundID = false; std::vector reconstructed; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("FILTER") && - (a->hasTag ("ID") || - a->hasTag ("UUID"))) + if (a.hasTag ("FILTER") && + (a.hasTag ("ID") || + a.hasTag ("UUID"))) { if (! foundID) { @@ -1576,8 +1537,7 @@ void CLI::insertIDExpr () reconstructed.push_back (openParen); // Add all ID ranges. - std::vector >::iterator r; - for (r = _id_ranges.begin (); r != _id_ranges.end (); ++r) + for (auto r = _id_ranges.begin (); r != _id_ranges.end (); ++r) { if (r != _id_ranges.begin ()) reconstructed.push_back (opOr); @@ -1628,8 +1588,7 @@ void CLI::insertIDExpr () reconstructed.push_back (opOr); // Add all UUID list items. - std::vector ::iterator u; - for (u = _uuid_list.begin (); u != _uuid_list.end (); ++u) + for (auto u = _uuid_list.begin (); u != _uuid_list.end (); ++u) { if (u != _uuid_list.begin ()) reconstructed.push_back (opOr); @@ -1654,7 +1613,7 @@ void CLI::insertIDExpr () // No 'else' which cause all other ID/UUID args to be eaten. } else - reconstructed.push_back (*a); + reconstructed.push_back (a); } if (changes) @@ -1671,9 +1630,8 @@ void CLI::desugarFilterPlainArgs () { bool changes = false; std::vector reconstructed; - std::vector ::iterator a; - std::vector ::iterator prev = _args.begin (); - for (a = _args.begin (); a != _args.end (); ++a) + auto prev = _args.begin (); + for (auto a = _args.begin (); a != _args.end (); ++a) { if (a != prev && // Not the first arg. ! prev->hasTag ("OP") && // An OP before protects the arg. @@ -1720,25 +1678,20 @@ void CLI::desugarFilterPlainArgs () //////////////////////////////////////////////////////////////////////////////// void CLI::findOperators () { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range ("operator"); - // Extract a list of entities for category. std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range ("operator"); + for (auto e = c.first; e != c.second; ++e) options.push_back (e->second); // Walk the arguments and tag as OP. bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) - if (a->hasTag ("FILTER")) - if (std::find (options.begin (), options.end (), a->attribute ("raw")) != options.end ()) - if (! a->hasTag ("OP")) + for (auto& a : _args) + if (a.hasTag ("FILTER")) + if (std::find (options.begin (), options.end (), a.attribute ("raw")) != options.end ()) + if (! a.hasTag ("OP")) { - a->tag ("OP"); + a.tag ("OP"); changes = true; } @@ -1750,25 +1703,20 @@ void CLI::findOperators () //////////////////////////////////////////////////////////////////////////////// void CLI::findAttributes () { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range ("attribute"); - // Extract a list of entities for category. std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range ("attribute"); + for (auto e = c.first; e != c.second; ++e) options.push_back (e->second); // Walk the arguments and tag as OP. bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) - if (a->hasTag ("FILTER")) - if (std::find (options.begin (), options.end (), a->attribute ("raw")) != options.end ()) - if (! a->hasTag ("ATTRIBUTE")) + for (auto& a : _args) + if (a.hasTag ("FILTER")) + if (std::find (options.begin (), options.end (), a.attribute ("raw")) != options.end ()) + if (! a.hasTag ("ATTRIBUTE")) { - a->tag ("ATTRIBUTE"); + a.tag ("ATTRIBUTE"); changes = true; } @@ -1790,9 +1738,8 @@ void CLI::insertJunctions () { bool changes = false; std::vector reconstructed; - std::vector ::iterator prev = _args.begin (); - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + auto prev = _args.begin (); + for (auto a = _args.begin (); a != _args.end (); ++a) { if (a->hasTag ("FILTER")) { @@ -1842,10 +1789,9 @@ void CLI::injectDefaults () bool found_sequence = false; bool found_terminator = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - std::string raw = a->attribute ("raw"); + std::string raw = a.attribute ("raw"); if (isTerminator (raw)) found_terminator = true; @@ -1875,16 +1821,15 @@ void CLI::injectDefaults () // Modify _args to be: [ ...] [...] std::vector reconstructed; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto a = _args.begin (); a != _args.end (); ++a) { reconstructed.push_back (*a); if (a == _args.begin ()) { - std::vector ::iterator t; - for (t = tokens.begin (); t != tokens.end (); ++t) + for (auto& token : tokens) { - A arg ("argDefault", *t); + A arg ("argDefault", token); arg.tag ("DEFAULT"); reconstructed.push_back (arg); } @@ -1917,16 +1862,15 @@ void CLI::injectDefaults () void CLI::decomposeModAttributes () { bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("TERMINATOR")) + if (a.hasTag ("TERMINATOR")) break; - if (a->hasTag ("MODIFICATION")) + if (a.hasTag ("MODIFICATION")) { // Look for a valid attribute name. - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string name; if (n.getName (name) && name.length ()) @@ -1945,25 +1889,24 @@ void CLI::decomposeModAttributes () std::string canonical; if (canonicalize (canonical, "uda", name)) { - a->attribute ("name", canonical); - a->attribute ("value", value); - a->tag ("UDA"); - a->tag ("MODIFIABLE"); + a.attribute ("name", canonical); + a.attribute ("value", value); + a.tag ("UDA"); + a.tag ("MODIFIABLE"); changes = true; } else if (canonicalize (canonical, "attribute", name)) { - a->attribute ("name", canonical); - a->attribute ("value", value); - a->tag ("ATTRIBUTE"); + a.attribute ("name", canonical); + a.attribute ("value", value); + a.tag ("ATTRIBUTE"); - std::map ::const_iterator col; - col = context.columns.find (canonical); + auto col = context.columns.find (canonical); if (col != context.columns.end () && col->second->modifiable ()) { - a->tag ("MODIFIABLE"); + a.tag ("MODIFIABLE"); } changes = true; @@ -1983,16 +1926,15 @@ void CLI::decomposeModAttributes () void CLI::decomposeModAttributeModifiers () { bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("TERMINATOR")) + if (a.hasTag ("TERMINATOR")) break; - if (a->hasTag ("MODIFICATION")) + if (a.hasTag ("MODIFICATION")) { // Look for a valid attribute name. - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string name; if (n.getUntil (".", name) && name.length ()) @@ -2025,29 +1967,28 @@ void CLI::decomposeModAttributeModifiers () std::string canonical; if (canonicalize (canonical, "uda", name)) { - a->attribute ("name", canonical); - a->attribute ("modifier", modifier); - a->attribute ("sense", sense); - a->attribute ("value", value); - a->tag ("UDA"); - a->tag ("MODIFIABLE"); + a.attribute ("name", canonical); + a.attribute ("modifier", modifier); + a.attribute ("sense", sense); + a.attribute ("value", value); + a.tag ("UDA"); + a.tag ("MODIFIABLE"); changes = true; } else if (canonicalize (canonical, "attribute", name)) { - a->attribute ("name", canonical); - a->attribute ("modifier", modifier); - a->attribute ("sense", sense); - a->attribute ("value", value); - a->tag ("ATTMOD"); + a.attribute ("name", canonical); + a.attribute ("modifier", modifier); + a.attribute ("sense", sense); + a.attribute ("value", value); + a.tag ("ATTMOD"); - std::map ::const_iterator col; - col = context.columns.find (canonical); + auto col = context.columns.find (canonical); if (col != context.columns.end () && col->second->modifiable ()) { - a->tag ("MODIFIABLE"); + a.tag ("MODIFIABLE"); } changes = true; @@ -2069,15 +2010,14 @@ void CLI::decomposeModAttributeModifiers () void CLI::decomposeModTags () { bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("TERMINATOR")) + if (a.hasTag ("TERMINATOR")) break; - if (a->hasTag ("MODIFICATION")) + if (a.hasTag ("MODIFICATION")) { - Nibbler n (a->attribute ("raw")); + Nibbler n (a.attribute ("raw")); std::string tag; std::string sign; @@ -2086,9 +2026,9 @@ void CLI::decomposeModTags () n.getUntilEOS (tag) && tag.find (' ') == std::string::npos) { - a->attribute ("name", tag); - a->attribute ("sign", sign); - a->tag ("TAG"); + a.attribute ("name", tag); + a.attribute ("sign", sign); + a.tag ("TAG"); changes = true; } } @@ -2103,15 +2043,14 @@ void CLI::decomposeModTags () void CLI::decomposeModSubstitutions () { bool changes = false; - std::vector ::iterator a; - for (a = _args.begin (); a != _args.end (); ++a) + for (auto& a : _args) { - if (a->hasTag ("TERMINATOR")) + if (a.hasTag ("TERMINATOR")) break; - if (a->hasTag ("MODIFICATION")) + if (a.hasTag ("MODIFICATION")) { - std::string raw = a->attribute ("raw"); + std::string raw = a.attribute ("raw"); Nibbler n (raw); std::string from; std::string to; @@ -2126,10 +2065,10 @@ void CLI::decomposeModSubstitutions () if (n.depleted () && ! Directory (raw).exists ()) { - a->tag ("SUBSTITUTION"); - a->attribute ("from", from); - a->attribute ("to", to); - a->attribute ("global", global ? 1 : 0); + a.tag ("SUBSTITUTION"); + a.attribute ("from", from); + a.attribute ("to", to); + a.attribute ("global", global ? 1 : 0); changes = true; } } @@ -2236,12 +2175,11 @@ bool CLI::isIDSequence (const std::string& raw) const std::vector elements; split (elements, raw, ','); - std::vector ::iterator e; - for (e = elements.begin (); e != elements.end (); ++e) + for (auto& e : elements) { // Split the ID range into min/max. std::vector terms; - split (terms, *e, '-'); + split (terms, e, '-'); if (terms.size () == 1 && ! isID (terms[0])) @@ -2340,14 +2278,10 @@ bool CLI::isAttribute (const std::string& raw) const //////////////////////////////////////////////////////////////////////////////// bool CLI::isOperator (const std::string& raw) const { - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range ("operator"); - // Walk the list of entities for category. std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) + auto c = _entities.equal_range ("operator"); + for (auto e = c.first; e != c.second; ++e) if (raw == e->second) return true; @@ -2385,9 +2319,8 @@ bool CLI::disqualifyNoOps ( const std::vector >& lexemes) const { bool foundOP = false; - std::vector >::const_iterator l; - for (l = lexemes.begin (); l != lexemes.end (); ++l) - if (l->second == Lexer::Type::op) + for (auto& lexeme : lexemes) + if (lexeme.second == Lexer::Type::op) foundOP = true; return ! foundOP; @@ -2401,25 +2334,24 @@ bool CLI::disqualifyOnlyParenOps ( int opSugarCount = 0; int opParenCount = 0; - std::vector >::const_iterator l; - for (l = lexemes.begin (); l != lexemes.end (); ++l) + for (auto& lexeme : lexemes) { - if (l->second == Lexer::Type::op) + if (lexeme.second == Lexer::Type::op) { ++opCount; - if (l->first == "(" || - l->first == ")") + if (lexeme.first == "(" || + lexeme.first == ")") ++opParenCount; } - else if (isTag (l->first) || - isUUIDList (l->first) || - isUUID (l->first) || - isIDSequence (l->first) || - isID (l->first) || - isPattern (l->first) || - isAttribute (l->first)) + else if (isTag (lexeme.first) || + isUUIDList (lexeme.first) || + isUUID (lexeme.first) || + isIDSequence (lexeme.first) || + isID (lexeme.first) || + isPattern (lexeme.first) || + isAttribute (lexeme.first)) ++opSugarCount; } diff --git a/src/Color.cpp b/src/Color.cpp index 4a9f891ae..e40392b37 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -119,10 +119,9 @@ Color::Color (const std::string& spec) bool bg = false; int index; std::string word; - std::vector ::iterator it; - for (it = words.begin (); it != words.end (); ++it) + for (auto& it : words) { - word = lowerCase (trim (*it)); + word = lowerCase (trim (it)); if (word == "bold") fg_value |= _COLOR_BOLD; else if (word == "bright") bg_value |= _COLOR_BRIGHT; @@ -154,7 +153,7 @@ Color::Color (const std::string& spec) { index = atoi (word.substr (4).c_str ()); if (index < 0 || index > 23) - throw format (STRING_COLOR_UNRECOGNIZED, *it); + throw format (STRING_COLOR_UNRECOGNIZED, it); if (bg) { @@ -176,7 +175,7 @@ Color::Color (const std::string& spec) index = atoi (word.substr (3).c_str ()); if (word.length () != 6 || index < 0 || index > 555) - throw format (STRING_COLOR_UNRECOGNIZED, *it); + throw format (STRING_COLOR_UNRECOGNIZED, it); int r = atoi (word.substr (3, 1).c_str ()); int g = atoi (word.substr (4, 1).c_str ()); @@ -184,7 +183,7 @@ Color::Color (const std::string& spec) if (r < 0 || r > 5 || g < 0 || g > 5 || b < 0 || b > 5) - throw format (STRING_COLOR_UNRECOGNIZED, *it); + throw format (STRING_COLOR_UNRECOGNIZED, it); index = 16 + r*36 + g*6 + b; @@ -207,7 +206,7 @@ Color::Color (const std::string& spec) { index = atoi (word.substr (5).c_str ()); if (index < 0 || index > 255) - throw format (STRING_COLOR_UNRECOGNIZED, *it); + throw format (STRING_COLOR_UNRECOGNIZED, it); upgrade (); @@ -225,7 +224,7 @@ Color::Color (const std::string& spec) } } else if (word != "") - throw format (STRING_COLOR_UNRECOGNIZED, *it); + throw format (STRING_COLOR_UNRECOGNIZED, it); } // Now combine the fg and bg into a single color. diff --git a/src/Config.cpp b/src/Config.cpp index f4132b385..3a79538d0 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -528,11 +528,8 @@ void Config::parse (const std::string& input, int nest /* = 1 */) split (lines, input, "\n"); // Parse each line. - std::vector ::iterator it; - for (it = lines.begin (); it != lines.end (); ++it) + for (auto& line : lines) { - std::string line = *it; - // Remove comments. std::string::size_type pound = line.find ("#"); // no i18n if (pound != std::string::npos) @@ -714,9 +711,8 @@ void Config::set (const std::string& key, const std::string& value) // Provide a vector of all configuration keys. void Config::all (std::vector& items) const { - std::map ::const_iterator it; - for (it = this->begin (); it != this->end (); ++it) - items.push_back (it->first); + for (auto& it : *this) + items.push_back (it.first); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Context.cpp b/src/Context.cpp index 40af3db21..91979dc77 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -84,13 +84,11 @@ Context::Context () //////////////////////////////////////////////////////////////////////////////// Context::~Context () { - std::map::iterator com; - for (com = commands.begin (); com != commands.end (); ++com) - delete com->second; + for (auto& com : commands) + delete com.second; - std::map::iterator col; - for (col = columns.begin (); col != columns.end (); ++col) - delete col->second; + for (auto& col : columns) + delete col.second; } //////////////////////////////////////////////////////////////////////////////// @@ -156,14 +154,13 @@ int Context::initialize (int argc, const char** argv) //////////////////////////////////////////////////////////////////////////// Command::factory (commands); - std::map ::iterator cmd; - for (cmd = commands.begin (); cmd != commands.end (); ++cmd) + for (auto& cmd : commands) { - cli.entity ("cmd", cmd->first); - cli.entity ((cmd->second->read_only () ? "readcmd" : "writecmd"), cmd->first); + cli.entity ("cmd", cmd.first); + cli.entity ((cmd.second->read_only () ? "readcmd" : "writecmd"), cmd.first); - if (cmd->first[0] == '_') - cli.entity ("helper", cmd->first); + if (cmd.first[0] == '_') + cli.entity ("helper", cmd.first); } //////////////////////////////////////////////////////////////////////////// @@ -173,9 +170,8 @@ int Context::initialize (int argc, const char** argv) //////////////////////////////////////////////////////////////////////////// Column::factory (columns); - std::map ::iterator col; - for (col = columns.begin (); col != columns.end (); ++col) - cli.entity ("attribute", col->first); + for (auto& col : columns) + cli.entity ("attribute", col.first); cli.entity ("pseudo", "limit"); @@ -188,15 +184,11 @@ int Context::initialize (int argc, const char** argv) for (unsigned int i = 0; i < NUM_MODIFIER_NAMES; ++i) cli.entity ("modifier", modifierNames[i]); - std::vector operators; - Eval::getOperators (operators); - std::vector ::iterator op; - for (op = operators.begin (); op != operators.end (); ++op) - cli.entity ("operator", *op); + for (auto& op : Eval::getOperators ()) + cli.entity ("operator", op); - Eval::getBinaryOperators (operators); - for (op = operators.begin (); op != operators.end (); ++op) - cli.entity ("binary_operator", *op); + for (auto& op : Eval::getBinaryOperators ()) + cli.entity ("binary_operator", op); //////////////////////////////////////////////////////////////////////////// // @@ -223,21 +215,20 @@ int Context::initialize (int argc, const char** argv) bool foundDefault = false; bool foundAssumed = false; std::string combined; - std::vector ::const_iterator a; - for (a = cli._args.begin (); a != cli._args.end (); ++a) + for (auto& a : cli._args) { if (combined.length ()) combined += ' '; - if (a->attribute ("canonical") != "") - combined += a->attribute ("canonical"); + if (a.attribute ("canonical") != "") + combined += a.attribute ("canonical"); else - combined += a->attribute ("raw"); + combined += a.attribute ("raw"); - if (a->hasTag ("DEFAULT")) + if (a.hasTag ("DEFAULT")) foundDefault = true; - if (a->hasTag ("ASSUMED")) + if (a.hasTag ("ASSUMED")) foundAssumed = true; } @@ -280,44 +271,40 @@ int Context::initialize (int argc, const char** argv) // Dump all debug messages, controlled by rc.debug. if (config.getBoolean ("debug")) { - std::vector ::iterator d; - for (d = debugMessages.begin (); d != debugMessages.end (); ++d) + for (auto& d : debugMessages) if (color ()) - std::cerr << colorizeDebug (*d) << "\n"; + std::cerr << colorizeDebug (d) << "\n"; else - std::cerr << *d << "\n"; + std::cerr << d << "\n"; } // Dump all headers, controlled by 'header' verbosity token. if (verbose ("header")) { - std::vector ::iterator h; - for (h = headers.begin (); h != headers.end (); ++h) + for (auto& h : headers) if (color ()) - std::cerr << colorizeHeader (*h) << "\n"; + std::cerr << colorizeHeader (h) << "\n"; else - std::cerr << *h << "\n"; + std::cerr << h << "\n"; } // Dump all footnotes, controlled by 'footnote' verbosity token. if (verbose ("footnote")) { - std::vector ::iterator f; - for (f = footnotes.begin (); f != footnotes.end (); ++f) + for (auto& f : footnotes) if (color ()) - std::cerr << colorizeFootnote (*f) << "\n"; + std::cerr << colorizeFootnote (f) << "\n"; else - std::cerr << *f << "\n"; + std::cerr << f << "\n"; } // Dump all errors, non-maskable. // Colorized as footnotes. - std::vector ::iterator e; - for (e = errors.begin (); e != errors.end (); ++e) + for (auto& e : errors) if (color ()) - std::cerr << colorizeFootnote (*e) << "\n"; + std::cerr << colorizeFootnote (e) << "\n"; else - std::cerr << *e << "\n"; + std::cerr << e << "\n"; } timer_init.stop (); @@ -390,23 +377,21 @@ int Context::run () // Dump all debug messages, controlled by rc.debug. if (config.getBoolean ("debug")) { - std::vector ::iterator d; - for (d = debugMessages.begin (); d != debugMessages.end (); ++d) + for (auto& d : debugMessages) if (color ()) - std::cerr << colorizeDebug (*d) << "\n"; + std::cerr << colorizeDebug (d) << "\n"; else - std::cerr << *d << "\n"; + std::cerr << d << "\n"; } // Dump all headers, controlled by 'header' verbosity token. if (verbose ("header")) { - std::vector ::iterator h; - for (h = headers.begin (); h != headers.end (); ++h) + for (auto& h : headers) if (color ()) - std::cerr << colorizeHeader (*h) << "\n"; + std::cerr << colorizeHeader (h) << "\n"; else - std::cerr << *h << "\n"; + std::cerr << h << "\n"; } // Dump the report output. @@ -415,22 +400,20 @@ int Context::run () // Dump all footnotes, controlled by 'footnote' verbosity token. if (verbose ("footnote")) { - std::vector ::iterator f; - for (f = footnotes.begin (); f != footnotes.end (); ++f) + for (auto& f : footnotes) if (color ()) - std::cerr << colorizeFootnote (*f) << "\n"; + std::cerr << colorizeFootnote (f) << "\n"; else - std::cerr << *f << "\n"; + std::cerr << f << "\n"; } // Dump all errors, non-maskable. // Colorized as footnotes. - std::vector ::iterator e; - for (e = errors.begin (); e != errors.end (); ++e) + for (auto& e : errors) if (color ()) - std::cerr << colorizeError (*e) << "\n"; + std::cerr << colorizeError (e) << "\n"; else - std::cerr << *e << "\n"; + std::cerr << e << "\n"; return rc; } @@ -581,9 +564,8 @@ bool Context::verbose (const std::string& token) const std::vector Context::getColumns () const { std::vector output; - std::map ::const_iterator i; - for (i = columns.begin (); i != columns.end (); ++i) - output.push_back (i->first); + for (auto& col : columns) + output.push_back (col.first); return output; } @@ -592,9 +574,8 @@ const std::vector Context::getColumns () const const std::vector Context::getCommands () const { std::vector output; - std::map ::const_iterator i; - for (i = commands.begin (); i != commands.end (); ++i) - output.push_back (i->first); + for (auto& cmd : commands) + output.push_back (cmd.first); return output; } @@ -640,24 +621,22 @@ void Context::staticInitialization () Lexer::dateFormat = Variant::dateFormat = config.get ("dateformat"); Lexer::isoEnabled = Variant::isoEnabled = config.getBoolean ("date.iso"); - Config::const_iterator rc; - for (rc = config.begin (); rc != config.end (); ++rc) + for (auto& rc : config) { - if (rc->first.substr (0, 4) == "uda." && - rc->first.substr (rc->first.length () - 7, 7) == ".values") + if (rc.first.substr (0, 4) == "uda." && + rc.first.substr (rc.first.length () - 7, 7) == ".values") { - std::string name = rc->first.substr (4, rc->first.length () - 7 - 4); + std::string name = rc.first.substr (4, rc.first.length () - 7 - 4); std::vector values; - split (values, rc->second, ','); + split (values, rc.second, ','); for (auto r = values.rbegin(); r != values.rend (); ++r) Task::customOrder[name].push_back (*r); } } - std::map ::iterator i; - for (i = columns.begin (); i != columns.end (); ++i) - Task::attributes[i->first] = i->second->type (); + for (auto& col : columns) + Task::attributes[col.first] = col.second->type (); Task::urgencyProjectCoefficient = config.getReal ("urgency.project.coefficient"); Task::urgencyActiveCoefficient = config.getReal ("urgency.active.coefficient"); @@ -676,11 +655,10 @@ void Context::staticInitialization () // Tag- and project-specific coefficients. std::vector all; config.all (all); - std::vector ::iterator var; - for (var = all.begin (); var != all.end (); ++var) - if (var->substr (0, 13) == "urgency.user." || - var->substr (0, 12) == "urgency.uda.") - Task::coefficients[*var] = config.getReal (*var); + for (auto& var : all) + if (var.substr (0, 13) == "urgency.user." || + var.substr (0, 12) == "urgency.uda.") + Task::coefficients[var] = config.getReal (var); } //////////////////////////////////////////////////////////////////////////////// @@ -745,16 +723,14 @@ void Context::clear () tdb2.clear (); // Eliminate the command objects. - std::map ::iterator com; - for (com = commands.begin (); com != commands.end (); ++com) - delete com->second; + for (auto& cmd : commands) + delete cmd.second; commands.clear (); // Eliminate the column objects. - std::map ::iterator col; - for (col = columns.begin (); col != columns.end (); ++col) - delete col->second; + for (auto& col : columns) + delete col.second; columns.clear (); clearMessages (); @@ -770,8 +746,7 @@ void Context::updateXtermTitle () std::string command = cli.getCommand (); std::string title; - std::vector ::const_iterator a; - for (a = cli._args.begin (); a != cli._args.end (); ++a) + for (auto a = cli._args.begin (); a != cli._args.end (); ++a) { if (a != cli._args.begin ()) title += ' '; @@ -799,10 +774,9 @@ void Context::updateVerbosity () //////////////////////////////////////////////////////////////////////////////// void Context::loadAliases () { - std::map ::iterator i; - for (i = config.begin (); i != config.end (); ++i) - if (i->first.substr (0, 6) == "alias.") - cli.alias (i->first.substr (6), i->second); + for (auto& i : config) + if (i.first.substr (0, 6) == "alias.") + cli.alias (i.first.substr (6), i.second); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/DOM.cpp b/src/DOM.cpp index e1e07d6e1..531443a9f 100644 --- a/src/DOM.cpp +++ b/src/DOM.cpp @@ -88,7 +88,7 @@ bool DOM::get (const std::string& name, Variant& value) name.substr (0, 3) == "rc.") { std::string key = name.substr (3); - std::map ::iterator c = context.config.find (key); + auto c = context.config.find (key); if (c != context.config.end ()) { value = Variant (c->second); @@ -376,8 +376,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value) int count = 0; // Count off the 'a'th annotation. - std::map ::iterator i; - for (i = annos.begin (); i != annos.end (); ++i) + for (auto& i : annos) { if (++count == a) { @@ -385,12 +384,12 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value) { // annotation_1234567890 // 0 ^11 - value = Variant ((time_t) strtol (i->first.substr (11).c_str (), NULL, 10), Variant::type_date); + value = Variant ((time_t) strtol (i.first.substr (11).c_str (), NULL, 10), Variant::type_date); return true; } else if (elements[3] == "description") { - value = Variant (i->second); + value = Variant (i.second); return true; } } @@ -405,8 +404,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value) int count = 0; // Count off the 'a'th annotation. - std::map ::iterator i; - for (i = annos.begin (); i != annos.end (); ++i) + for (auto& i : annos) { if (++count == a) { @@ -419,7 +417,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value) // ..entry.hour // ..entry.minute // ..entry.second - Date date (i->first.substr (11)); + Date date (i.first.substr (11)); if (elements[4] == "year") { value = Variant (static_cast (date.year ())); return true; } else if (elements[4] == "month") { value = Variant (static_cast (date.month ())); return true; } else if (elements[4] == "day") { value = Variant (static_cast (date.day ())); return true; } diff --git a/src/Date.cpp b/src/Date.cpp index fe8f9f26e..256d52653 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -536,10 +536,9 @@ int Date::length (const std::string& format) { int total = 0; - std::string::const_iterator i; - for (i = format.begin (); i != format.end (); ++i) + for (auto& i : format) { - switch (*i) + switch (i) { case 'm': case 'M': @@ -563,7 +562,7 @@ int Date::length (const std::string& format) case 'B': total += 10; break; // Calculate the width, don't assume a single character width. - default: total += mk_wcwidth (*i); break; + default: total += mk_wcwidth (i); break; } } diff --git a/src/Eval.cpp b/src/Eval.cpp index 756a5c77c..8c9fe55f4 100644 --- a/src/Eval.cpp +++ b/src/Eval.cpp @@ -217,21 +217,25 @@ void Eval::debug (bool value) //////////////////////////////////////////////////////////////////////////////// // Static. -void Eval::getOperators (std::vector & all) +std::vector Eval::getOperators () { - all.clear (); + std::vector all; for (unsigned int i = 0; i < NUM_OPERATORS; ++i) all.push_back (operators[i].op); + + return all; } //////////////////////////////////////////////////////////////////////////////// // Static. -void Eval::getBinaryOperators (std::vector & all) +std::vector Eval::getBinaryOperators () { - all.clear (); + std::vector all; for (unsigned int i = 0; i < NUM_OPERATORS; ++i) if (operators[i].type == 'b') all.push_back (operators[i].op); + + return all; } //////////////////////////////////////////////////////////////////////////////// @@ -245,12 +249,11 @@ void Eval::evaluatePostfixStack ( // This is stack used by the postfix evaluator. std::vector values; - std::vector >::const_iterator token; - for (token = tokens.begin (); token != tokens.end (); ++token) + for (auto& token : tokens) { // Unary operators. - if (token->second == Lexer::Type::op && - token->first == "!") + if (token.second == Lexer::Type::op && + token.first == "!") { if (values.size () < 1) throw std::string (STRING_EVAL_NO_EVAL); @@ -260,10 +263,10 @@ void Eval::evaluatePostfixStack ( Variant result = ! right; values.push_back (result); if (_debug) - context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token->first, (std::string) right, (std::string) result)); + context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result)); } - else if (token->second == Lexer::Type::op && - token->first == "_neg_") + else if (token.second == Lexer::Type::op && + token.first == "_neg_") { if (values.size () < 1) throw std::string (STRING_EVAL_NO_EVAL); @@ -276,18 +279,18 @@ void Eval::evaluatePostfixStack ( values.push_back (result); if (_debug) - context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token->first, (std::string) right, (std::string) result)); + context.debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result)); } - else if (token->second == Lexer::Type::op && - token->first == "_pos_") + else if (token.second == Lexer::Type::op && + token.first == "_pos_") { // The _pos_ operator is a NOP. if (_debug) - context.debug (format ("[{1}] eval op {2} NOP", values.size (), token->first)); + context.debug (format ("[{1}] eval op {2} NOP", values.size (), token.first)); } // Binary operators. - else if (token->second == Lexer::Type::op) + else if (token.second == Lexer::Type::op) { if (values.size () < 2) throw std::string (STRING_EVAL_NO_EVAL); @@ -300,46 +303,46 @@ void Eval::evaluatePostfixStack ( // Ordering these by anticipation frequency of use is a good idea. Variant result; - if (token->first == "and") result = left && right; - else if (token->first == "or") result = left || right; - else if (token->first == "&&") result = left && right; - else if (token->first == "||") result = left || right; - else if (token->first == "<") result = left < right; - else if (token->first == "<=") result = left <= right; - else if (token->first == ">") result = left > right; - else if (token->first == ">=") result = left >= right; - else if (token->first == "==") result = left.operator== (right); - else if (token->first == "!==") result = left.operator!= (right); - else if (token->first == "=") result = left.operator_partial (right); - else if (token->first == "!=") result = left.operator_nopartial (right); - else if (token->first == "+") result = left + right; - else if (token->first == "-") result = left - right; - else if (token->first == "*") result = left * right; - else if (token->first == "/") result = left / right; - else if (token->first == "^") result = left ^ right; - else if (token->first == "%") result = left % right; - else if (token->first == "xor") result = left.operator_xor (right); - else if (token->first == "~") result = left.operator_match (right, contextTask); - else if (token->first == "!~") result = left.operator_nomatch (right, contextTask); - else if (token->first == "_hastag_") result = left.operator_hastag (right, contextTask); - else if (token->first == "_notag_") result = left.operator_notag (right, contextTask); + if (token.first == "and") result = left && right; + else if (token.first == "or") result = left || right; + else if (token.first == "&&") result = left && right; + else if (token.first == "||") result = left || right; + else if (token.first == "<") result = left < right; + else if (token.first == "<=") result = left <= right; + else if (token.first == ">") result = left > right; + else if (token.first == ">=") result = left >= right; + else if (token.first == "==") result = left.operator== (right); + else if (token.first == "!==") result = left.operator!= (right); + else if (token.first == "=") result = left.operator_partial (right); + else if (token.first == "!=") result = left.operator_nopartial (right); + else if (token.first == "+") result = left + right; + else if (token.first == "-") result = left - right; + else if (token.first == "*") result = left * right; + else if (token.first == "/") result = left / right; + else if (token.first == "^") result = left ^ right; + else if (token.first == "%") result = left % right; + else if (token.first == "xor") result = left.operator_xor (right); + else if (token.first == "~") result = left.operator_match (right, contextTask); + else if (token.first == "!~") result = left.operator_nomatch (right, contextTask); + else if (token.first == "_hastag_") result = left.operator_hastag (right, contextTask); + else if (token.first == "_notag_") result = left.operator_notag (right, contextTask); else - throw format (STRING_EVAL_UNSUPPORTED, token->first); + throw format (STRING_EVAL_UNSUPPORTED, token.first); values.push_back (result); if (_debug) - context.debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", (std::string) left, token->first, (std::string) right, (std::string) result)); + context.debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", (std::string) left, token.first, (std::string) right, (std::string) result)); } // Literals and identifiers. else { - Variant v (token->first); - switch (token->second) + Variant v (token.first); + switch (token.second) { case Lexer::Type::number: - if (Lexer::isAllDigits (token->first)) + if (Lexer::isAllDigits (token.first)) { v.cast (Variant::type_integer); if (_debug) @@ -362,13 +365,12 @@ void Eval::evaluatePostfixStack ( case Lexer::Type::identifier: { bool found = false; - std::vector ::const_iterator source; - for (source = _sources.begin (); source != _sources.end (); ++source) + for (auto source = _sources.begin (); source != _sources.end (); ++source) { - if ((*source) (token->first, v)) + if ((*source) (token.first, v)) { if (_debug) - context.debug (format ("Eval identifier source '{1}' → ↑'{2}'", token->first, (std::string) v)); + context.debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, (std::string) v)); found = true; break; } @@ -379,7 +381,7 @@ void Eval::evaluatePostfixStack ( { v.cast (Variant::type_string); if (_debug) - context.debug (format ("Eval identifier source failed '{1}'", token->first)); + context.debug (format ("Eval identifier source failed '{1}'", token.first)); } } break; @@ -707,8 +709,7 @@ bool Eval::parsePrimitive ( else { bool found = false; - std::vector ::const_iterator source; - for (source = _sources.begin (); source != _sources.end (); ++source) + for (auto source = _sources.begin (); source != _sources.end (); ++source) { Variant v; if ((*source) (infix[i].first, v)) @@ -784,16 +785,15 @@ void Eval::infixToPostfix ( unsigned int precedence; char associativity; - std::vector >::iterator token; - for (token = infix.begin (); token != infix.end (); ++token) + for (auto& token : infix) { - if (token->second == Lexer::Type::op && - token->first == "(") + if (token.second == Lexer::Type::op && + token.first == "(") { - op_stack.push_back (*token); + op_stack.push_back (token); } - else if (token->second == Lexer::Type::op && - token->first == ")") + else if (token.second == Lexer::Type::op && + token.first == ")") { while (op_stack.size () && op_stack.back ().first != "(") @@ -807,8 +807,8 @@ void Eval::infixToPostfix ( else throw std::string ("Mismatched parentheses in expression"); } - else if (token->second == Lexer::Type::op && - identifyOperator (token->first, type, precedence, associativity)) + else if (token.second == Lexer::Type::op && + identifyOperator (token.first, type, precedence, associativity)) { char type2; unsigned int precedence2; @@ -822,11 +822,11 @@ void Eval::infixToPostfix ( op_stack.pop_back (); } - op_stack.push_back (*token); + op_stack.push_back (token); } else { - postfix.push_back (*token); + postfix.push_back (token); } } @@ -880,8 +880,7 @@ std::string Eval::dump ( color_map[Lexer::Type::duration] = Color ("rgb531 on gray6"); std::string output; - std::vector >::const_iterator i; - for (i = tokens.begin (); i != tokens.end (); ++i) + for (auto i = tokens.begin (); i != tokens.end (); ++i) { if (i != tokens.begin ()) output += ' '; diff --git a/src/Eval.h b/src/Eval.h index 5b56cc191..fd44184d1 100644 --- a/src/Eval.h +++ b/src/Eval.h @@ -49,8 +49,8 @@ public: void ambiguity (bool); void debug (bool); - static void getOperators (std::vector &); - static void getBinaryOperators (std::vector &); + static std::vector getOperators (); + static std::vector getBinaryOperators (); private: void evaluatePostfixStack (const std::vector >&, Variant&) const; diff --git a/src/File.cpp b/src/File.cpp index 86ed71bb9..021dc2160 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -244,9 +244,8 @@ void File::write (const std::vector & lines) if (_fh) { - std::vector ::const_iterator it; - for (it = lines.begin (); it != lines.end (); ++it) - fputs (it->c_str (), _fh); + for (auto& line : lines) + fputs (line.c_str (), _fh); } } @@ -274,9 +273,8 @@ void File::append (const std::vector & lines) if (_fh) { fseek (_fh, 0, SEEK_END); - std::vector ::const_iterator it; - for (it = lines.begin (); it != lines.end (); ++it) - fputs (((*it) + "\n").c_str (), _fh); + for (auto& line : lines) + fputs ((line + "\n").c_str (), _fh); } } @@ -458,10 +456,9 @@ bool File::write ( std::ios_base::out | std::ios_base::trunc); if (out.good ()) { - std::vector ::const_iterator it; - for (it = lines.begin (); it != lines.end (); ++it) + for (auto& line : lines) { - out << *it; + out << line; if (addNewlines) out << "\n"; @@ -499,10 +496,9 @@ bool File::append ( std::ios_base::out | std::ios_base::app); if (out.good ()) { - std::vector ::const_iterator it; - for (it = lines.begin (); it != lines.end (); ++it) + for (auto& line : lines) { - out << *it; + out << line; if (addNewlines) out << "\n"; diff --git a/src/Filter.cpp b/src/Filter.cpp index 0f3cd265f..e2246c573 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -89,16 +89,15 @@ void Filter::subset (const std::vector & input, std::vector & output eval.compileExpression (filterExpr); eval.debug (false); - std::vector ::const_iterator task; - for (task = input.begin (); task != input.end (); ++task) + for (auto& task : input) { // Set up context for any DOM references. - contextTask = *task; + contextTask = task; Variant var; eval.evaluateCompiledExpression (var); if (var.get_bool ()) - output.push_back (*task); + output.push_back (task); } } else @@ -123,7 +122,7 @@ void Filter::subset (std::vector & output, bool applyContext /* = true */) if (filterExpr.length ()) { context.timer_filter.stop (); - const std::vector & pending = context.tdb2.pending.get_tasks (); + auto pending = context.tdb2.pending.get_tasks (); context.timer_filter.start (); _startCount = (int) pending.size (); @@ -139,58 +138,53 @@ void Filter::subset (std::vector & output, bool applyContext /* = true */) eval.debug (false); output.clear (); - std::vector ::const_iterator task; - - for (task = pending.begin (); task != pending.end (); ++task) + for (auto& task : pending) { // Set up context for any DOM references. - contextTask = *task; + contextTask = task; Variant var; eval.debug (context.config.getInteger ("debug.parser") >= 2 ? true : false); eval.evaluateCompiledExpression (var); eval.debug (false); if (var.get_bool ()) - output.push_back (*task); + output.push_back (task); } shortcut = pendingOnly (); if (! shortcut) { context.timer_filter.stop (); - const std::vector & completed = context.tdb2.completed.get_tasks (); + auto completed = context.tdb2.completed.get_tasks (); context.timer_filter.start (); _startCount += (int) completed.size (); - for (task = completed.begin (); task != completed.end (); ++task) + for (auto& task : completed) { // Set up context for any DOM references. - contextTask = *task; + contextTask = task; Variant var; eval.debug (context.config.getInteger ("debug.parser") >= 2 ? true : false); eval.evaluateCompiledExpression (var); eval.debug (false); if (var.get_bool ()) - output.push_back (*task); + output.push_back (task); } } } else { safety (); - context.timer_filter.stop (); - const std::vector & pending = context.tdb2.pending.get_tasks (); - const std::vector & completed = context.tdb2.completed.get_tasks (); + + for (auto& task : context.tdb2.pending.get_tasks ()) + output.push_back (task); + + for (auto& task : context.tdb2.completed.get_tasks ()) + output.push_back (task); + context.timer_filter.start (); - - std::vector ::const_iterator task; - for (task = pending.begin (); task != pending.end (); ++task) - output.push_back (*task); - - for (task = completed.begin (); task != completed.end (); ++task) - output.push_back (*task); } _endCount = (int) output.size (); @@ -218,19 +212,18 @@ bool Filter::pendingOnly () int countXor = 0; int countNot = 0; - std::vector ::iterator a; - for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a) + for (auto& a : context.cli._args) { - if (a->hasTag ("FILTER")) + if (a.hasTag ("FILTER")) { - if (a->hasTag ("ID")) ++countId; - if (a->hasTag ("OP") && a->attribute ("raw") == "or") ++countOr; - if (a->hasTag ("OP") && a->attribute ("raw") == "xor") ++countXor; - if (a->hasTag ("OP") && a->attribute ("raw") == "not") ++countNot; - if (a->hasTag ("ATTRIBUTE") && a->attribute ("name") == "status") ++countStatus; - if ( a->attribute ("raw") == "pending") ++countPending; - if ( a->attribute ("raw") == "waiting") ++countWaiting; - if ( a->attribute ("raw") == "recurring") ++countRecurring; + if (a.hasTag ("ID")) ++countId; + if (a.hasTag ("OP") && a.attribute ("raw") == "or") ++countOr; + if (a.hasTag ("OP") && a.attribute ("raw") == "xor") ++countXor; + if (a.hasTag ("OP") && a.attribute ("raw") == "not") ++countNot; + if (a.hasTag ("ATTRIBUTE") && a.attribute ("name") == "status") ++countStatus; + if ( a.attribute ("raw") == "pending") ++countPending; + if ( a.attribute ("raw") == "waiting") ++countWaiting; + if ( a.attribute ("raw") == "recurring") ++countRecurring; } } @@ -258,12 +251,11 @@ bool Filter::pendingOnly () // all tasks to be modified. This is usually not intended. void Filter::safety () { - std::vector ::iterator a; - for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a) + for (auto& a : context.cli._args) { - if (a->hasTag ("CMD")) + if (a.hasTag ("CMD")) { - if (a->hasTag ("WRITECMD")) + if (a.hasTag ("WRITECMD")) { if (context.cli.getFilter () == "") { diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 6d9fef7cc..84c790c67 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -73,18 +73,17 @@ void Hooks::initialize () if (_debug >= 1) { - std::vector ::iterator i; - for (i = _scripts.begin (); i != _scripts.end (); ++i) + for (auto& i : _scripts) { - Path p (*i); + Path p (i); std::string name = p.name (); if (name.substr (0, 6) == "on-add" || name.substr (0, 9) == "on-modify" || name.substr (0, 9) == "on-launch" || name.substr (0, 7) == "on-exit") - context.debug ("Found hook script " + *i); + context.debug ("Found hook script " + i); else - context.debug ("Found misnamed hook script " + *i); + context.debug ("Found misnamed hook script " + i); } } } @@ -124,12 +123,11 @@ void Hooks::onLaunch () std::vector matchingScripts = scripts ("on-launch"); if (matchingScripts.size ()) { - std::vector ::iterator script; - for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script) + for (auto& script : matchingScripts) { std::vector input; std::vector output; - int status = callHookScript (*script, input, output); + int status = callHookScript (script, input, output); std::vector outputJSON; std::vector outputFeedback; @@ -139,17 +137,14 @@ void Hooks::onLaunch () if (status == 0) { - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.footnote (*message); + for (auto& message : outputFeedback) + context.footnote (message); } else { assertFeedback (outputFeedback); - - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.error (*message); + for (auto& message : outputFeedback) + context.error (message); throw 0; // This is how hooks silently terminate processing. } @@ -187,16 +182,14 @@ void Hooks::onExit () // Convert to a vector of strings. std::vector input; - std::vector ::const_iterator t; - for (t = tasks.begin (); t != tasks.end (); ++t) - input.push_back (t->composeJSON ()); + for (auto& t : tasks) + input.push_back (t.composeJSON ()); // Call the hook scripts, with the invariant input. - std::vector ::iterator script; - for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script) + for (auto& script : matchingScripts) { std::vector output; - int status = callHookScript (*script, input, output); + int status = callHookScript (script, input, output); std::vector outputJSON; std::vector outputFeedback; @@ -206,17 +199,14 @@ void Hooks::onExit () if (status == 0) { - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.footnote (*message); + for (auto& message : outputFeedback) + context.footnote (message); } else { assertFeedback (outputFeedback); - - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.error (*message); + for (auto& message : outputFeedback) + context.error (message); throw 0; // This is how hooks silently terminate processing. } @@ -253,11 +243,10 @@ void Hooks::onAdd (Task& task) input.push_back (task.composeJSON ()); // Call the hook scripts. - std::vector ::iterator script; - for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script) + for (auto& script : matchingScripts) { std::vector output; - int status = callHookScript (*script, input, output); + int status = callHookScript (script, input, output); std::vector outputJSON; std::vector outputFeedback; @@ -272,17 +261,14 @@ void Hooks::onAdd (Task& task) // Propagate forward to the next script. input[0] = outputJSON[0]; - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.footnote (*message); + for (auto& message : outputFeedback) + context.footnote (message); } else { assertFeedback (outputFeedback); - - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.error (*message); + for (auto& message : outputFeedback) + context.error (message); throw 0; // This is how hooks silently terminate processing. } @@ -324,11 +310,10 @@ void Hooks::onModify (const Task& before, Task& after) input.push_back (after.composeJSON ()); // [line 1] modified // Call the hook scripts. - std::vector ::iterator script; - for (script = matchingScripts.begin (); script != matchingScripts.end (); ++script) + for (auto& script : matchingScripts) { std::vector output; - int status = callHookScript (*script, input, output); + int status = callHookScript (script, input, output); std::vector outputJSON; std::vector outputFeedback; @@ -343,17 +328,14 @@ void Hooks::onModify (const Task& before, Task& after) // Propagate accepted changes forward to the next script. input[1] = outputJSON[0]; - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.footnote (*message); + for (auto& message : outputFeedback) + context.footnote (message); } else { assertFeedback (outputFeedback); - - std::vector ::iterator message; - for (message = outputFeedback.begin (); message != outputFeedback.end (); ++message) - context.error (*message); + for (auto& message : outputFeedback) + context.error (message); throw 0; // This is how hooks silently terminate processing. } @@ -375,14 +357,13 @@ std::vector Hooks::list () std::vector Hooks::scripts (const std::string& event) { std::vector matching; - std::vector ::iterator i; - for (i = _scripts.begin (); i != _scripts.end (); ++i) + for (auto& i : _scripts) { - if (i->find ("/" + event) != std::string::npos) + if (i.find ("/" + event) != std::string::npos) { - File script (*i); + File script (i); if (script.executable ()) - matching.push_back (*i); + matching.push_back (i); } } @@ -395,13 +376,12 @@ void Hooks::separateOutput ( std::vector & json, std::vector & feedback) const { - std::vector ::const_iterator i; - for (i = output.begin (); i != output.end (); ++i) + for (auto& i : output) { - if (isJSON (*i)) - json.push_back (*i); + if (isJSON (i)) + json.push_back (i); else - feedback.push_back (*i); + feedback.push_back (i); } } @@ -416,12 +396,11 @@ bool Hooks::isJSON (const std::string& input) const //////////////////////////////////////////////////////////////////////////////// void Hooks::assertValidJSON (const std::vector & input) const { - std::vector ::const_iterator i; - for (i = input.begin (); i != input.end (); i++) + for (auto& i : input) { - if (i->length () < 3 || - (*i)[0] != '{' || - (*i)[i->length () - 1] != '}') + if (i.length () < 3 || + i[0] != '{' || + i[i.length () - 1] != '}') { context.error (STRING_HOOK_ERROR_OBJECT); throw 0; @@ -429,7 +408,7 @@ void Hooks::assertValidJSON (const std::vector & input) const try { - json::value* root = json::parse (*i); + json::value* root = json::parse (i); if (root->type () != json::j_object) { context.error (STRING_HOOK_ERROR_OBJECT); @@ -451,7 +430,7 @@ void Hooks::assertValidJSON (const std::vector & input) const catch (const std::string& e) { - context.error (format (STRING_HOOK_ERROR_SYNTAX, *i)); + context.error (format (STRING_HOOK_ERROR_SYNTAX, i)); if (_debug) context.error (STRING_HOOK_ERROR_JSON + e); throw 0; @@ -459,7 +438,7 @@ void Hooks::assertValidJSON (const std::vector & input) const catch (...) { - context.error (STRING_HOOK_ERROR_NOPARSE + *i); + context.error (STRING_HOOK_ERROR_NOPARSE + i); throw 0; } } @@ -480,13 +459,12 @@ void Hooks::assertSameTask (const std::vector & input, const Task& { std::string uuid = task.get ("uuid"); - std::vector ::const_iterator i; - for (i = input.begin (); i != input.end (); i++) + for (auto& i : input) { - json::object* root_obj = (json::object*)json::parse (*i); + json::object* root_obj = (json::object*)json::parse (i); // If there is no UUID at all. - json_object_iter u = root_obj->_data.find ("uuid"); + auto u = root_obj->_data.find ("uuid"); if (u == root_obj->_data.end () || u->second->type () != json::j_string) { @@ -508,9 +486,8 @@ void Hooks::assertSameTask (const std::vector & input, const Task& void Hooks::assertFeedback (const std::vector & input) const { bool foundSomething = false; - std::vector ::const_iterator i; - for (i = input.begin (); i != input.end (); ++i) - if (nontrivial (*i)) + for (auto& i : input) + if (nontrivial (i)) foundSomething = true; if (! foundSomething) @@ -559,22 +536,20 @@ int Hooks::callHookScript ( if (_debug >= 2) { context.debug ("Hook: input"); - std::vector ::const_iterator i; - for (i = input.begin (); i != input.end (); ++i) - context.debug (" " + *i); + for (auto& i : input) + context.debug (" " + i); } std::string inputStr; - std::vector ::const_iterator i; - for (i = input.begin (); i != input.end (); ++i) - inputStr += *i + "\n"; + for (auto& i : input) + inputStr += i + "\n"; std::vector args; buildHookScriptArgs (args); if (_debug >= 2) { context.debug ("Hooks: args"); - for (auto arg: args) + for (auto& arg: args) context.debug (" " + arg); } @@ -596,10 +571,9 @@ int Hooks::callHookScript ( if (_debug >= 2) { context.debug ("Hook: output"); - std::vector ::iterator i; - for (i = output.begin (); i != output.end (); ++i) - if (*i != "") - context.debug (" " + *i); + for (auto& i : output) + if (i != "") + context.debug (" " + i); context.debug (format ("Hook: Completed with status {1}", status)); context.debug (" "); // Blank line diff --git a/src/JSON.cpp b/src/JSON.cpp index f5a24e3c0..baf3e01c9 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -162,9 +162,8 @@ std::string json::literal::dump () //////////////////////////////////////////////////////////////////////////////// json::array::~array () { - std::vector ::iterator i; - for (i = _data.begin (); i != _data.end (); ++i) - delete *i; + for (auto& i : _data) + delete i; } //////////////////////////////////////////////////////////////////////////////// @@ -227,10 +226,7 @@ std::string json::array::dump () std::string output; output += "["; - std::vector ::iterator i; - for (i = _data.begin (); - i != _data.end (); - ++i) + for (auto i = _data.begin (); i != _data.end (); ++i) { if (i != _data.begin ()) output += ","; @@ -245,9 +241,8 @@ std::string json::array::dump () //////////////////////////////////////////////////////////////////////////////// json::object::~object () { - std::map ::iterator i; - for (i = _data.begin (); i != _data.end (); ++i) - delete i->second; + for (auto& i : _data) + delete i.second; } //////////////////////////////////////////////////////////////////////////////// @@ -341,8 +336,7 @@ std::string json::object::dump () std::string output; output += "{"; - std::map ::iterator i; - for (i = _data.begin (); i != _data.end (); ++i) + for (auto i = _data.begin (); i != _data.end (); ++i) { if (i != _data.begin ()) output += ","; @@ -384,9 +378,9 @@ std::string json::encode (const std::string& input) { std::string output; - for (std::string::size_type i = 0; i < input.length (); ++i) + for (auto& i : input) { - switch (input[i]) + switch (i) { // Simple translations. case '"': output += "\\\""; break; @@ -399,7 +393,7 @@ std::string json::encode (const std::string& input) case '\t': output += "\\t"; break; // Default NOP. - default: output += input[i]; break; + default: output += i; break; } } diff --git a/src/JSON.h b/src/JSON.h index f086e4371..cfc6e5b10 100644 --- a/src/JSON.h +++ b/src/JSON.h @@ -131,8 +131,5 @@ namespace json std::string decode (const std::string&); } -typedef std::vector ::iterator json_array_iter; -typedef std::map ::iterator json_object_iter; - #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Msg.cpp b/src/Msg.cpp index fc224b497..2999516ef 100644 --- a/src/Msg.cpp +++ b/src/Msg.cpp @@ -102,8 +102,7 @@ void Msg::setPayload (const std::string& payload) //////////////////////////////////////////////////////////////////////////////// std::string Msg::get (const std::string& name) const { - std::map ::const_iterator i; - i = _header.find (name); + auto i = _header.find (name); if (i != _header.end ()) return i->second; @@ -119,9 +118,8 @@ std::string Msg::getPayload () const //////////////////////////////////////////////////////////////////////////////// void Msg::all (std::vector & names) const { - std::map ::const_iterator i; - for (i = _header.begin (); i != _header.end (); ++i) - names.push_back (i->first); + for (auto& i : _header) + names.push_back (i.first); } //////////////////////////////////////////////////////////////////////////////// @@ -129,9 +127,8 @@ std::string Msg::serialize () const { std::string output; - std::map ::const_iterator i; - for (i = _header.begin (); i != _header.end (); ++i) - output += i->first + ": " + i->second + "\n"; + for (auto& i : _header) + output += i.first + ": " + i.second + "\n"; output += "\n" + _payload + "\n"; @@ -144,21 +141,20 @@ bool Msg::parse (const std::string& input) _header.clear (); _payload = ""; - std::string::size_type separator = input.find ("\n\n"); + auto separator = input.find ("\n\n"); if (separator == std::string::npos) throw std::string ("ERROR: Malformed message"); // Parse header. std::vector lines; split (lines, input.substr (0, separator), '\n'); - std::vector ::iterator i; - for (i = lines.begin (); i != lines.end (); ++i) + for (auto& i : lines) { - std::string::size_type delimiter = i->find (':'); + std::string::size_type delimiter = i.find (':'); if (delimiter == std::string::npos) - throw std::string ("ERROR: Malformed message header '") + *i + "'"; + throw std::string ("ERROR: Malformed message header '") + i + "'"; - _header[trim (i->substr (0, delimiter))] = trim (i->substr (delimiter + 1)); + _header[trim (i.substr (0, delimiter))] = trim (i.substr (delimiter + 1)); } // Parse payload. diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index 261dc4745..7a7f25889 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -982,12 +982,11 @@ bool Nibbler::getOneOf ( const std::vector & options, std::string& found) { - std::vector ::const_iterator option; - for (option = options.begin (); option != options.end (); ++option) + for (auto& option : options) { - if (getLiteral (*option)) + if (getLiteral (option)) { - found = *option; + found = option; return true; } } diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 253fc6cca..196a789a4 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -121,12 +121,11 @@ bool TF2::get (const std::string& uuid, Task& task) if (! _loaded_tasks) load_tasks (); - std::vector ::iterator i; - for (i = _tasks.begin (); i != _tasks.end (); ++i) + for (auto& i : _tasks) { - if (i->get ("uuid") == uuid) + if (i.get ("uuid") == uuid) { - task = *i; + task = i; return true; } } @@ -140,9 +139,8 @@ bool TF2::has (const std::string& uuid) if (! _loaded_tasks) load_tasks (); - std::vector ::iterator i; - for (i = _tasks.begin (); i != _tasks.end (); ++i) - if (i->get ("uuid") == uuid) + for (auto& i : _tasks) + if (i.get ("uuid") == uuid) return true; return false; @@ -174,12 +172,11 @@ bool TF2::modify_task (const Task& task) { // Modify in-place. std::string uuid = task.get ("uuid"); - std::vector ::iterator i; - for (i = _tasks.begin (); i != _tasks.end (); ++i) + for (auto& i : _tasks) { - if (i->get ("uuid") == uuid) + if (i.get ("uuid") == uuid) { - *i = task; + i = task; _modified_tasks.push_back (task); _dirty = true; @@ -229,24 +226,14 @@ void TF2::commit () _file.lock (); // Write out all the added tasks. - std::vector ::iterator task; - for (task = _added_tasks.begin (); - task != _added_tasks.end (); - ++task) - { - _file.append (task->composeF4 () + "\n"); - } + for (auto& task : _added_tasks) + _file.append (task.composeF4 () + "\n"); _added_tasks.clear (); // Write out all the added lines. - std::vector ::iterator line; - for (line = _added_lines.begin (); - line != _added_lines.end (); - ++line) - { - _file.append (*line); - } + for (auto& line : _added_lines) + _file.append (line); _added_lines.clear (); _file.close (); @@ -264,22 +251,12 @@ void TF2::commit () _file.truncate (); // Only write out _tasks, because any deltas have already been applied. - std::vector ::iterator task; - for (task = _tasks.begin (); - task != _tasks.end (); - ++task) - { - _file.append (task->composeF4 () + "\n"); - } + for (auto& task : _tasks) + _file.append (task.composeF4 () + "\n"); // Write out all the added lines. - std::vector ::iterator line; - for (line = _added_lines.begin (); - line != _added_lines.end (); - ++line) - { - _file.append (*line); - } + for (auto& line : _added_lines) + _file.append (line); _added_lines.clear (); _file.close (); @@ -299,9 +276,8 @@ void TF2::load_tasks () load_lines (); // Apply previously added lines. - std::vector ::iterator i; - for (i = _added_lines.begin (); i != _added_lines.end (); ++i) - _lines.push_back (*i); + for (auto& line : _added_lines) + _lines.push_back (line); } int line_number = 0; @@ -310,11 +286,10 @@ void TF2::load_tasks () // Reduce unnecessary allocations/copies. _tasks.reserve (_lines.size ()); - std::vector ::iterator i; - for (i = _lines.begin (); i != _lines.end (); ++i) + for (auto& line : _lines) { ++line_number; - Task task (*i); + Task task (line); // Some tasks get an ID. if (_has_ids) @@ -374,13 +349,12 @@ std::string TF2::uuid (int id) load_tasks (); // Apply previously added tasks. - std::vector ::iterator i; - for (i = _added_tasks.begin (); i != _added_tasks.end (); ++i) - _tasks.push_back (*i); + for (auto& task : _added_tasks) + _tasks.push_back (task); } - std::map ::const_iterator i; - if ((i = _I2U.find (id)) != _I2U.end ()) + auto i = _I2U.find (id); + if (i != _I2U.end ()) return i->second; return ""; @@ -394,13 +368,12 @@ int TF2::id (const std::string& uuid) load_tasks (); // Apply previously added tasks. - std::vector ::iterator i; - for (i = _added_tasks.begin (); i != _added_tasks.end (); ++i) - _tasks.push_back (*i); + for (auto& task : _added_tasks) + _tasks.push_back (task); } - std::map ::const_iterator i; - if ((i = _U2I.find (uuid)) != _U2I.end ()) + auto i = _U2I.find (uuid); + if (i != _U2I.end ()) return i->second; return 0; @@ -448,38 +421,32 @@ void TF2::clear () void TF2::dependency_scan () { // Iterate and modify TDB2 in-place. Don't do this at home. - std::vector ::iterator left; - for (left = _tasks.begin (); - left != _tasks.end (); - ++left) + for (auto& left : _tasks) { - if (left->has ("depends")) + if (left.has ("depends")) { std::vector deps; - left->getDependencies (deps); + left.getDependencies (deps); - std::vector ::iterator d; - for (d = deps.begin (); d != deps.end (); ++d) + for (auto& dep : deps) { - std::vector ::iterator right; - for (right = _tasks.begin (); - right != _tasks.end (); - ++right) + for (auto& right : _tasks) { - if (right->get ("uuid") == *d) + if (right.get ("uuid") == dep) { // GC hasn't run yet, check both tasks for their current status - Task::status lstatus = left->getStatus (); - Task::status rstatus = right->getStatus (); + Task::status lstatus = left.getStatus (); + Task::status rstatus = right.getStatus (); if (lstatus != Task::completed && lstatus != Task::deleted && rstatus != Task::completed && rstatus != Task::deleted) { - left->is_blocked = true; - right->is_blocking = true; + left.is_blocked = true; + right.is_blocking = true; } + // Only want to break out of the "right" loop. break; } } @@ -701,18 +668,17 @@ void TDB2::commit () void TDB2::gather_changes () { _changes.clear (); - std::vector ::iterator i; - for (i = pending._added_tasks.begin (); i != pending._added_tasks.end (); ++i) - _changes.push_back (*i); + for (auto& task : pending._added_tasks) + _changes.push_back (task); - for (i = pending._modified_tasks.begin (); i != pending._modified_tasks.end (); ++i) - _changes.push_back (*i); + for (auto& task : pending._modified_tasks) + _changes.push_back (task); - for (i = completed._added_tasks.begin (); i != completed._added_tasks.end (); ++i) - _changes.push_back (*i); + for (auto& task : completed._added_tasks) + _changes.push_back (task); - for (i = completed._modified_tasks.begin (); i != completed._modified_tasks.end (); ++i) - _changes.push_back (*i); + for (auto& task : completed._modified_tasks) + _changes.push_back (task); } //////////////////////////////////////////////////////////////////////////////// @@ -842,8 +808,7 @@ void TDB2::revert_pending ( std::string uuid_att = "uuid:\"" + uuid + "\""; // is 'current' in pending? - std::vector ::iterator task; - for (task = p.begin (); task != p.end (); ++task) + for (auto task = p.begin (); task != p.end (); ++task) { if (task->find (uuid_att) != std::string::npos) { @@ -877,8 +842,7 @@ void TDB2::revert_completed ( std::string uuid_att = "uuid:\"" + uuid + "\""; // is 'current' in completed? - std::vector ::iterator task; - for (task = c.begin (); task != c.end (); ++task) + for (auto task = c.begin (); task != c.end (); ++task) { if (task->find (uuid_att) != std::string::npos) { @@ -927,8 +891,7 @@ void TDB2::revert_backlog ( std::string uuid_att = "\"uuid\":\"" + uuid + "\""; bool found = false; - std::vector ::reverse_iterator task; - for (task = b.rbegin (); task != b.rend (); ++task) + for (auto task = b.rbegin (); task != b.rend (); ++task) { if (task->find (uuid_att) != std::string::npos) { @@ -995,59 +958,56 @@ void TDB2::show_diff ( Task before (prior); std::vector beforeAtts; - std::map ::iterator att; - for (att = before.begin (); att != before.end (); ++att) - beforeAtts.push_back (att->first); + for (auto& att : before) + beforeAtts.push_back (att.first); std::vector afterAtts; - for (att = after.begin (); att != after.end (); ++att) - afterAtts.push_back (att->first); + for (auto& att : after) + afterAtts.push_back (att.first); std::vector beforeOnly; std::vector afterOnly; listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly); int row; - std::vector ::iterator name; - for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name) + for (auto& name : beforeOnly) { row = view.addRow (); - view.set (row, 0, *name); - view.set (row, 1, renderAttribute (*name, before.get (*name)), color_red); + view.set (row, 0, name); + view.set (row, 1, renderAttribute (name, before.get (name)), color_red); } - for (att = before.begin (); att != before.end (); ++att) + for (auto& att : before) { - std::string priorValue = before.get (att->first); - std::string currentValue = after.get (att->first); + std::string priorValue = before.get (att.first); + std::string currentValue = after.get (att.first); if (currentValue != "") { row = view.addRow (); - view.set (row, 0, att->first); - view.set (row, 1, renderAttribute (att->first, priorValue), + view.set (row, 0, att.first); + view.set (row, 1, renderAttribute (att.first, priorValue), (priorValue != currentValue ? color_red : Color ())); - view.set (row, 2, renderAttribute (att->first, currentValue), + view.set (row, 2, renderAttribute (att.first, currentValue), (priorValue != currentValue ? color_green : Color ())); } } - for (name = afterOnly.begin (); name != afterOnly.end (); ++name) + for (auto& name : afterOnly) { row = view.addRow (); - view.set (row, 0, *name); - view.set (row, 2, renderAttribute (*name, after.get (*name)), color_green); + view.set (row, 0, name); + view.set (row, 2, renderAttribute (name, after.get (name)), color_green); } } else { int row; - std::map ::iterator att; - for (att = after.begin (); att != after.end (); ++att) + for (auto& att : after) { row = view.addRow (); - view.set (row, 0, att->first); - view.set (row, 2, renderAttribute (att->first, after.get (att->first)), color_green); + view.set (row, 0, att.first); + view.set (row, 2, renderAttribute (att.first, after.get (att.first)), color_green); } } @@ -1101,14 +1061,13 @@ void TDB2::show_diff ( std::vector all = context.getColumns (); // Now factor in the annotation attributes. - Task::iterator it; - for (it = before.begin (); it != before.end (); ++it) - if (it->first.substr (0, 11) == "annotation_") - all.push_back (it->first); + for (auto& it : before) + if (it.first.substr (0, 11) == "annotation_") + all.push_back (it.first); - for (it = after.begin (); it != after.end (); ++it) - if (it->first.substr (0, 11) == "annotation_") - all.push_back (it->first); + for (auto& it : after) + if (it.first.substr (0, 11) == "annotation_") + all.push_back (it.first); // Now render all the attributes. std::sort (all.begin (), all.end ()); @@ -1116,19 +1075,18 @@ void TDB2::show_diff ( std::string before_att; std::string after_att; std::string last_att; - std::vector ::iterator a; - for (a = all.begin (); a != all.end (); ++a) + for (auto& a : all) { - if (*a != last_att) // Skip duplicates. + if (a != last_att) // Skip duplicates. { - last_att = *a; + last_att = a; - before_att = before.get (*a); - after_att = after.get (*a); + before_att = before.get (a); + after_att = after.get (a); // Don't report different uuid. // Show nothing if values are the unchanged. - if (*a == "uuid" || + if (a == "uuid" || before_att == after_att) { // Show nothing - no point displaying that which did not change. @@ -1142,21 +1100,21 @@ void TDB2::show_diff ( else if (before_att != "" && after_att == "") { row = view.addRow (); - view.set (row, 0, "-" + *a + ":", color_red); + view.set (row, 0, "-" + a + ":", color_red); view.set (row, 1, before_att, color_red); row = view.addRow (); - view.set (row, 0, "+" + *a + ":", color_green); + view.set (row, 0, "+" + a + ":", color_green); } // Attribute added. else if (before_att == "" && after_att != "") { row = view.addRow (); - view.set (row, 0, "-" + *a + ":", color_red); + view.set (row, 0, "-" + a + ":", color_red); row = view.addRow (); - view.set (row, 0, "+" + *a + ":", color_green); + view.set (row, 0, "+" + a + ":", color_green); view.set (row, 1, after_att, color_green); } @@ -1164,11 +1122,11 @@ void TDB2::show_diff ( else { row = view.addRow (); - view.set (row, 0, "-" + *a + ":", color_red); + view.set (row, 0, "-" + a + ":", color_red); view.set (row, 1, before_att, color_red); row = view.addRow (); - view.set (row, 0, "+" + *a + ":", color_green); + view.set (row, 0, "+" + a + ":", color_green); view.set (row, 1, after_att, color_green); } } @@ -1198,10 +1156,10 @@ int TDB2::gc () // Allowed as an override, but not recommended. if (context.config.getBoolean ("gc")) { - std::vector pending_tasks = pending.get_tasks (); + auto pending_tasks = pending.get_tasks (); // TODO Thread. - std::vector completed_tasks = completed.get_tasks (); + auto completed_tasks = completed.get_tasks (); // TODO Assume pending < completed, therefore there is room here to process // data before joining with the completed.data thread. @@ -1218,32 +1176,29 @@ int TDB2::gc () // completed, or need to be 'woken'. Date now; std::string status; - std::vector ::iterator task; - for (task = pending_tasks.begin (); - task != pending_tasks.end (); - ++task) + for (auto& task : pending_tasks) { - status = task->get ("status"); + status = task.get ("status"); if (status == "pending" || status == "recurring") { - pending_tasks_after.push_back (*task); + pending_tasks_after.push_back (task); } else if (status == "waiting") { - Date wait (task->get_date ("wait")); + Date wait (task.get_date ("wait")); if (wait < now) { - task->set ("status", "pending"); - task->remove ("wait"); + task.set ("status", "pending"); + task.remove ("wait"); pending_changes = true; } - pending_tasks_after.push_back (*task); + pending_tasks_after.push_back (task); } else { - completed_tasks_after.push_back (*task); + completed_tasks_after.push_back (task); pending_changes = true; completed_changes = true; } @@ -1256,35 +1211,33 @@ int TDB2::gc () // Scan all completed tasks, looking for any that need to be relocated to // pending. - for (task = completed_tasks.begin (); - task != completed_tasks.end (); - ++task) + for (auto& task : completed_tasks) { - status = task->get ("status"); + status = task.get ("status"); if (status == "pending" || status == "recurring") { - pending_tasks_after.push_back (*task); + pending_tasks_after.push_back (task); pending_changes = true; completed_changes = true; } else if (status == "waiting") { - Date wait (task->get_date ("wait")); + Date wait (task.get_date ("wait")); if (wait < now) { - task->set ("status", "pending"); - task->remove ("wait"); - pending_tasks_after.push_back (*task); + task.set ("status", "pending"); + task.remove ("wait"); + pending_tasks_after.push_back (task); pending_changes = true; completed_changes = true; } - pending_tasks_after.push_back (*task); + pending_tasks_after.push_back (task); } else { - completed_tasks_after.push_back (*task); + completed_tasks_after.push_back (task); } } @@ -1296,12 +1249,8 @@ int TDB2::gc () pending._loaded_tasks = true; _id = 1; - for (task = pending._tasks.begin (); - task != pending._tasks.end (); - ++task) - { - task->id = _id++; - } + for (auto& task : pending._tasks) + task.id = _id++; // Note: deliberately no commit. } @@ -1347,9 +1296,8 @@ const std::vector TDB2::all_tasks () completed._added_tasks.size ()); extra = completed.get_tasks (); - std::vector ::iterator task; - for (task = extra.begin (); task != extra.end (); ++task) - all.push_back (*task); + for (auto& task : extra) + all.push_back (task); return all; } @@ -1390,21 +1338,20 @@ const std::vector TDB2::siblings (Task& task) if (! pending._loaded_tasks) pending.load_tasks (); - std::vector ::iterator i; - for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i) + for (auto& i : pending._tasks) { // Do not include self in results. - if (i->id != task.id) + if (i.id != task.id) { // Do not include completed or deleted tasks. - if (i->getStatus () != Task::completed && - i->getStatus () != Task::deleted) + if (i.getStatus () != Task::completed && + i.getStatus () != Task::deleted) { // If task has the same parent, it is a sibling. - if (i->has ("parent") && - i->get ("parent") == parent) + if (i.has ("parent") && + i.get ("parent") == parent) { - results.push_back (*i); + results.push_back (i); } } } @@ -1424,19 +1371,18 @@ const std::vector TDB2::children (Task& task) if (! pending._loaded_tasks) pending.load_tasks (); - std::vector ::iterator i; - for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i) + for (auto& i : pending._tasks) { // Do not include self in results. - if (i->id != task.id) + if (i.id != task.id) { // Do not include completed or deleted tasks. - if (i->getStatus () != Task::completed && - i->getStatus () != Task::deleted) + if (i.getStatus () != Task::completed && + i.getStatus () != Task::deleted) { // If task has the same parent, it is a sibling. - if (i->get ("parent") == parent) - results.push_back (*i); + if (i.get ("parent") == parent) + results.push_back (i); } } } diff --git a/src/Task.cpp b/src/Task.cpp index 760b94e56..915644e57 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -130,10 +130,9 @@ bool Task::operator== (const Task& other) if (size () != other.size ()) return false; - Task::iterator i; - for (i = this->begin (); i != this->end (); ++i) - if (i->first != "uuid" && - i->second != other.get (i->first)) + for (auto& i : *this) + if (i.first != "uuid" && + i.second != other.get (i.first)) return false; return true; @@ -194,7 +193,7 @@ void Task::setAsNow (const std::string& att) //////////////////////////////////////////////////////////////////////////////// bool Task::has (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return true; @@ -205,8 +204,7 @@ bool Task::has (const std::string& name) const std::vector Task::all () { std::vector all; - Task::iterator i; - for (i = this->begin (); i != this->end (); ++i) + for (auto i = this->begin (); i != this->end (); ++i) all.push_back (i->first); return all; @@ -215,7 +213,7 @@ std::vector Task::all () //////////////////////////////////////////////////////////////////////////////// const std::string Task::get (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return i->second; @@ -225,7 +223,7 @@ const std::string Task::get (const std::string& name) const //////////////////////////////////////////////////////////////////////////////// const std::string& Task::get_ref (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return i->second; @@ -235,7 +233,7 @@ const std::string& Task::get_ref (const std::string& name) const //////////////////////////////////////////////////////////////////////////////// int Task::get_int (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return strtol (i->second.c_str (), NULL, 10); @@ -245,7 +243,7 @@ int Task::get_int (const std::string& name) const //////////////////////////////////////////////////////////////////////////////// unsigned long Task::get_ulong (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return strtoul (i->second.c_str (), NULL, 10); @@ -255,7 +253,7 @@ unsigned long Task::get_ulong (const std::string& name) const //////////////////////////////////////////////////////////////////////////////// float Task::get_float (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return strtof (i->second.c_str (), NULL); @@ -265,7 +263,7 @@ float Task::get_float (const std::string& name) const //////////////////////////////////////////////////////////////////////////////// time_t Task::get_date (const std::string& name) const { - Task::const_iterator i = this->find (name); + auto i = this->find (name); if (i != this->end ()) return (time_t) strtoul (i->second.c_str (), NULL, 10); @@ -291,8 +289,8 @@ void Task::set (const std::string& name, int value) //////////////////////////////////////////////////////////////////////////////// void Task::remove (const std::string& name) { - Task::iterator it; - if ((it = this->find (name)) != this->end ()) + auto it = this->find (name); + if (it != this->end ()) { this->erase (it); recalc_urgency = true; @@ -606,66 +604,60 @@ void Task::parseJSON (const std::string& line) json::object* root_obj = (json::object*)root; // For each object element... - json_object_iter i; - for (i = root_obj->_data.begin (); - i != root_obj->_data.end (); - ++i) + for (auto& i : root_obj->_data) { // If the attribute is a recognized column. - std::string type = Task::attributes[i->first]; + std::string type = Task::attributes[i.first]; if (type != "") { // Any specified id is ignored. - if (i->first == "id") + if (i.first == "id") ; // Urgency, if present, is ignored. - else if (i->first == "urgency") + else if (i.first == "urgency") ; // TW-1274 Standardization. - else if (i->first == "modification") + else if (i.first == "modification") { - Date d (unquoteText (i->second->dump ())); + Date d (unquoteText (i.second->dump ())); set ("modified", d.toEpochString ()); } // Dates are converted from ISO to epoch. else if (type == "date") { - std::string text = unquoteText (i->second->dump ()); + std::string text = unquoteText (i.second->dump ()); Date d (text); - set (i->first, text == "" ? "" : d.toEpochString ()); + set (i.first, text == "" ? "" : d.toEpochString ()); } // Tags are an array of JSON strings. - else if (i->first == "tags" && i->second->type() == json::j_array) + else if (i.first == "tags" && i.second->type() == json::j_array) { - json::array* tags = (json::array*)i->second; - json_array_iter t; - for (t = tags->_data.begin (); - t != tags->_data.end (); - ++t) + json::array* tags = (json::array*)i.second; + for (auto& t : tags->_data) { - json::string* tag = (json::string*)*t; + json::string* tag = (json::string*)t; addTag (tag->_data); } } // This is a temporary measure to allow Mirakel sync, and will be removed // in a future release. - else if (i->first == "tags" && i->second->type() == json::j_string) + else if (i.first == "tags" && i.second->type() == json::j_string) { - json::string* tag = (json::string*)i->second; + json::string* tag = (json::string*)i.second; addTag (tag->_data); } // Strings are decoded. else if (type == "string") - set (i->first, json::decode (unquoteText (i->second->dump ()))); + set (i.first, json::decode (unquoteText (i.second->dump ()))); // Other types are simply added. else - set (i->first, unquoteText (i->second->dump ())); + set (i.first, unquoteText (i.second->dump ())); } // UDA orphans and annotations do not have columns. @@ -673,17 +665,14 @@ void Task::parseJSON (const std::string& line) { // Annotations are an array of JSON objects with 'entry' and // 'description' values and must be converted. - if (i->first == "annotations") + if (i.first == "annotations") { std::map annos; - json::array* atts = (json::array*)i->second; - json_array_iter annotations; - for (annotations = atts->_data.begin (); - annotations != atts->_data.end (); - ++annotations) + json::array* atts = (json::array*)i.second; + for (auto& annotations : atts->_data) { - json::object* annotation = (json::object*)*annotations; + json::object* annotation = (json::object*)annotations; json::string* when = (json::string*)annotation->_data["entry"]; json::string* what = (json::string*)annotation->_data["description"]; @@ -706,13 +695,13 @@ void Task::parseJSON (const std::string& line) #ifdef PRODUCT_TASKWARRIOR std::stringstream message; message << "Task::parseJSON found orphan '" - << i->first + << i.first << "' with value '" - << i->second + << i.second << "' --> preserved\n"; context.debug (message.str ()); #endif - set (i->first, json::decode (unquoteText (i->second->dump ()))); + set (i.first, json::decode (unquoteText (i.second->dump ()))); } } } @@ -761,15 +750,14 @@ std::string Task::composeF4 () const std::string ff4 = "["; bool first = true; - Task::const_iterator it; - for (it = this->begin (); it != this->end (); ++it) + for (auto it : *this) { - if (it->second != "") + if (it.second != "") { ff4 += (first ? "" : " ") - + it->first + + it.first + ":\"" - + encode (json::encode (it->second)) + + encode (json::encode (it.second)) + "\""; first = false; @@ -793,33 +781,32 @@ std::string Task::composeJSON (bool decorate /*= false*/) const // First the non-annotations. int attributes_written = 0; - Task::const_iterator i; - for (i = this->begin (); i != this->end (); ++i) + for (auto& i : *this) { // Annotations are not written out here. - if (i->first.substr (0, 11) == "annotation_") + if (i.first.substr (0, 11) == "annotation_") continue; // If value is an empty string, do not ever output it - if (i->second == "") + if (i.second == "") continue; if (attributes_written) out << ","; - std::string type = Task::attributes[i->first]; + std::string type = Task::attributes[i.first]; if (type == "") type = "string"; // Date fields are written as ISO 8601. if (type == "date") { - Date d (i->second); + Date d (i.second); out << "\"" - << (i->first == "modification" ? "modified" : i->first) + << (i.first == "modification" ? "modified" : i.first) << "\":\"" // Date was deleted, do not export parsed empty string - << (i->second == "" ? "" : d.toISO ()) + << (i.second == "" ? "" : d.toISO ()) << "\""; ++attributes_written; @@ -828,23 +815,22 @@ std::string Task::composeJSON (bool decorate /*= false*/) const else if (type == "numeric") { out << "\"" - << i->first + << i.first << "\":" - << i->second; + << i.second; ++attributes_written; } // Tags are converted to an array. - else if (i->first == "tags") + else if (i.first == "tags") { std::vector tags; - split (tags, i->second, ','); + split (tags, i.second, ','); out << "\"tags\":["; - std::vector ::iterator i; - for (i = tags.begin (); i != tags.end (); ++i) + for (auto i = tags.begin (); i != tags.end (); ++i) { if (i != tags.begin ()) out << ","; @@ -861,9 +847,9 @@ std::string Task::composeJSON (bool decorate /*= false*/) const else { out << "\"" - << i->first + << i.first << "\":\"" - << json::encode (i->second) + << json::encode (i.second) << "\""; ++attributes_written; @@ -877,18 +863,18 @@ std::string Task::composeJSON (bool decorate /*= false*/) const << "\"annotations\":["; int annotations_written = 0; - for (i = this->begin (); i != this->end (); ++i) + for (auto& i : *this) { - if (i->first.substr (0, 11) == "annotation_") + if (i.first.substr (0, 11) == "annotation_") { if (annotations_written) out << ","; - Date d (i->first.substr (11)); + Date d (i.first.substr (11)); out << "{\"entry\":\"" << d.toISO () << "\",\"description\":\"" - << json::encode (i->second) + << json::encode (i.second) << "\"}"; ++annotations_written; @@ -943,7 +929,7 @@ void Task::addAnnotation (const std::string& description) void Task::removeAnnotations () { // Erase old annotations. - Task::iterator i = this->begin (); + auto i = this->begin (); while (i != this->end ()) { if (i->first.substr (0, 11) == "annotation_") @@ -963,10 +949,9 @@ void Task::getAnnotations (std::map & annotations) con { annotations.clear (); - Task::const_iterator ci; - for (ci = this->begin (); ci != this->end (); ++ci) - if (ci->first.substr (0, 11) == "annotation_") - annotations.insert (*ci); + for (auto& ann : *this) + if (ann.first.substr (0, 11) == "annotation_") + annotations.insert (ann); } //////////////////////////////////////////////////////////////////////////////// @@ -975,9 +960,8 @@ void Task::setAnnotations (const std::map & annotation // Erase old annotations. removeAnnotations (); - std::map ::const_iterator ci; - for (ci = annotations.begin (); ci != annotations.end (); ++ci) - this->insert (*ci); + for (auto& anno : annotations) + this->insert (anno); annotation_count = annotations.size (); recalc_urgency = true; @@ -1031,8 +1015,7 @@ void Task::removeDependency (const std::string& uuid) std::vector deps; split (deps, get ("depends"), ','); - std::vector ::iterator i; - i = std::find (deps.begin (), deps.end (), uuid); + auto i = std::find (deps.begin (), deps.end (), uuid); if (i != deps.end ()) { deps.erase (i); @@ -1064,9 +1047,8 @@ void Task::getDependencies (std::vector & all) const all.clear (); - std::vector ::iterator i; - for (i = deps.begin (); i != deps.end (); ++i) - all.push_back (context.tdb2.pending.id (*i)); + for (auto& dep : deps) + all.push_back (context.tdb2.pending.id (dep)); } //////////////////////////////////////////////////////////////////////////////// @@ -1160,9 +1142,8 @@ void Task::addTags (const std::vector & tags) { remove ("tags"); - std::vector ::const_iterator it; - for (it = tags.begin (); it != tags.end (); ++it) - addTag (*it); + for (auto& tag : tags) + addTag (tag); recalc_urgency = true; } @@ -1179,8 +1160,7 @@ void Task::removeTag (const std::string& tag) std::vector tags; split (tags, get ("tags"), ','); - std::vector ::iterator i; - i = std::find (tags.begin (), tags.end (), tag); + auto i = std::find (tags.begin (), tags.end (), tag); if (i != tags.end ()) { tags.erase (i); @@ -1198,21 +1178,19 @@ void Task::removeTag (const std::string& tag) // 'uda..type' void Task::getUDAs (std::vector & names) const { - Task::const_iterator it; - for (it = this->begin (); it != this->end (); ++it) - if (context.config.get ("uda." + it->first + ".type") != "") - names.push_back (it->first); + for (auto& it : *this) + if (context.config.get ("uda." + it.first + ".type") != "") + names.push_back (it.first); } //////////////////////////////////////////////////////////////////////////////// // A UDA Orphan is an attribute that is not represented in context.columns. void Task::getUDAOrphans (std::vector & names) const { - Task::const_iterator it; - for (it = this->begin (); it != this->end (); ++it) - if (it->first.substr (0, 11) != "annotation_") - if (context.columns.find (it->first) == context.columns.end ()) - names.push_back (it->first); + for (auto& it : *this) + if (it.first.substr (0, 11) != "annotation_") + if (context.columns.find (it.first) == context.columns.end ()) + names.push_back (it.first); } //////////////////////////////////////////////////////////////////////////////// @@ -1257,17 +1235,16 @@ void Task::substitute ( if (!done) { // Perform all subs on annotations. - std::map ::iterator it; - for (it = annotations.begin (); it != annotations.end () && !done; ++it) + for (auto& it : annotations) { start.clear (); end.clear (); - if (rx.match (start, end, it->second)) + if (rx.match (start, end, it.second)) { int skew = 0; for (unsigned int i = 0; i < start.size () && !done; ++i) { - it->second.replace (start[i + skew], end[i] - start[i], to); + it.second.replace (start[i + skew], end[i] - start[i], to); skew += to.length () - (end[i] - start[i]); ++changes; @@ -1304,14 +1281,13 @@ void Task::substitute ( { // Perform all subs on annotations. counter = 0; - std::map ::iterator i; - for (i = annotations.begin (); i != annotations.end () && !done; ++i) + for (auto& anno : annotations) { pos = 0; skew = 0; - while ((pos = ::find (i->second, from, pos, Task::searchCaseSensitive)) != std::string::npos && !done) + while ((pos = ::find (anno.second, from, pos, Task::searchCaseSensitive)) != std::string::npos && !done) { - i->second.replace (pos + skew, from.length (), to); + anno.second.replace (pos + skew, from.length (), to); skew += to.length () - from.length (); pos += to.length (); @@ -1412,15 +1388,14 @@ void Task::validate (bool applyDefault /* = true */) // override with uda.(uda).default, if not specified. // Gather a list of all UDAs with a .default value std::vector udas; - Config::const_iterator var; - for (var = context.config.begin (); var != context.config.end (); ++var) + for (auto& var : context.config) { - if (var->first.substr (0, 4) == "uda." && - var->first.find (".default") != std::string::npos) + if (var.first.substr (0, 4) == "uda." && + var.first.find (".default") != std::string::npos) { - std::string::size_type period = var->first.find ('.', 4); + std::string::size_type period = var.first.find ('.', 4); if (period != std::string::npos) - udas.push_back (var->first.substr (4, period - 4)); + udas.push_back (var.first.substr (4, period - 4)); } } @@ -1428,14 +1403,13 @@ void Task::validate (bool applyDefault /* = true */) { // For each of those, setup the default value on the task now, // of course only if we don't have one on the command line already - std::vector ::iterator uda; - for (uda = udas.begin (); uda != udas.end (); ++uda) + for (auto& uda : udas) { - std::string defVal= context.config.get ("uda." + *uda + ".default"); + std::string defVal= context.config.get ("uda." + uda + ".default"); // If the default is empty, or we already have a value, skip it - if (defVal != "" && get (*uda) == "") - set (*uda, defVal); + if (defVal != "" && get (uda) == "") + set (uda, defVal); } } } @@ -1650,64 +1624,63 @@ float Task::urgency_c () const value += fabsf (Task::urgencyInheritCoefficient) > epsilon ? (urgency_inherit () * Task::urgencyInheritCoefficient) : 0.0; // Tag- and project-specific coefficients. - std::map ::iterator var; - for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var) + for (auto& var : Task::coefficients) { - if (fabs (var->second) > epsilon) + if (fabs (var.second) > epsilon) { - if (var->first.substr (0, 13) == "urgency.user.") + if (var.first.substr (0, 13) == "urgency.user.") { // urgency.user.project..coefficient std::string::size_type end = std::string::npos; - if (var->first.substr (13, 8) == "project." && - (end = var->first.find (".coefficient")) != std::string::npos) + if (var.first.substr (13, 8) == "project." && + (end = var.first.find (".coefficient")) != std::string::npos) { - std::string project = var->first.substr (21, end - 21); + std::string project = var.first.substr (21, end - 21); if (get ("project").find (project) == 0) - value += var->second; + value += var.second; } // urgency.user.tag..coefficient - if (var->first.substr (13, 4) == "tag." && - (end = var->first.find (".coefficient")) != std::string::npos) + if (var.first.substr (13, 4) == "tag." && + (end = var.first.find (".coefficient")) != std::string::npos) { - std::string tag = var->first.substr (17, end - 17); + std::string tag = var.first.substr (17, end - 17); if (hasTag (tag)) - value += var->second; + value += var.second; } // urgency.user.keyword..coefficient - if (var->first.substr (13, 8) == "keyword." && - (end = var->first.find (".coefficient")) != std::string::npos) + if (var.first.substr (13, 8) == "keyword." && + (end = var.first.find (".coefficient")) != std::string::npos) { - std::string keyword = var->first.substr (21, end - 21); + std::string keyword = var.first.substr (21, end - 21); if (get ("description").find (keyword) != std::string::npos) - value += var->second; + value += var.second; } } - else if (var->first.substr (0, 12) == "urgency.uda.") + else if (var.first.substr (0, 12) == "urgency.uda.") { // urgency.uda..coefficient // urgency.uda...coefficient - std::string::size_type end = var->first.find (".coefficient"); + std::string::size_type end = var.first.find (".coefficient"); if (end != std::string::npos) { - const std::string uda = var->first.substr (12, end - 12); + const std::string uda = var.first.substr (12, end - 12); std::string::size_type dot = uda.find ("."); if (dot == std::string::npos) { // urgency.uda..coefficient if (has (uda)) - value += var->second; + value += var.second; } else { // urgency.uda...coefficient if (get (uda.substr(0, dot)) == uda.substr(dot+1)) - value += var->second; + value += var.second; } } } @@ -1744,20 +1717,19 @@ float Task::urgency_inherit () const dependencyGetBlocked (*this, blocked); float v = 0.0; - std::vector ::const_iterator it; - for (it = blocked.begin (); it != blocked.end (); ++it) + for (auto& task : blocked) { // urgency_blocked, _blocking, _project and _tags left out. - v += it->urgency_active (); - v += it->urgency_age (); - v += it->urgency_annotations (); - v += it->urgency_due (); - v += it->urgency_next (); - v += it->urgency_scheduled (); - v += it->urgency_waiting (); + v += task.urgency_active (); + v += task.urgency_age (); + v += task.urgency_annotations (); + v += task.urgency_due (); + v += task.urgency_next (); + v += task.urgency_scheduled (); + v += task.urgency_waiting (); // Inherit from all parent tasks in the dependency chain recursively. - v += it->urgency_inherit (); + v += task.urgency_inherit (); } return v; @@ -1910,17 +1882,16 @@ void Task::modify (modType type, bool text_required /* = false */) std::string label = " MODIFICATION "; int modCount = 0; - std::vector ::iterator a; - for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a) + for (auto& a : context.cli._args) { - if (a->hasTag ("MODIFICATION")) + if (a.hasTag ("MODIFICATION")) { - if (a->hasTag ("ATTRIBUTE")) + if (a.hasTag ("ATTRIBUTE")) { // 'name' is canonical. // 'value' requires eval. - std::string name = a->attribute ("name"); - std::string value = a->attribute ("value"); + std::string name = a.attribute ("name"); + std::string value = a.attribute ("value"); if (value == "" || value == "''" || value == "\"\"") @@ -1948,22 +1919,21 @@ void Task::modify (modType type, bool text_required /* = false */) split (deps, value, ','); // Apply or remove dendencies in turn. - std::vector ::iterator i; - for (i = deps.begin (); i != deps.end (); i++) + for (auto& dep : deps) { - if ((*i)[0] == '-') + if (dep[0] == '-') { - if ((*i).length () == 37) - removeDependency (context.tdb2.pending.id ((*i).substr (1))); + if (dep.length () == 37) + removeDependency (context.tdb2.pending.id (dep.substr (1))); else - removeDependency (strtol ((*i).substr (1).c_str (), NULL, 10)); + removeDependency (strtol (dep.substr (1).c_str (), NULL, 10)); } else { - if ((*i).length () == 36) - addDependency (context.tdb2.pending.id ((*i))); + if (dep.length () == 36) + addDependency (context.tdb2.pending.id (dep)); else - addDependency (strtol ((*i).c_str (), NULL, 10)); + addDependency (strtol (dep.c_str (), NULL, 10)); } } @@ -2104,22 +2074,22 @@ void Task::modify (modType type, bool text_required /* = false */) } // arg7 from='from' global='1' raw='/from/to/g' to='to' ORIGINAL SUBSTITUTION MODIFICATION - else if (a->hasTag ("SUBSTITUTION")) + else if (a.hasTag ("SUBSTITUTION")) { - context.debug (label + "substitute " + a->attribute ("raw")); - substitute (a->attribute ("from"), - a->attribute ("to"), - (a->attribute ("global") == "1")); + context.debug (label + "substitute " + a.attribute ("raw")); + substitute (a.attribute ("from"), + a.attribute ("to"), + (a.attribute ("global") == "1")); ++modCount; } // Tags need special handling because they are essentially a vector stored // in a single string, therefore Task::{add,remove}Tag must be called as // appropriate. - else if (a->hasTag ("TAG")) + else if (a.hasTag ("TAG")) { - std::string tag = a->attribute ("name"); - if (a->attribute ("sign") == "+") + std::string tag = a.attribute ("name"); + if (a.attribute ("sign") == "+") { context.debug (label + "tags <-- add '" + tag + "'"); addTag (tag); @@ -2135,12 +2105,12 @@ void Task::modify (modType type, bool text_required /* = false */) } // WORD and TERMINATED args are accumulated. - else if (a->hasTag ("WORD") || - a->hasTag ("TERMINATED")) + else if (a.hasTag ("WORD") || + a.hasTag ("TERMINATED")) { if (text != "") text += ' '; - text += a->attribute ("raw"); + text += a.attribute ("raw"); } // Unknown args are accumulated as though they were WORDs. @@ -2148,7 +2118,7 @@ void Task::modify (modType type, bool text_required /* = false */) { if (text != "") text += ' '; - text += a->attribute ("raw"); + text += a.attribute ("raw"); } } } diff --git a/src/Variant.cpp b/src/Variant.cpp index 60dc36081..7f21b53b2 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -1010,9 +1010,8 @@ bool Variant::operator_match (const Variant& other, const Task& task) const std::map annotations; task.getAnnotations (annotations); - std::map ::iterator a; - for (a = annotations.begin (); a != annotations.end (); ++a) - if (r.match (a->second)) + for (auto& a : annotations) + if (r.match (a.second)) return true; } } @@ -1028,9 +1027,8 @@ bool Variant::operator_match (const Variant& other, const Task& task) const std::map annotations; task.getAnnotations (annotations); - std::map ::iterator a; - for (a = annotations.begin (); a != annotations.end (); ++a) - if (find (a->second, pattern, searchCaseSensitive) != std::string::npos) + for (auto& a : annotations) + if (find (a.second, pattern, searchCaseSensitive) != std::string::npos) return true; } } diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index f5caf7b9a..ab6e4dac9 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -60,9 +60,8 @@ ViewTask::ViewTask () //////////////////////////////////////////////////////////////////////////////// ViewTask::~ViewTask () { - std::vector ::iterator i; - for (i = _columns.begin (); i != _columns.end (); ++i) - delete *i; + for (auto& col : _columns) + delete col; _columns.clear (); } @@ -297,7 +296,6 @@ std::string ViewTask::render (std::vector & data, std::vector & seque // Compose, render columns, in sequence. _rows = 0; std::vector > cells; - std::vector ::iterator s; for (unsigned int s = 0; s < sequence.size (); ++s) { max_lines = 0; @@ -334,10 +332,9 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (s > 0 && _breaks.size () > 0) { - std::vector ::iterator b; - for (b = _breaks.begin (); b != _breaks.end (); ++b) + for (auto& b : _breaks) { - if (data[sequence[s - 1]].get (*b) != data[sequence[s]].get (*b)) + if (data[sequence[s - 1]].get (b) != data[sequence[s]].get (b)) { out += "\n"; ++_lines; diff --git a/src/ViewText.cpp b/src/ViewText.cpp index 80b071b5f..6a6943747 100644 --- a/src/ViewText.cpp +++ b/src/ViewText.cpp @@ -56,9 +56,8 @@ ViewText::ViewText () //////////////////////////////////////////////////////////////////////////////// ViewText::~ViewText () { - std::vector ::iterator i; - for (i = _columns.begin (); i != _columns.end (); ++i) - delete *i; + for (auto& col : _columns) + delete col; _columns.clear (); } @@ -147,14 +146,13 @@ std::string ViewText::render () // Sum the minimal widths. int sum_minimal = 0; - std::vector ::iterator c; - for (c = minimal.begin (); c != minimal.end (); ++c) - sum_minimal += *c; + for (auto& c : minimal) + sum_minimal += c; // Sum the ideal widths. int sum_ideal = 0; - for (c = ideal.begin (); c != ideal.end (); ++c) - sum_ideal += *c; + for (auto& c : ideal) + sum_ideal += c; // Calculate final column widths. int overage = _width diff --git a/src/calc.cpp b/src/calc.cpp index 9fd2882e2..ad704e0c5 100644 --- a/src/calc.cpp +++ b/src/calc.cpp @@ -141,9 +141,8 @@ int main (int argc, char** argv) e.evaluatePostfixExpression (expression, result); // Show any debug output. - std::vector ::iterator i; - for (i = context.debugMessages.begin (); i != context.debugMessages.end (); ++i) - std::cout << *i << "\n"; + for (auto& i : context.debugMessages) + std::cout << i << "\n"; // Show the result in string form. std::cout << (std::string) result diff --git a/src/dependency.cpp b/src/dependency.cpp index 32d283e24..1a3fe2e8c 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -42,14 +42,13 @@ void dependencyGetBlocked (const Task& task, std::vector & blocked) { std::string uuid = task.get ("uuid"); - const std::vector & all = context.tdb2.pending.get_tasks (); - std::vector ::const_iterator it; - for (it = all.begin (); it != all.end (); ++it) - if ((it->getStatus () == Task::pending || - it->getStatus () == Task::waiting) && - it->has ("depends") && - it->get ("depends").find (uuid) != std::string::npos) - blocked.push_back (*it); + auto all = context.tdb2.pending.get_tasks (); + for (auto& it : all) + if ((it.getStatus () == Task::pending || + it.getStatus () == Task::waiting) && + it.has ("depends") && + it.get ("depends").find (uuid) != std::string::npos) + blocked.push_back (it); } //////////////////////////////////////////////////////////////////////////////// @@ -57,15 +56,11 @@ void dependencyGetBlocking (const Task& task, std::vector & blocking) { std::string depends = task.get ("depends"); if (depends != "") - { - const std::vector & all = context.tdb2.pending.get_tasks (); - std::vector ::const_iterator it; - for (it = all.begin (); it != all.end (); ++it) - if ((it->getStatus () == Task::pending || - it->getStatus () == Task::waiting) && - depends.find (it->get ("uuid")) != std::string::npos) - blocking.push_back (*it); - } + for (auto& it : context.tdb2.pending.get_tasks ()) + if ((it.getStatus () == Task::pending || + it.getStatus () == Task::waiting) && + depends.find (it.get ("uuid")) != std::string::npos) + blocking.push_back (it); } //////////////////////////////////////////////////////////////////////////////// @@ -152,9 +147,8 @@ void dependencyChainOnComplete (Task& task) std::cout << format (STRING_DEPEND_BLOCKED, task.id) << "\n"; - std::vector ::iterator b; - for (b = blocking.begin (); b != blocking.end (); ++b) - std::cout << " " << b->id << " " << b->get ("description") << "\n"; + for (auto& b : blocking) + std::cout << " " << b.id << " " << b.get ("description") << "\n"; } // If there are both blocking and blocked tasks, the chain is broken. @@ -165,9 +159,8 @@ void dependencyChainOnComplete (Task& task) std::cout << STRING_DEPEND_BLOCKING << "\n"; - std::vector ::iterator b; - for (b = blocked.begin (); b != blocked.end (); ++b) - std::cout << " " << b->id << " " << b->get ("description") << "\n"; + for (auto& b : blocked) + std::cout << " " << b.id << " " << b.get ("description") << "\n"; } if (!context.config.getBoolean ("dependency.confirmation") || @@ -175,22 +168,20 @@ void dependencyChainOnComplete (Task& task) { // Repair the chain - everything in blocked should now depend on // everything in blocking, instead of task.id. - std::vector ::iterator left; - std::vector ::iterator right; - for (left = blocked.begin (); left != blocked.end (); ++left) + for (auto& left : blocked) { - left->removeDependency (task.id); + left.removeDependency (task.id); - for (right = blocking.begin (); right != blocking.end (); ++right) - left->addDependency (right->id); + for (auto& right : blocking) + left.addDependency (right.id); } // Now update TDB2, now that the updates have all occurred. - for (left = blocked.begin (); left != blocked.end (); ++left) - context.tdb2.modify (*left); + for (auto& left : blocked) + context.tdb2.modify (left); - for (right = blocking.begin (); right != blocking.end (); ++right) - context.tdb2.modify (*right); + for (auto& right : blocking) + context.tdb2.modify (right); } } } @@ -211,9 +202,8 @@ void dependencyChainOnStart (Task& task) std::cout << format (STRING_DEPEND_BLOCKED, task.id) << "\n"; - std::vector ::iterator b; - for (b = blocking.begin (); b != blocking.end (); ++b) - std::cout << " " << b->id << " " << b->get ("description") << "\n"; + for (auto& b : blocking) + std::cout << " " << b.id << " " << b.get ("description") << "\n"; } } } @@ -254,11 +244,8 @@ void dependencyChainOnModify (Task& before, Task& after) std::vector blocked; dependencyGetBlocked (after, blocked); - std::vector ::iterator b; - for (b = blocked.begin (); b != blocked.end (); ++b) - { + for (auto& b : blocked) std::cout << "# dependencyChainOnModify\n"; - } } */ } diff --git a/src/feedback.cpp b/src/feedback.cpp index 3ece2778f..5f4d1d6b6 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -49,13 +49,12 @@ bool taskDiff (const Task& before, const Task& after) // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - Task::const_iterator att; - for (att = before.begin (); att != before.end (); ++att) - beforeAtts.push_back (att->first); + for (auto& att : before) + beforeAtts.push_back (att.first); std::vector afterAtts; - for (att = after.begin (); att != after.end (); ++att) - afterAtts.push_back (att->first); + for (auto& att : after) + afterAtts.push_back (att.first); std::vector beforeOnly; std::vector afterOnly; @@ -65,10 +64,9 @@ bool taskDiff (const Task& before, const Task& after) afterOnly.size ()) return true; - std::vector ::iterator name; - for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) - if (*name != "uuid" && - before.get (*name) != after.get (*name)) + for (auto& name : beforeAtts) + if (name != "uuid" && + before.get (name) != after.get (name)) return true; return false; @@ -80,13 +78,12 @@ std::string taskDifferences (const Task& before, const Task& after) // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - Task::const_iterator att; - for (att = before.begin (); att != before.end (); ++att) - beforeAtts.push_back (att->first); + for (auto& att : before) + beforeAtts.push_back (att.first); std::vector afterAtts; - for (att = after.begin (); att != after.end (); ++att) - afterAtts.push_back (att->first); + for (auto& att : after) + afterAtts.push_back (att.first); std::vector beforeOnly; std::vector afterOnly; @@ -94,15 +91,14 @@ std::string taskDifferences (const Task& before, const Task& after) // Now start generating a description of the differences. std::stringstream out; - std::vector ::iterator name; - for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name) + for (auto& name : beforeOnly) out << " - " - << format (STRING_FEEDBACK_DELETED, ucFirst (*name)) + << format (STRING_FEEDBACK_DELETED, ucFirst (name)) << "\n"; - for (name = afterOnly.begin (); name != afterOnly.end (); ++name) + for (auto& name : afterOnly) { - if (*name == "depends") + if (name == "depends") { std::vector deps_after; after.getDependencies (deps_after); @@ -116,21 +112,21 @@ std::string taskDifferences (const Task& before, const Task& after) else out << " - " << format (STRING_FEEDBACK_ATT_SET, - ucFirst (*name), - renderAttribute (*name, after.get (*name))) + ucFirst (name), + renderAttribute (name, after.get (name))) << "\n"; } - for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) + for (auto& name : beforeAtts) { // Ignore UUID differences, and find values that changed, but are not also // in the beforeOnly and afterOnly lists, which have been handled above.. - if (*name != "uuid" && - before.get (*name) != after.get (*name) && - std::find (beforeOnly.begin (), beforeOnly.end (), *name) == beforeOnly.end () && - std::find (afterOnly.begin (), afterOnly.end (), *name) == afterOnly.end ()) + if (name != "uuid" && + before.get (name) != after.get (name) && + std::find (beforeOnly.begin (), beforeOnly.end (), name) == beforeOnly.end () && + std::find (afterOnly.begin (), afterOnly.end (), name) == afterOnly.end ()) { - if (*name == "depends") + if (name == "depends") { std::vector deps_before; before.getDependencies (deps_before); @@ -149,9 +145,9 @@ std::string taskDifferences (const Task& before, const Task& after) else out << " - " << format (STRING_FEEDBACK_ATT_MOD, - ucFirst (*name), - renderAttribute (*name, before.get (*name)), - renderAttribute (*name, after.get (*name))) + ucFirst (name), + renderAttribute (name, before.get (name)), + renderAttribute (name, after.get (name))) << "\n"; } } @@ -176,13 +172,12 @@ std::string taskInfoDifferences ( // Attributes are all there is, so figure the different attribute names // between before and after. std::vector beforeAtts; - Task::const_iterator att; - for (att = before.begin (); att != before.end (); ++att) - beforeAtts.push_back (att->first); + for (auto& att : before) + beforeAtts.push_back (att.first); std::vector afterAtts; - for (att = after.begin (); att != after.end (); ++att) - afterAtts.push_back (att->first); + for (auto& att : after) + afterAtts.push_back (att.first); std::vector beforeOnly; std::vector afterOnly; @@ -190,10 +185,9 @@ std::string taskInfoDifferences ( // Now start generating a description of the differences. std::stringstream out; - std::vector ::iterator name; - for (name = beforeOnly.begin (); name != beforeOnly.end (); ++name) + for (auto& name : beforeOnly) { - if (*name == "depends") + if (name == "depends") { std::vector deps_before; before.getDependencies (deps_before); @@ -203,27 +197,27 @@ std::string taskInfoDifferences ( out << format (STRING_FEEDBACK_DEP_DEL, from) << "\n"; } - else if (name->substr (0, 11) == "annotation_") + else if (name.substr (0, 11) == "annotation_") { - out << format (STRING_FEEDBACK_ANN_DEL, before.get (*name)) + out << format (STRING_FEEDBACK_ANN_DEL, before.get (name)) << "\n"; } - else if (*name == "start") + else if (name == "start") { - out << format (STRING_FEEDBACK_ATT_DEL_DUR, ucFirst (*name), + out << format (STRING_FEEDBACK_ATT_DEL_DUR, ucFirst (name), Duration (current_timestamp - last_timestamp).formatPrecise ()) << "\n"; } else { - out << format (STRING_FEEDBACK_ATT_DEL, ucFirst (*name)) + out << format (STRING_FEEDBACK_ATT_DEL, ucFirst (name)) << "\n"; } } - for (name = afterOnly.begin (); name != afterOnly.end (); ++name) + for (auto& name : afterOnly) { - if (*name == "depends") + if (name == "depends") { std::vector deps_after; after.getDependencies (deps_after); @@ -233,30 +227,31 @@ std::string taskInfoDifferences ( out << format (STRING_FEEDBACK_DEP_WAS_SET, to) << "\n"; } - else if (name->substr (0, 11) == "annotation_") + else if (name.substr (0, 11) == "annotation_") { - out << format (STRING_FEEDBACK_ANN_ADD, after.get (*name)) + out << format (STRING_FEEDBACK_ANN_ADD, after.get (name)) << "\n"; } else { - if (*name == "start") + if (name == "start") last_timestamp = current_timestamp; out << format (STRING_FEEDBACK_ATT_WAS_SET, - ucFirst (*name), - renderAttribute (*name, after.get (*name), dateformat)) + ucFirst (name), + renderAttribute (name, after.get (name), dateformat)) << "\n"; } } - for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name) - if (*name != "uuid" && - *name != "modified" && - before.get (*name) != after.get (*name) && - before.get (*name) != "" && after.get (*name) != "") + for (auto& name : beforeAtts) + if (name != "uuid" && + name != "modified" && + before.get (name) != after.get (name) && + before.get (name) != "" && + after.get (name) != "") { - if (*name == "depends") + if (name == "depends") { std::vector deps_before; before.getDependencies (deps_before); @@ -271,16 +266,16 @@ std::string taskInfoDifferences ( out << format (STRING_FEEDBACK_DEP_WAS_MOD, from, to) << "\n"; } - else if (name->substr (0, 11) == "annotation_") + else if (name.substr (0, 11) == "annotation_") { - out << format (STRING_FEEDBACK_ANN_WAS_MOD, after.get (*name)) + out << format (STRING_FEEDBACK_ANN_WAS_MOD, after.get (name)) << "\n"; } else out << format (STRING_FEEDBACK_ATT_WAS_MOD, - ucFirst (*name), - renderAttribute (*name, before.get (*name), dateformat), - renderAttribute (*name, after.get (*name), dateformat)) + ucFirst (name), + renderAttribute (name, before.get (name), dateformat), + renderAttribute (name, after.get (name), dateformat)) << "\n"; } @@ -397,24 +392,23 @@ void feedback_unblocked (const Task& task) dependencyGetBlocked (task, blocked); // Scan all the tasks that were blocked by this task - std::vector ::iterator i; - for (i = blocked.begin (); i != blocked.end (); ++i) + for (auto& i : blocked) { std::vector blocking; - dependencyGetBlocking (*i, blocking); + dependencyGetBlocking (i, blocking); if (blocking.size () == 0) { - if (i->id) + if (i.id) std::cout << format (STRING_FEEDBACK_UNBLOCKED, - i->id, - i->get ("description")) + i.id, + i.get ("description")) << "\n"; else { - std::string uuid = i->get ("uuid"); + std::string uuid = i.get ("uuid"); std::cout << format (STRING_FEEDBACK_UNBLOCKED, - i->get ("uuid"), - i->get ("description")) + i.get ("uuid"), + i.get ("description")) << "\n"; } } @@ -429,10 +423,9 @@ void feedback_backlog () context.verbose ("sync")) { std::vector lines = context.tdb2.backlog.get_lines (); - std::vector ::iterator line; - for (line = lines.begin (); line != lines.end (); ++line) + for (auto& line : lines) { - if ((*line)[0] == '{') + if ((line)[0] == '{') { context.footnote (STRING_FEEDBACK_BACKLOG); break; @@ -518,12 +511,11 @@ static void countTasks ( int& count_pending, int& count_done) { - std::vector ::const_iterator it; - for (it = all.begin (); it != all.end (); ++it) + for (auto& it : all) { - if (it->get ("project") == project) + if (it.get ("project") == project) { - switch (it->getStatus ()) + switch (it.getStatus ()) { case Task::pending: case Task::waiting: diff --git a/src/legacy.cpp b/src/legacy.cpp index 9adcb9efc..f95e62a2f 100644 --- a/src/legacy.cpp +++ b/src/legacy.cpp @@ -63,7 +63,7 @@ void legacyColumnMap (std::string& name) } // If a legacy column was used, complain about it, but modify it anyway. - std::map ::iterator found = legacyMap.find (name); + auto found = legacyMap.find (name); if (found != legacyMap.end ()) { context.footnote (format (STRING_LEGACY_PRIORITY, name, found->second)); @@ -95,7 +95,7 @@ void legacySortColumnMap (std::string& name) } // If a legacy column was used, complain about it, but modify it anyway. - std::map ::iterator found = legacyMap.find (name); + auto found = legacyMap.find (name); if (found != legacyMap.end ()) { context.footnote (format (STRING_LEGACY_PRIORITY, name, found->second)); @@ -115,25 +115,24 @@ std::string legacyCheckForDeprecatedColor () std::string legacyCheckForDeprecatedVariables () { std::vector deprecated; - std::map ::const_iterator it; - for (it = context.config.begin (); it != context.config.end (); ++it) + for (auto& it : context.config) { // 2014-07-04: report.*.limit removed. // report.*.annotations - if (it->first.length () > 19 && - it->first.substr (0, 7) == "report." && - it->first.substr (it->first.length () - 12) == ".annotations") - deprecated.push_back (it->first); + if (it.first.length () > 19 && + it.first.substr (0, 7) == "report." && + it.first.substr (it.first.length () - 12) == ".annotations") + deprecated.push_back (it.first); - if (it->first == "next" || - it->first == "annotations" || - it->first == "export.ical.class") - deprecated.push_back (it->first); + if (it.first == "next" || + it.first == "annotations" || + it.first == "export.ical.class") + deprecated.push_back (it.first); // Deprecated іn 2.4.0. - if (it->first == "alias._query") - deprecated.push_back (it->first); + if (it.first == "alias._query") + deprecated.push_back (it.first); } std::stringstream out; @@ -142,9 +141,8 @@ std::string legacyCheckForDeprecatedVariables () out << STRING_CONFIG_DEPRECATED_VAR << "\n"; - std::vector ::iterator it2; - for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2) - out << " " << *it2 << "\n"; + for (auto& dep : deprecated) + out << " " << dep << "\n"; out << "\n"; } @@ -156,16 +154,15 @@ std::string legacyCheckForDeprecatedVariables () std::string legacyCheckForDeprecatedColumns () { std::vector deprecated; - std::map ::const_iterator it; - for (it = context.config.begin (); it != context.config.end (); ++it) + for (auto& it : context.config) { - if (it->first.find ("report") == 0) + if (it.first.find ("report") == 0) { - std::string value = context.config.get (it->first); + std::string value = context.config.get (it.first); if (value.find ("entry_time") != std::string::npos || value.find ("start_time") != std::string::npos || value.find ("end_time") != std::string::npos) - deprecated.push_back (it->first); + deprecated.push_back (it.first); } } @@ -177,9 +174,8 @@ std::string legacyCheckForDeprecatedColumns () out << STRING_CONFIG_DEPRECATED_COL << "\n"; - std::vector ::iterator it2; - for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2) - out << " " << *it2 << "=" << context.config.get (*it2) << "\n"; + for (auto& dep : deprecated) + out << " " << dep << "=" << context.config.get (dep) << "\n"; out << "\n"; } diff --git a/src/recur.cpp b/src/recur.cpp index b965a84b2..c123d8caf 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -60,56 +60,54 @@ void handleRecurrence () if (! context.config.getBoolean ("recurrence")) return; - std::vector tasks = context.tdb2.pending.get_tasks (); + auto tasks = context.tdb2.pending.get_tasks (); Date now; // Look at all tasks and find any recurring ones. - std::vector ::iterator t; - for (t = tasks.begin (); t != tasks.end (); ++t) + for (auto& t : tasks) { - if (t->getStatus () == Task::recurring) + if (t.getStatus () == Task::recurring) { // Generate a list of due dates for this recurring task, regardless of // the mask. std::vector due; - if (!generateDueDates (*t, due)) + if (!generateDueDates (t, due)) { // Determine the end date. - t->setStatus (Task::deleted); - context.tdb2.modify (*t); - context.footnote (onExpiration (*t)); + t.setStatus (Task::deleted); + context.tdb2.modify (t); + context.footnote (onExpiration (t)); continue; } // Get the mask from the parent task. - std::string mask = t->get ("mask"); + std::string mask = t.get ("mask"); // Iterate over the due dates, and check each against the mask. bool changed = false; unsigned int i = 0; - std::vector ::iterator d; - for (d = due.begin (); d != due.end (); ++d) + for (auto& d : due) { if (mask.length () <= i) { changed = true; - Task rec (*t); // Clone the parent. + Task rec (t); // Clone the parent. rec.setStatus (Task::pending); // Change the status. rec.id = context.tdb2.next_id (); // New ID. rec.set ("uuid", uuid ()); // New UUID. - rec.set ("parent", t->get ("uuid")); // Remember mom. + rec.set ("parent", t.get ("uuid")); // Remember mom. rec.setAsNow ("entry"); // New entry date. char dueDate[16]; - sprintf (dueDate, "%u", (unsigned int) d->toEpoch ()); + sprintf (dueDate, "%u", (unsigned int) d.toEpoch ()); rec.set ("due", dueDate); // Store generated due date. - if (t->has ("wait")) + if (t.has ("wait")) { - Date old_wait (t->get_date ("wait")); - Date old_due (t->get_date ("due")); - Date due (*d); + Date old_wait (t.get_date ("wait")); + Date old_due (t.get_date ("due")); + Date due (d); sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ()); rec.set ("wait", dueDate); rec.setStatus (Task::waiting); @@ -137,20 +135,20 @@ void handleRecurrence () // Only modify the parent if necessary. if (changed) { - t->set ("mask", mask); - context.tdb2.modify (*t); + t.set ("mask", mask); + context.tdb2.modify (t); } } // Non-recurring tasks expire too. else { - if (t->has ("until") && - Date (t->get_date ("until")) < now) + if (t.has ("until") && + Date (t.get_date ("until")) < now) { - t->setStatus (Task::deleted); - context.tdb2.modify(*t); - context.footnote (onExpiration (*t)); + t.setStatus (Task::deleted); + context.tdb2.modify(t); + context.footnote (onExpiration (t)); } } } @@ -424,14 +422,11 @@ bool nag (Task& task) std::string nagMessage = context.config.get ("nag"); if (nagMessage != "") { - // Load all pending tasks. - std::vector tasks = context.tdb2.pending.get_tasks (); - // Scan all pending tasks. - std::vector ::iterator t; - for (t = tasks.begin (); t != tasks.end (); ++t) + auto pending = context.tdb2.pending.get_tasks (); + for (auto& t : pending) { - if (t->urgency () > task.urgency ()) + if (t.urgency () > task.urgency ()) { context.footnote (nagMessage); return true; diff --git a/src/rules.cpp b/src/rules.cpp index 593ee72a9..2291e40a6 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -53,15 +53,14 @@ 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 rules; - Config::const_iterator v; - for (v = context.config.begin (); v != context.config.end (); ++v) + for (auto& v : context.config) { - if (v->first.substr (0, 6) == "color.") + if (v.first.substr (0, 6) == "color.") { - Color c (v->second); - gsColor[v->first] = c; + Color c (v.second); + gsColor[v.first] = c; - rules.push_back (v->first); + rules.push_back (v.first); } } @@ -71,16 +70,14 @@ void initializeColorRules () std::vector precedence; split (precedence, context.config.get ("rule.precedence.color"), ','); - std::vector ::iterator p; - for (p = precedence.begin (); p != precedence.end (); ++p) + for (auto& p : precedence) { // Add the leading "color." string. - std::string rule = "color." + *p; + std::string rule = "color." + p; autoComplete (rule, rules, results, 3); // Hard-coded 3. - std::vector ::iterator r; - for (r = results.begin (); r != results.end (); ++r) - gsPrecedence.push_back (*r); + for (auto& r : results) + gsPrecedence.push_back (r); } } @@ -185,11 +182,10 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b // first match. else { - Task::iterator it; - for (it = task.begin (); it != task.end (); ++it) + for (auto& it : task) { - if (it->first.substr (0, 11) == "annotation_" && - find (it->second, rule.substr (14), sensitive) != std::string::npos) + if (it.first.substr (0, 11) == "annotation_" && + find (it.second, rule.substr (14), sensitive) != std::string::npos) { c.blend (base); return; @@ -292,8 +288,7 @@ void autoColorize (Task& task, Color& c) // Note: c already contains colors specifically assigned via command. // Note: These rules form a hierarchy - the last rule is King, hence the // reverse iterator. - std::vector ::reverse_iterator r; - for (r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r) + for (auto r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r) { Color base = gsColor[*r]; if (base.nontrivial ()) diff --git a/src/sort.cpp b/src/sort.cpp index ea04bbfb8..8e5ec9fd5 100644 --- a/src/sort.cpp +++ b/src/sort.cpp @@ -80,10 +80,9 @@ static bool sort_compare (int left, int right) float left_real; float right_real; - std::vector ::iterator k; - for (k = global_keys.begin (); k != global_keys.end (); ++k) + for (auto& k : global_keys) { - context.decomposeSortField (*k, field, ascending, breakIndicator); + context.decomposeSortField (k, field, ascending, breakIndicator); // Urgency. if (field == "urgency") diff --git a/src/util.cpp b/src/util.cpp index 5711b0ab1..b0a9a940f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -156,23 +156,22 @@ int autoComplete ( unsigned int length = partial.length (); if (length) { - std::vector ::const_iterator item; - for (item = list.begin (); item != list.end (); ++item) + for (auto& item : list) { // An exact match is a special case. Assume there is only one exact match // and return immediately. - if (partial == *item) + if (partial == item) { matches.clear (); - matches.push_back (*item); + matches.push_back (item); return 1; } // Maintain a list of partial matches. else if (length >= (unsigned) minimum && - length <= item->length () && - partial == item->substr (0, length)) - matches.push_back (*item); + length <= item.length () && + partial == item.substr (0, length)) + matches.push_back (item); } }