forked from qt-creator/qt-creator
Git: Replace QRegExp by QRegularExpression
Task-number: QTCREATORBUG-24098 Change-Id: I77a2e9959981b2e173142253baf1668d57982a2e Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -479,20 +479,20 @@ QString GerritPlugin::findLocalRepository(QString project, const QString &branch
|
||||
project.remove(0, slashPos + 1);
|
||||
// When looking at branch 1.7, try to check folders
|
||||
// "qtbase_17", 'qtbase1.7' with a semi-smart regular expression.
|
||||
QScopedPointer<QRegExp> branchRegexp;
|
||||
QScopedPointer<QRegularExpression> branchRegexp;
|
||||
if (!branch.isEmpty() && branch != "master") {
|
||||
QString branchPattern = branch;
|
||||
branchPattern.replace('.', "[\\.-_]?");
|
||||
const QString pattern = '^' + project
|
||||
+ "[-_]?"
|
||||
+ branchPattern + '$';
|
||||
branchRegexp.reset(new QRegExp(pattern));
|
||||
branchRegexp.reset(new QRegularExpression(pattern));
|
||||
if (!branchRegexp->isValid())
|
||||
branchRegexp.reset(); // Oops.
|
||||
}
|
||||
for (const QString &repository : gitRepositories) {
|
||||
const QString fileName = Utils::FilePath::fromString(repository).fileName();
|
||||
if ((!branchRegexp.isNull() && branchRegexp->exactMatch(fileName))
|
||||
if ((!branchRegexp.isNull() && branchRegexp->match(fileName).hasMatch())
|
||||
|| fileName == project) {
|
||||
// Perform a check on the branch.
|
||||
if (branch.isEmpty()) {
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextBlock>
|
||||
#include <QToolButton>
|
||||
#include <QTextCodec>
|
||||
@@ -702,20 +702,22 @@ private:
|
||||
|
||||
void readStdOut(const QString &data)
|
||||
{
|
||||
static QRegExp patchFailedRE("Patch failed at ([^\\n]*)");
|
||||
static QRegExp conflictedFilesRE("Merge conflict in ([^\\n]*)");
|
||||
if (patchFailedRE.indexIn(data) != -1)
|
||||
m_commit = patchFailedRE.cap(1);
|
||||
int fileIndex = -1;
|
||||
while ((fileIndex = conflictedFilesRE.indexIn(data, fileIndex + 1)) != -1)
|
||||
m_files.append(conflictedFilesRE.cap(1));
|
||||
static const QRegularExpression patchFailedRE("Patch failed at ([^\\n]*)");
|
||||
static const QRegularExpression conflictedFilesRE("Merge conflict in ([^\\n]*)");
|
||||
const QRegularExpressionMatch match = patchFailedRE.match(data);
|
||||
if (match.hasMatch())
|
||||
m_commit = match.captured(1);
|
||||
QRegularExpressionMatchIterator it = conflictedFilesRE.globalMatch(data);
|
||||
while (it.hasNext())
|
||||
m_files.append(it.next().captured(1));
|
||||
}
|
||||
|
||||
void readStdErr(const QString &data)
|
||||
{
|
||||
static QRegExp couldNotApplyRE("[Cc]ould not (?:apply|revert) ([^\\n]*)");
|
||||
if (couldNotApplyRE.indexIn(data) != -1)
|
||||
m_commit = couldNotApplyRE.cap(1);
|
||||
static const QRegularExpression couldNotApplyRE("[Cc]ould not (?:apply|revert) ([^\\n]*)");
|
||||
const QRegularExpressionMatch match = couldNotApplyRE.match(data);
|
||||
if (match.hasMatch())
|
||||
m_commit = match.captured(1);
|
||||
}
|
||||
private:
|
||||
QString m_workingDirectory;
|
||||
@@ -738,11 +740,12 @@ private:
|
||||
|
||||
void parseProgress(const QString &text) override
|
||||
{
|
||||
if (m_progressExp.lastIndexIn(text) != -1)
|
||||
setProgressAndMaximum(m_progressExp.cap(1).toInt(), m_progressExp.cap(2).toInt());
|
||||
const QRegularExpressionMatch match = m_progressExp.match(text);
|
||||
if (match.hasMatch())
|
||||
setProgressAndMaximum(match.captured(1).toInt(), match.captured(2).toInt());
|
||||
}
|
||||
|
||||
QRegExp m_progressExp;
|
||||
const QRegularExpression m_progressExp;
|
||||
};
|
||||
|
||||
static inline QString msgRepositoryNotFound(const QString &dir)
|
||||
@@ -3546,12 +3549,13 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
|
||||
// cut 'git version 1.6.5.1.sha'
|
||||
// another form: 'git version 1.9.rc1'
|
||||
const QString output = resp.stdOut();
|
||||
QRegExp versionPattern("^[^\\d]+(\\d+)\\.(\\d+)\\.(\\d+|rc\\d).*$");
|
||||
const QRegularExpression versionPattern("^[^\\d]+(\\d+)\\.(\\d+)\\.(\\d+|rc\\d).*$");
|
||||
QTC_ASSERT(versionPattern.isValid(), return 0);
|
||||
QTC_ASSERT(versionPattern.exactMatch(output), return 0);
|
||||
const unsigned majorV = versionPattern.cap(1).toUInt(nullptr, 16);
|
||||
const unsigned minorV = versionPattern.cap(2).toUInt(nullptr, 16);
|
||||
const unsigned patchV = versionPattern.cap(3).toUInt(nullptr, 16);
|
||||
const QRegularExpressionMatch match = versionPattern.match(output);
|
||||
QTC_ASSERT(match.hasMatch(), return 0);
|
||||
const unsigned majorV = match.captured(1).toUInt(nullptr, 16);
|
||||
const unsigned minorV = match.captured(2).toUInt(nullptr, 16);
|
||||
const unsigned patchV = match.captured(3).toUInt(nullptr, 16);
|
||||
return version(majorV, minorV, patchV);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QTextBlock>
|
||||
#include <QTextCodec>
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
};
|
||||
|
||||
GitEditorWidget::GitEditorWidget() :
|
||||
m_changeNumberPattern(CHANGE_PATTERN)
|
||||
m_changeNumberPattern(QRegularExpression::anchoredPattern(CHANGE_PATTERN))
|
||||
{
|
||||
QTC_ASSERT(m_changeNumberPattern.isValid(), return);
|
||||
/* Diff format:
|
||||
@@ -132,7 +132,7 @@ QString GitEditorWidget::changeUnderCursor(const QTextCursor &c) const
|
||||
if (!cursor.hasSelection())
|
||||
return QString();
|
||||
const QString change = cursor.selectedText();
|
||||
if (m_changeNumberPattern.exactMatch(change))
|
||||
if (m_changeNumberPattern.match(change).hasMatch())
|
||||
return change;
|
||||
return QString();
|
||||
}
|
||||
@@ -352,9 +352,10 @@ QString GitEditorWidget::fileNameForLine(int line) const
|
||||
// 7971b6e7 share/qtcreator/dumper/dumper.py (hjk
|
||||
QTextBlock block = document()->findBlockByLineNumber(line - 1);
|
||||
QTC_ASSERT(block.isValid(), return source());
|
||||
static QRegExp renameExp("^" CHANGE_PATTERN "\\s+([^(]+)");
|
||||
if (renameExp.indexIn(block.text()) != -1) {
|
||||
const QString fileName = renameExp.cap(1).trimmed();
|
||||
static QRegularExpression renameExp("^" CHANGE_PATTERN "\\s+([^(]+)");
|
||||
const QRegularExpressionMatch match = renameExp.match(block.text());
|
||||
if (match.hasMatch()) {
|
||||
const QString fileName = match.captured(1).trimmed();
|
||||
if (!fileName.isEmpty())
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <vcsbase/vcsbaseeditor.h>
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Utils { class FancyLineEdit; }
|
||||
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
QString fileNameForLine(int line) const override;
|
||||
QString sourceWorkingDirectory() const;
|
||||
|
||||
mutable QRegExp m_changeNumberPattern;
|
||||
const QRegularExpression m_changeNumberPattern;
|
||||
GitLogFilterWidget *m_logFilterWidget = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace Internal {
|
||||
static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
||||
|
||||
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
||||
TextEditor::SyntaxHighlighter(parent)
|
||||
TextEditor::SyntaxHighlighter(parent),
|
||||
m_keywordPattern("^[\\w-]+:")
|
||||
{
|
||||
setDefaultTextFormatCategories();
|
||||
m_keywordPattern.setPattern("^[\\w-]+:");
|
||||
m_hashChar = '#';
|
||||
QTC_CHECK(m_keywordPattern.isValid());
|
||||
}
|
||||
@@ -73,10 +73,11 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
case Other:
|
||||
// Format key words ("Task:") italic
|
||||
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
|
||||
const QRegularExpressionMatch match = m_keywordPattern.match(text);
|
||||
if (match.hasMatch() && match.capturedStart(0) == 0) {
|
||||
QTextCharFormat charFormat = format(0);
|
||||
charFormat.setFontItalic(true);
|
||||
setFormat(0, m_keywordPattern.matchedLength(), charFormat);
|
||||
setFormat(0, match.capturedLength(), charFormat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -130,20 +131,21 @@ void GitRebaseHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
if (text.startsWith(m_hashChar)) {
|
||||
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
||||
int changeIndex = 0;
|
||||
while ((changeIndex = m_changeNumberPattern.indexIn(text, changeIndex)) != -1) {
|
||||
const int changeLen = m_changeNumberPattern.matchedLength();
|
||||
setFormat(changeIndex, changeLen, formatForCategory(Format_Change));
|
||||
changeIndex += changeLen;
|
||||
QRegularExpressionMatchIterator it = m_changeNumberPattern.globalMatch(text);
|
||||
while (it.hasNext()) {
|
||||
const QRegularExpressionMatch match = it.next();
|
||||
setFormat(match.capturedStart(), match.capturedLength(), formatForCategory(Format_Change));
|
||||
}
|
||||
} else {
|
||||
for (const RebaseAction &action : qAsConst(m_actions)) {
|
||||
if (action.exp.indexIn(text) != -1) {
|
||||
const int len = action.exp.matchedLength();
|
||||
const QRegularExpressionMatch match = action.exp.match(text);
|
||||
if (match.hasMatch()) {
|
||||
const int len = match.capturedLength();
|
||||
setFormat(0, len, formatForCategory(action.formatCategory));
|
||||
const int changeIndex = m_changeNumberPattern.indexIn(text, len);
|
||||
if (changeIndex != -1) {
|
||||
const int changeLen = m_changeNumberPattern.matchedLength();
|
||||
const QRegularExpressionMatch changeMatch = m_changeNumberPattern.match(text, len);
|
||||
const int changeIndex = changeMatch.capturedStart();
|
||||
if (changeMatch.hasMatch()) {
|
||||
const int changeLen = changeMatch.capturedLength();
|
||||
const int descStart = changeIndex + changeLen + 1;
|
||||
setFormat(changeIndex, changeLen, formatForCategory(Format_Change));
|
||||
setFormat(descStart, text.size() - descStart, formatForCategory(Format_Description));
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
enum State { None = -1, Header, Other };
|
||||
QRegExp m_keywordPattern;
|
||||
const QRegularExpression m_keywordPattern;
|
||||
QChar m_hashChar;
|
||||
};
|
||||
|
||||
@@ -72,12 +72,12 @@ private:
|
||||
class RebaseAction
|
||||
{
|
||||
public:
|
||||
mutable QRegExp exp;
|
||||
const QRegularExpression exp;
|
||||
Format formatCategory;
|
||||
RebaseAction(const QString ®exp, const Format formatCategory);
|
||||
};
|
||||
const QChar m_hashChar;
|
||||
QRegExp m_changeNumberPattern;
|
||||
const QRegularExpression m_changeNumberPattern;
|
||||
QList<RebaseAction> m_actions;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QGroupBox>
|
||||
#include <QRegExp>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <vcsbase/submiteditorwidget.h>
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user