Skip to content

Commit 2b3fc5e

Browse files
authored
replaced Qt foreach() with standard for range loop / some related cleanups (cppcheck-opensource#3915)
* replaced Qt foreach() with standard for range loop / some related cleanups * updated translations
1 parent 0e14750 commit 2b3fc5e

27 files changed

Lines changed: 916 additions & 929 deletions

gui/checkthread.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void CheckThread::run()
137137

138138
void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSettings, const QString &fileName)
139139
{
140-
foreach (const QString addon, mAddonsAndTools) {
140+
for (const QString& addon : mAddonsAndTools) {
141141
if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) {
142142
if (!fileSettings)
143143
continue;
@@ -150,17 +150,17 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
150150
args << ("-I" + QString::fromStdString(*incIt));
151151
for (std::list<std::string>::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i)
152152
args << "-isystem" << QString::fromStdString(*i);
153-
foreach (QString def, QString::fromStdString(fileSettings->defines).split(";")) {
153+
for (const QString& def : QString::fromStdString(fileSettings->defines).split(";")) {
154154
args << ("-D" + def);
155155
}
156-
foreach (const std::string& U, fileSettings->undefs) {
156+
for (const std::string& U : fileSettings->undefs) {
157157
args << QString::fromStdString("-U" + U);
158158
}
159159

160160
const QString clangPath = CheckThread::clangTidyCmd();
161161
if (!clangPath.isEmpty()) {
162162
QDir dir(clangPath + "/../lib/clang");
163-
foreach (QString ver, dir.entryList()) {
163+
for (QString ver : dir.entryList()) {
164164
QString includePath = dir.absolutePath() + '/' + ver + "/include";
165165
if (ver[0] != '.' && QDir(includePath).exists()) {
166166
args << "-isystem" << includePath;
@@ -173,7 +173,7 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
173173
// To create compile_commands.json in windows see:
174174
// https://bitsmaker.gitlab.io/post/clang-tidy-from-vs2015/
175175

176-
foreach (QString includePath, mClangIncludePaths) {
176+
for (QString includePath : mClangIncludePaths) {
177177
if (!includePath.isEmpty()) {
178178
includePath.replace("\\", "/");
179179
args << "-isystem" << includePath.trimmed();
@@ -262,7 +262,7 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
262262
{
263263
const QString cmd(clangTidyCmd());
264264
QString debug(cmd.contains(" ") ? ('\"' + cmd + '\"') : cmd);
265-
foreach (QString arg, args) {
265+
for (const QString& arg : args) {
266266
if (arg.contains(" "))
267267
debug += " \"" + arg + '\"';
268268
else
@@ -375,7 +375,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
375375
}
376376
errorItems.append(errorItem);
377377

378-
foreach (const ErrorItem &e, errorItems) {
378+
for (const ErrorItem &e : errorItems) {
379379
if (e.errorPath.isEmpty())
380380
continue;
381381
Suppressions::ErrorMessage errorMessage;
@@ -388,7 +388,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
388388
continue;
389389

390390
std::list<ErrorMessage::FileLocation> callstack;
391-
foreach (const QErrorPathItem &path, e.errorPath) {
391+
for (const QErrorPathItem &path : e.errorPath) {
392392
callstack.push_back(ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line, path.column));
393393
}
394394
const std::string f0 = file0.toStdString();
@@ -401,7 +401,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
401401

402402
bool CheckThread::isSuppressed(const Suppressions::ErrorMessage &errorMessage) const
403403
{
404-
foreach (const Suppressions::Suppression &suppression, mSuppressions) {
404+
for (const Suppressions::Suppression &suppression : mSuppressions) {
405405
if (suppression.isSuppressed(errorMessage))
406406
return true;
407407
}

gui/codeeditor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Highlighter::Highlighter(QTextDocument *parent,
112112
<< "volatile"
113113
<< "wchar_­t"
114114
<< "while";
115-
foreach (const QString &pattern, keywordPatterns) {
115+
for (const QString &pattern : keywordPatterns) {
116116
rule.pattern = QRegularExpression("\\b" + pattern + "\\b");
117117
rule.format = mKeywordFormat;
118118
rule.ruleRole = RuleRole::Keyword;
@@ -156,7 +156,7 @@ Highlighter::Highlighter(QTextDocument *parent,
156156
void Highlighter::setSymbols(const QStringList &symbols)
157157
{
158158
mHighlightingRulesWithSymbols = mHighlightingRules;
159-
foreach (const QString &sym, symbols) {
159+
for (const QString &sym : symbols) {
160160
HighlightingRule rule;
161161
rule.pattern = QRegularExpression("\\b" + sym + "\\b");
162162
rule.format = mSymbolFormat;
@@ -191,7 +191,7 @@ void Highlighter::setStyle(const CodeEditorStyle &newStyle)
191191

192192
void Highlighter::highlightBlock(const QString &text)
193193
{
194-
foreach (const HighlightingRule &rule, mHighlightingRulesWithSymbols) {
194+
for (const HighlightingRule &rule : mHighlightingRulesWithSymbols) {
195195
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
196196
while (matchIterator.hasNext()) {
197197
QRegularExpressionMatch match = matchIterator.next();

0 commit comments

Comments
 (0)