diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-01-01 15:18:57 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-02-02 12:49:19 +0000 |
commit | df39627fa33392a71ab79aadaa57e5c5e650e79e (patch) | |
tree | 83a776716c9b8d9bea2e0a5c3282aa5e0cbcdb6d /examples/xml | |
parent | 7847e6bc02552fa7fc7f518e5cb3336f667b5a6d (diff) |
Examples: cleanup foreach usage
Replace deprecated foreach macro with range-based for loop
Change-Id: If919ba1d1d4acddfc1c5460ce7aebf8c49e3ac38
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/xml')
-rw-r--r-- | examples/xml/htmlinfo/main.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp index 6591c3ac91..22bf36f33c 100644 --- a/examples/xml/htmlinfo/main.cpp +++ b/examples/xml/htmlinfo/main.cpp @@ -50,7 +50,8 @@ #include <QtCore> -void parseHtmlFile(QTextStream &out, const QString &fileName) { +void parseHtmlFile(QTextStream &out, const QString &fileName) +{ QFile file(fileName); out << "Analysis of HTML file: " << fileName << endl; @@ -71,11 +72,11 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { while (!reader.atEnd()) { reader.readNext(); if (reader.isStartElement()) { - if (reader.name() == "title") + if (reader.name() == QLatin1String("title")) title = reader.readElementText(); - else if(reader.name() == "a") - links.append(reader.attributes().value("href").toString()); - else if(reader.name() == "p") + else if (reader.name() == QLatin1String("a")) + links.append(reader.attributes().value(QLatin1String("href")).toString()); + else if (reader.name() == QLatin1String("p")) ++paragraphCount; } } @@ -94,10 +95,10 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { << " Number of links: " << links.size() << endl << " Showing first few links:" << endl; - while(links.size() > 5) + while (links.size() > 5) links.removeLast(); - foreach(QString link, links) + for (const QString &link : qAsConst(links)) out << " " << link << endl; out << endl << endl; } @@ -108,11 +109,10 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); // get a list of all html files in the current directory - QStringList filter; - filter << "*.htm"; - filter << "*.html"; + const QStringList filter = { QStringLiteral("*.htm"), + QStringLiteral("*.html") }; - QStringList htmlFiles = QDir(":/").entryList(filter, QDir::Files); + const QStringList htmlFiles = QDir(QStringLiteral(":/")).entryList(filter, QDir::Files); QTextStream out(stdout); @@ -122,8 +122,8 @@ int main(int argc, char **argv) } // parse each html file and write the result to file/stream - foreach(QString file, htmlFiles) - parseHtmlFile(out, ":/" + file); + for (const QString &file : htmlFiles) + parseHtmlFile(out, QStringLiteral(":/") + file); return 0; } |