clang-tidy: loop conversion

Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2021-04-22 21:48:50 -07:00 committed by Tomas Babej
parent 15f0ab87e0
commit ab7f5b0b51
7 changed files with 36 additions and 38 deletions

View file

@ -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);

View file

@ -195,8 +195,9 @@ void Eval::debug (bool value)
std::vector <std::string> Eval::getOperators ()
{
std::vector <std::string> 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 <std::string> Eval::getOperators ()
std::vector <std::string> Eval::getBinaryOperators ()
{
std::vector <std::string> 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;
}
}

View file

@ -320,8 +320,8 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& 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 <Task>& data, std::vector <int>& 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))
{

View file

@ -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);
}
}

View file

@ -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");

@ -1 +1 @@
Subproject commit df7267c75c0d77f5356c7c9b9028d9100590c6e6
Subproject commit c1760be8686ce0b2f778832aaa1e2f98eed2ffc1

View file

@ -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: "<token>"
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: "<token>"
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);
}
}
}