Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#include <QtCore>
|
|
|
|
void parseHtmlFile(QTextStream &out, const QString &fileName)
|
|
{
|
|
QFile file(fileName);
|
|
|
|
out << "Analysis of HTML file: " << fileName << Qt::endl;
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
out << " Couldn't open the file." << Qt::endl << Qt::endl << Qt::endl;
|
|
return;
|
|
}
|
|
|
|
//! [0]
|
|
QXmlStreamReader reader(&file);
|
|
//! [0]
|
|
|
|
//! [1]
|
|
int paragraphCount = 0;
|
|
QStringList links;
|
|
QString title;
|
|
while (!reader.atEnd()) {
|
|
reader.readNext();
|
|
if (reader.isStartElement()) {
|
|
if (reader.name() == QLatin1String("title"))
|
|
title = reader.readElementText();
|
|
else if (reader.name() == QLatin1String("a"))
|
|
links.append(reader.attributes().value(QLatin1String("href")).toString());
|
|
else if (reader.name() == QLatin1String("p"))
|
|
++paragraphCount;
|
|
}
|
|
}
|
|
//! [1]
|
|
|
|
//! [2]
|
|
if (reader.hasError()) {
|
|
out << " The HTML file isn't well-formed: " << reader.errorString()
|
|
<< Qt::endl << Qt::endl << Qt::endl;
|
|
return;
|
|
}
|
|
//! [2]
|
|
|
|
out << " Title: \"" << title << '"' << Qt::endl
|
|
<< " Number of paragraphs: " << paragraphCount << Qt::endl
|
|
<< " Number of links: " << links.size() << Qt::endl
|
|
<< " Showing first few links:" << Qt::endl;
|
|
|
|
while (links.size() > 5)
|
|
links.removeLast();
|
|
|
|
for (const QString &link : qAsConst(links))
|
|
out << " " << link << Qt::endl;
|
|
out << Qt::endl << Qt::endl;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
// initialize Qt Core application
|
|
QCoreApplication app(argc, argv);
|
|
|
|
// get a list of all html files in the current directory
|
|
const QStringList filter = { QStringLiteral("*.htm"),
|
|
QStringLiteral("*.html") };
|
|
|
|
const QStringList htmlFiles = QDir(QStringLiteral(":/")).entryList(filter, QDir::Files);
|
|
|
|
QTextStream out(stdout);
|
|
|
|
if (htmlFiles.isEmpty()) {
|
|
out << "No html files available.";
|
|
return 1;
|
|
}
|
|
|
|
// parse each html file and write the result to file/stream
|
|
for (const QString &file : htmlFiles)
|
|
parseHtmlFile(out, QStringLiteral(":/") + file);
|
|
|
|
return 0;
|
|
}
|