diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-02-08 16:06:53 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-02-13 12:50:08 +0000 |
commit | 82b211417e67dd41bdb90caaf19263e94679c2da (patch) | |
tree | a7e6fee7e303f7ac597216cb60b53abc55a864c6 /sources/shiboken2/generator | |
parent | c9fb3900d92041fa7a2d3cbe2d689696343bd973 (diff) |
Refactor QtXmlToSphinx::readFromLocation()
Split out the code path for empty identifier
and port to QRegularExpression.
Task-number: PYSIDE-363
Change-Id: I6c0eeba1d62762e475de12d503fdc1a9d495d349
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r-- | sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index 17671de2d..91c69fc85 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -35,6 +35,7 @@ #include <typedatabase.h> #include <algorithm> #include <QtCore/QStack> +#include <QtCore/QRegularExpression> #include <QtCore/QTextStream> #include <QtCore/QXmlStreamReader> #include <QtCore/QFile> @@ -353,29 +354,34 @@ QString QtXmlToSphinx::readFromLocation(const QString &location, const QString & return QString(); } - QRegExp searchString(QLatin1String("//!\\s*\\[") + identifier + QLatin1String("\\]")); - QRegExp codeSnippetCode(QLatin1String("//!\\s*\\[[\\w\\d\\s]+\\]")); QString code; + if (identifier.isEmpty()) { + while (!inputFile.atEnd()) + code += QString::fromUtf8(inputFile.readLine()); + return code; + } + + const QRegularExpression searchString(QLatin1String("//!\\s*\\[") + + identifier + QLatin1String("\\]")); + Q_ASSERT(searchString.isValid()); + static const QRegularExpression codeSnippetCode(QLatin1String("//!\\s*\\[[\\w\\d\\s]+\\]")); + Q_ASSERT(codeSnippetCode.isValid()); - bool identifierIsEmpty = identifier.isEmpty(); bool getCode = false; while (!inputFile.atEnd()) { QString line = QString::fromUtf8(inputFile.readLine()); - if (identifierIsEmpty) { - code += line; - } else if (getCode && !line.contains(searchString)) { + if (getCode && !line.contains(searchString)) { line.remove(codeSnippetCode); code += line; } else if (line.contains(searchString)) { if (getCode) break; - else - getCode = true; + getCode = true; } } - if (!identifierIsEmpty && !getCode) { + if (!getCode) { QTextStream(errorMessage) << "Code snippet file found (" << QDir::toNativeSeparators(location) << "), but snippet [" << identifier << "] not found."; |