diff --git a/src/Context.cpp b/src/Context.cpp index 78c44f00b..0bff55913 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -409,8 +409,6 @@ static const char* modifierNames[] = "noword" }; -#define NUM_MODIFIER_NAMES (sizeof (modifierNames) / sizeof (modifierNames[0])) - Context* Context::context; //////////////////////////////////////////////////////////////////////////////// @@ -564,8 +562,8 @@ int Context::initialize (int argc, const char** argv) // //////////////////////////////////////////////////////////////////////////// - for (unsigned int i = 0; i < NUM_MODIFIER_NAMES; ++i) - cli2.entity ("modifier", modifierNames[i]); + for (auto& modifierName : modifierNames) + cli2.entity ("modifier", modifierName); for (auto& op : Eval::getOperators ()) cli2.entity ("operator", op); diff --git a/src/Eval.cpp b/src/Eval.cpp index 8089f7fac..e96464576 100644 --- a/src/Eval.cpp +++ b/src/Eval.cpp @@ -195,8 +195,9 @@ void Eval::debug (bool value) std::vector Eval::getOperators () { std::vector all; - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) - all.push_back (operators[i].op); + all.reserve(NUM_OPERATORS); + for (const auto &opr : operators) + all.push_back (opr.op); return all; } @@ -206,9 +207,9 @@ std::vector Eval::getOperators () std::vector Eval::getBinaryOperators () { std::vector all; - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) - if (operators[i].type == 'b') - all.push_back (operators[i].op); + for (const auto &opr : operators) + if (opr.type == 'b') + all.push_back (opr.op); return all; } @@ -338,9 +339,9 @@ void Eval::evaluatePostfixStack ( case Lexer::Type::identifier: { bool found = false; - for (auto source = _sources.begin (); source != _sources.end (); ++source) + for (const auto& source : _sources) { - if ((*source) (token.first, v)) + if (source (token.first, v)) { if (_debug) Context::getContext ().debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, (std::string) v)); @@ -669,10 +670,10 @@ bool Eval::parsePrimitive ( else { bool found = false; - for (auto source = _sources.begin (); source != _sources.end (); ++source) + for (const auto& source : _sources) { Variant v; - if ((*source) (infix[i].first, v)) + if (source (infix[i].first, v)) { found = true; break; @@ -810,13 +811,13 @@ bool Eval::identifyOperator ( unsigned int& precedence, char& associativity) const { - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) + for (const auto& opr : operators) { - if (operators[i].op == op) + if (opr.op == op) { - type = operators[i].type; - precedence = operators[i].precedence; - associativity = operators[i].associativity; + type = opr.type; + precedence = opr.precedence; + associativity = opr.associativity; return true; } } diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index 3d3473204..2f0cd1eed 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -320,8 +320,8 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (obfuscate) if (_columns[c]->type () == "string") - for (unsigned int line = 0; line < cells[c].size (); ++line) - cells[c][line] = obfuscateText (cells[c][line]); + for (auto& line : cells[c]) + line = obfuscateText (line); } // Listing breaks are simply blank lines inserted when a column value @@ -329,7 +329,7 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (s > 0 && _breaks.size () > 0) { - for (auto& b : _breaks) + for (const auto& b : _breaks) { if (data[sequence[s - 1]].get (b) != data[sequence[s]].get (b)) { diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index 3f8cd7527..f068fb4fc 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -427,11 +427,11 @@ int CmdCalendar::execute (std::string& output) auto v = hm_it.second; Datetime hDate (hm_it.first); auto d = hDate.toString (format); - for (size_t i = 0; i < v.size(); i++) + for (const auto& i : v) { auto row = holTable.addRow (); holTable.set (row, 0, d); - holTable.set (row, 1, v[i]); + holTable.set (row, 1, i); } } diff --git a/src/dependency.cpp b/src/dependency.cpp index b5c4c4102..d05e4a450 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -91,9 +91,9 @@ bool dependencyIsCircular (const Task& task) // This is a basic depth first search that always terminates given the // fact that we do not visit any task twice - for (unsigned int i = 0; i < deps_current.size (); i++) + for (const auto& dep : deps_current) { - if (Context::getContext ().tdb2.get (deps_current[i], current)) + if (Context::getContext ().tdb2.get (dep, current)) { auto current_uuid = current.get ("uuid"); diff --git a/src/libshared b/src/libshared index df7267c75..c1760be86 160000 --- a/src/libshared +++ b/src/libshared @@ -1 +1 @@ -Subproject commit df7267c75c0d77f5356c7c9b9028d9100590c6e6 +Subproject commit c1760be8686ce0b2f778832aaa1e2f98eed2ffc1 diff --git a/test/lexer.t.cpp b/test/lexer.t.cpp index 31d25e0c5..89a79349e 100644 --- a/test/lexer.t.cpp +++ b/test/lexer.t.cpp @@ -485,35 +485,34 @@ int main (int, char**) { "name:value", Lexer::Type::pair }, { ")", Lexer::Type::op }, NO, NO }, }, }; - #define NUM_TESTS (sizeof (lexerTests) / sizeof (lexerTests[0])) - for (unsigned int i = 0; i < NUM_TESTS; i++) + for (const auto& lexerTest : lexerTests) { // The isolated test puts the input string directly into the Lexer. - Lexer isolated (lexerTests[i].input); + Lexer isolated (lexerTest.input); - for (int j = 0; j < 5; j++) + for (const auto& result : lexerTest.results) { - if (lexerTests[i].results[j].token[0]) + if (result.token[0]) { // Isolated: "" t.ok (isolated.token (token, type), "Isolated Lexer::token(...) --> true"); - t.is (token, lexerTests[i].results[j].token, " token --> " + token, lexerTests[i].results[j].expfail_token); - t.is ((int)type, (int)lexerTests[i].results[j].type, " type --> Lexer::Type::" + Lexer::typeToString (type), lexerTests[i].results[j].expfail_type); + t.is (token, result.token, " token --> " + token, result.expfail_token); + t.is ((int)type, (int)result.type, " type --> Lexer::Type::" + Lexer::typeToString (type), result.expfail_type); } } // The embedded test surrounds the input string with a space. - Lexer embedded (std::string (" ") + lexerTests[i].input + " "); + Lexer embedded (std::string (" ") + lexerTest.input + " "); - for (int j = 0; j < 5; j++) + for (const auto& result : lexerTest.results) { - if (lexerTests[i].results[j].token[0]) + if (result.token[0]) { // Embedded: "" t.ok (embedded.token (token, type), "Embedded Lexer::token(...) --> true"); - t.is (token, lexerTests[i].results[j].token, " token --> " + token, lexerTests[i].results[j].expfail_token); - t.is ((int)type, (int)lexerTests[i].results[j].type, " type --> Lexer::Type::" + Lexer::typeToString (type), lexerTests[i].results[j].expfail_type); + t.is (token, result.token, " token --> " + token, result.expfail_token); + t.is ((int)type, (int)result.type, " type --> Lexer::Type::" + Lexer::typeToString (type), result.expfail_type); } } }