| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #include "qmltypereader.h" |
| 5 | |
| 6 | #include <QFileInfo> |
| 7 | #include <QFile> |
| 8 | #include <QRegularExpression> |
| 9 | |
| 10 | #include <iostream> |
| 11 | |
| 12 | QStringList readQmlTypes(const QString &filename) { |
| 13 | QRegularExpression re("import QtQuick\\.tooling 1\\.2.*Module {\\s*dependencies:\\s*\\[([^\\]]*)\\](.*)}", |
| 14 | QRegularExpression::DotMatchesEverythingOption); |
| 15 | if (!QFileInfo(filename).exists()) { |
| 16 | std::cerr << "Non existing file: "<< filename.toStdString() << std::endl; |
| 17 | return QStringList(); |
| 18 | } |
| 19 | QFile f(filename); |
| 20 | if (!f.open(flags: QFileDevice::ReadOnly)) { |
| 21 | std::cerr << "Error in opening file "<< filename.toStdString() << " : " |
| 22 | << f.errorString().toStdString() << std::endl; |
| 23 | return QStringList(); |
| 24 | } |
| 25 | QByteArray fileData = f.readAll(); |
| 26 | QString data(fileData); |
| 27 | QRegularExpressionMatch m = re.match(subject: data); |
| 28 | if (m.lastCapturedIndex() != 2) { |
| 29 | std::cerr << "Malformed file: "<< filename.toStdString() << std::endl; |
| 30 | return QStringList(); |
| 31 | } |
| 32 | return m.capturedTexts(); |
| 33 | } |
| 34 |
