summaryrefslogtreecommitdiffstats
path: root/src/qdoc/codeparser.cpp
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2019-08-11 20:11:48 +0200
committerPaul Wicking <paul.wicking@qt.io>2019-09-28 07:47:54 +0200
commitbe8ffa4e910a3413bd3df907d8e15514691a0342 (patch)
tree2be24fb7cadbbe17fb8a2a10fdbddd8ff113b3bb /src/qdoc/codeparser.cpp
parent72a5776421948ab82bcfa4d744a027cadcd7267e (diff)
QDoc: Use range-based for instead of foreach
This change replaces the use of foreach with range-based for throughout QDoc. It also ensures that the loop body doesn't modify the container being iterated over, by: - Making a const copy when the container is a member variable or the result of an expression, and iterating over that copy. This is the preferred approach. - Using qAsConst() when the container is a (static) member variable or local to the method and not const. The latter is typical where the collection is sorted immediately before the loop. In two cases (doc.cpp), replaced Q_FOREACH + delete with qDeleteAll. In two cases (cppcodeparser.cpp), the range declaration is replaced within the loop statement. These rewrites express the behavior clearer than the original code. In two cases (codeparser.cpp), use a range-based for instead of a while loop where the condition is an iterator, for more expressive code. Finally, use the auto keyword where appropriate and improve a few variable names. QDoc warning count and generated output is unchanged after this refactoring. Change-Id: I64f02d24dca373a3a41402d535382e2c526bb55e Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/qdoc/codeparser.cpp')
-rw-r--r--src/qdoc/codeparser.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/qdoc/codeparser.cpp b/src/qdoc/codeparser.cpp
index 3453f0b18..99bd5b1c8 100644
--- a/src/qdoc/codeparser.cpp
+++ b/src/qdoc/codeparser.cpp
@@ -124,16 +124,13 @@ CodeParser *CodeParser::parserForHeaderFile(const QString &filePath)
{
QString fileName = QFileInfo(filePath).fileName();
- QList<CodeParser *>::ConstIterator p = parsers.constBegin();
- while (p != parsers.constEnd()) {
-
- QStringList headerPatterns = (*p)->headerFileNameFilter();
- foreach (const QString &pattern, headerPatterns) {
+ for (const auto &parser : qAsConst(parsers)) {
+ const QStringList headerPatterns = parser->headerFileNameFilter();
+ for (const auto &pattern : headerPatterns) {
QRegExp re(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.exactMatch(fileName))
- return *p;
+ return parser;
}
- ++p;
}
return nullptr;
}
@@ -142,16 +139,13 @@ CodeParser *CodeParser::parserForSourceFile(const QString &filePath)
{
QString fileName = QFileInfo(filePath).fileName();
- QList<CodeParser *>::ConstIterator p = parsers.constBegin();
- while (p != parsers.constEnd()) {
-
- QStringList sourcePatterns = (*p)->sourceFileNameFilter();
- foreach (const QString &pattern, sourcePatterns) {
+ for (const auto &parser : parsers) {
+ const QStringList sourcePatterns = parser->sourceFileNameFilter();
+ for (const QString &pattern : sourcePatterns) {
QRegExp re(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.exactMatch(fileName))
- return *p;
+ return parser;
}
- ++p;
}
return nullptr;
}