QmlJS: Replace QRegExp by QRegularExpression

Task-number: QTCREATORBUG-24098
Change-Id: I70157bcbee67cf493e28b5bad97248877a25e5c6
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-07-17 12:13:06 +02:00
parent 9dec1680cc
commit 6e29adaae7
7 changed files with 39 additions and 33 deletions

View File

@@ -30,7 +30,7 @@
#include <QDebug>
#include <QLatin1String>
#include <QRegExp>
#include <QRegularExpression>
#include <cmath>
@@ -273,8 +273,8 @@ bool JsonCheck::visit(StringLiteral *ast)
const QString &pattern = m_schema->pattern();
if (!pattern.isEmpty()) {
QRegExp regExp(pattern);
if (regExp.indexIn(literal.toString()) == -1) {
const QRegularExpression regExp(pattern);
if (regExp.match(literal.toString()).hasMatch()) {
analysis()->m_messages.append(Message(ErrInvalidStringValuePattern,
ast->firstSourceLocation(),
QString(), QString(), false));

View File

@@ -35,7 +35,7 @@
#include <QCryptographicHash>
#include <QDir>
#include <QFileInfo>
#include <QRegExp>
#include <QRegularExpression>
#include <algorithm>
@@ -510,17 +510,19 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
}
QStringList splitPath = path.split(QLatin1Char('/'));
QRegExp vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
QRegExp safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
foreach (const ImportKey &importKey, packages) {
if (importKey.splitPath.size() == 1 && importKey.splitPath.at(0).isEmpty() && splitPath.length() > 0) {
// relocatable
QStringList myPath = splitPath;
if (vNr.indexIn(myPath.last()) == 0)
myPath.last() = vNr.cap(1);
QRegularExpressionMatch match = vNr.match(myPath.last());
if (match.hasMatch())
myPath.last() = match.captured(1);
for (int iPath = myPath.size(); iPath != 1; ) {
--iPath;
if (safeName.indexIn(myPath.at(iPath)) != 0)
match = safeName.match(myPath.at(iPath));
if (!match.hasMatch())
break;
ImportKey iKey(ImportType::Library, QStringList(myPath.mid(iPath)).join(QLatin1Char('.')),
importKey.majorVersion, importKey.minorVersion);
@@ -534,8 +536,8 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
}
}
if (cImport.possibleExports.isEmpty() && splitPath.size() > 0) {
QRegExp vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
QRegExp safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
int majorVersion = LanguageUtils::ComponentVersion::NoVersion;
int minorVersion = LanguageUtils::ComponentVersion::NoVersion;
@@ -546,20 +548,22 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
minorVersion = component.minorVersion;
}
if (vNr.indexIn(splitPath.last()) == 0) {
splitPath.last() = vNr.cap(1);
QRegularExpressionMatch match = vNr.match(splitPath.last());
if (match.hasMatch()) {
splitPath.last() = match.captured(1);
bool ok;
majorVersion = vNr.cap(2).toInt(&ok);
majorVersion = match.captured(2).toInt(&ok);
if (!ok)
majorVersion = LanguageUtils::ComponentVersion::NoVersion;
minorVersion = vNr.cap(3).toInt(&ok);
if (vNr.cap(3).isEmpty() || !ok)
minorVersion = match.captured(3).toInt(&ok);
if (match.captured(3).isEmpty() || !ok)
minorVersion = LanguageUtils::ComponentVersion::NoVersion;
}
for (int iPath = splitPath.size(); iPath != 1; ) {
--iPath;
if (safeName.indexIn(splitPath.at(iPath)) != 0)
match = safeName.match(splitPath.at(iPath));
if (!match.hasMatch())
break;
ImportKey iKey(ImportType::Library, QStringList(splitPath.mid(iPath)).join(QLatin1Char('.')),
majorVersion, minorVersion);

View File

@@ -34,7 +34,7 @@
#include <utils/qtcassert.h>
#include <QList>
#include <QRegExp>
#include <QRegularExpression>
//using namespace QmlJS;
@@ -294,7 +294,7 @@ protected:
}
if (packageName.isEmpty() && _compound) {
// check the comments in _compound for annotations
QRegExp uriAnnotation(QLatin1String("@uri\\s*([\\w\\.]*)"));
const QRegularExpression uriAnnotation(QLatin1String("@uri\\s*([\\w\\.]*)"));
// scan every comment between the pipes in
// {|
@@ -312,8 +312,9 @@ protected:
continue;
}
const QString comment = stringOf(commentToken);
if (uriAnnotation.indexIn(comment) != -1) {
packageName = uriAnnotation.cap(1);
const QRegularExpressionMatch match = uriAnnotation.match(comment);
if (match.hasMatch()) {
packageName = match.captured(1);
break;
}
}

View File

@@ -79,11 +79,11 @@ using namespace QmlJS;
QmlJSIndenter::QmlJSIndenter()
: caseOrDefault(QRegExp(QLatin1String(
"\\s*(?:"
: caseOrDefault(QRegularExpression(QLatin1String(
"^\\s*(?:"
"case\\b[^:]+|"
"default)"
"\\s*:.*")))
"\\s*:.*$")))
{
@@ -534,7 +534,7 @@ int QmlJSIndenter::indentForStandaloneLine()
readLine();
int indentChange = - *yyBraceDepth;
if (caseOrDefault.exactMatch(*yyLine))
if (caseOrDefault.match(*yyLine).hasMatch())
++indentChange;
/*
@@ -598,7 +598,7 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t
*/
indent -= ppIndentSize;
} else if (okay(typedIn, QLatin1Char(':'))) {
if (caseOrDefault.exactMatch(bottomLine)) {
if (caseOrDefault.match(bottomLine).hasMatch()) {
/*
Move a case label (or the ':' in front of a
constructor initialization list) one level to the

View File

@@ -28,7 +28,7 @@
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljslineinfo.h>
#include <QRegExp>
#include <QRegularExpression>
QT_FORWARD_DECLARE_CLASS(QTextBlock)
@@ -67,7 +67,7 @@ private:
int ppCommentOffset;
private:
QRegExp caseOrDefault;
QRegularExpression caseOrDefault;
};
} // namespace QmlJS

View File

@@ -45,7 +45,6 @@
#include <QFile>
#include <QFileInfo>
#include <QMetaObject>
#include <QRegExp>
#include <QTextDocument>
#include <QTextStream>
#include <QTimer>

View File

@@ -29,7 +29,7 @@
#include "qmljsmodelmanagerinterface.h"
#include "parser/qmljsengine_p.h"
#include <QRegExp>
#include <QRegularExpression>
using namespace QmlJS;
@@ -286,18 +286,20 @@ void ScopeChain::update() const
static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *chain)
{
const QRegExp importCommentPattern(QLatin1String("@scope\\s+(.*)"));
const QRegularExpression importCommentPattern(QLatin1String("@scope\\s+(.*)"));
foreach (const SourceLocation &commentLoc, chain->document()->engine()->comments()) {
const QString &comment = chain->document()->source().mid(commentLoc.begin(), commentLoc.length);
// find all @scope annotations
QStringList additionalScopes;
int lastOffset = -1;
QRegularExpressionMatch match;
forever {
lastOffset = importCommentPattern.indexIn(comment, lastOffset + 1);
match = importCommentPattern.match(comment, lastOffset + 1);
lastOffset = match.capturedStart();
if (lastOffset == -1)
break;
additionalScopes << QFileInfo(chain->document()->path() + QLatin1Char('/') + importCommentPattern.cap(1).trimmed()).absoluteFilePath();
additionalScopes << QFileInfo(chain->document()->path() + QLatin1Char('/') + match.captured(1).trimmed()).absoluteFilePath();
}
foreach (const QmlComponentChain *c, chain->instantiatingComponents())