diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index 85d414b9b9a..c67db2f8b41 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include #include @@ -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 branchRegexp; + QScopedPointer 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()) { diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 70f34604ae3..8a29f903dcf 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -78,7 +78,7 @@ #include #include #include -#include +#include #include #include #include @@ -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); } diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 940945d3be6..404dd28d506 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include @@ -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; } diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h index 0377c2d6806..b24639a1d6d 100644 --- a/src/plugins/git/giteditor.h +++ b/src/plugins/git/giteditor.h @@ -27,7 +27,7 @@ #include -#include +#include 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; }; diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp index 763a3b9f79f..4f881833914 100644 --- a/src/plugins/git/githighlighters.cpp +++ b/src/plugins/git/githighlighters.cpp @@ -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)); diff --git a/src/plugins/git/githighlighters.h b/src/plugins/git/githighlighters.h index 27ab98036e5..9cedb727d82 100644 --- a/src/plugins/git/githighlighters.h +++ b/src/plugins/git/githighlighters.h @@ -27,7 +27,7 @@ #include -#include +#include 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 m_actions; }; diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index 308b34fba69..def70f08ac9 100644 --- a/src/plugins/git/gitsubmiteditorwidget.cpp +++ b/src/plugins/git/gitsubmiteditorwidget.cpp @@ -38,7 +38,6 @@ #include #include -#include #include #include diff --git a/src/plugins/git/gitsubmiteditorwidget.h b/src/plugins/git/gitsubmiteditorwidget.h index 1387d6e341a..9da282e9def 100644 --- a/src/plugins/git/gitsubmiteditorwidget.h +++ b/src/plugins/git/gitsubmiteditorwidget.h @@ -32,7 +32,6 @@ #include #include -#include #include QT_BEGIN_NAMESPACE