diff --git a/src/plugins/bazaar/annotationhighlighter.cpp b/src/plugins/bazaar/annotationhighlighter.cpp index 5980470a6f0..2fcebe0b1f5 100644 --- a/src/plugins/bazaar/annotationhighlighter.cpp +++ b/src/plugins/bazaar/annotationhighlighter.cpp @@ -26,6 +26,8 @@ #include "annotationhighlighter.h" #include "constants.h" +#include + using namespace Bazaar::Internal; using namespace Bazaar; @@ -37,7 +39,8 @@ BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &ch QString BazaarAnnotationHighlighter::changeNumber(const QString &block) const { - if (m_changeset.indexIn(block) != -1) - return m_changeset.cap(1); + const QRegularExpressionMatch match = m_changeset.match(block); + if (match.hasMatch()) + return match.captured(1); return QString(); } diff --git a/src/plugins/bazaar/annotationhighlighter.h b/src/plugins/bazaar/annotationhighlighter.h index 442f3defa93..7e16bbf0cd8 100644 --- a/src/plugins/bazaar/annotationhighlighter.h +++ b/src/plugins/bazaar/annotationhighlighter.h @@ -26,7 +26,7 @@ #pragma once #include -#include +#include namespace Bazaar { namespace Internal { @@ -39,7 +39,7 @@ public: private: QString changeNumber(const QString &block) const override; - mutable QRegExp m_changeset; + const QRegularExpression m_changeset; }; } // namespace Internal diff --git a/src/plugins/bazaar/bazaarclient.cpp b/src/plugins/bazaar/bazaarclient.cpp index 6fca62d459f..503eb4db886 100644 --- a/src/plugins/bazaar/bazaarclient.cpp +++ b/src/plugins/bazaar/bazaarclient.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -123,14 +123,18 @@ BranchInfo BazaarClient::synchronousBranchQuery(const QString &repositoryRoot) c QTextStream ts(&branchConfFile); QString branchLocation; QString isBranchBound; - QRegExp branchLocationRx(QLatin1String("bound_location\\s*=\\s*(.+)$")); - QRegExp isBranchBoundRx(QLatin1String("bound\\s*=\\s*(.+)$")); + QRegularExpression branchLocationRx("bound_location\\s*=\\s*(.+)$"); + QRegularExpression isBranchBoundRx("bound\\s*=\\s*(.+)$"); while (!ts.atEnd() && (branchLocation.isEmpty() || isBranchBound.isEmpty())) { const QString line = ts.readLine(); - if (branchLocationRx.indexIn(line) != -1) - branchLocation = branchLocationRx.cap(1); - else if (isBranchBoundRx.indexIn(line) != -1) - isBranchBound = isBranchBoundRx.cap(1); + QRegularExpressionMatch match = branchLocationRx.match(line); + if (match.hasMatch()) { + branchLocation = match.captured(1); + } else { + QRegularExpressionMatch match = isBranchBoundRx.match(line); + if (match.hasMatch()) + isBranchBound = match.captured(1); + } } if (isBranchBound.simplified().toLower() == QLatin1String("true")) return BranchInfo(branchLocation, true); diff --git a/src/plugins/bazaar/bazaarcommitwidget.cpp b/src/plugins/bazaar/bazaarcommitwidget.cpp index 23861568cea..c2f0da6bd9a 100644 --- a/src/plugins/bazaar/bazaarcommitwidget.cpp +++ b/src/plugins/bazaar/bazaarcommitwidget.cpp @@ -35,7 +35,7 @@ #include #include -#include +#include //see the git submit widget for details of the syntax Highlighter @@ -62,7 +62,7 @@ public: private: enum State { Header, Comment, Other }; const QTextCharFormat m_commentFormat; - QRegExp m_keywordPattern; + QRegularExpression m_keywordPattern; const QChar m_hashChar; }; @@ -97,15 +97,17 @@ void BazaarSubmitHighlighter::highlightBlock(const QString &text) case Comment: setFormat(0, text.size(), m_commentFormat); break; - case Other: + 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()) { QTextCharFormat charFormat = format(0); charFormat.setFontItalic(true); - setFormat(0, m_keywordPattern.matchedLength(), charFormat); + setFormat(0, match.capturedLength(), charFormat); } break; } + } } @@ -143,7 +145,7 @@ QString BazaarCommitWidget::committer() const QStringList BazaarCommitWidget::fixedBugs() const { - return m_bazaarCommitPanelUi.fixedBugsLineEdit->text().split(QRegExp(QLatin1String("\\s+"))); + return m_bazaarCommitPanelUi.fixedBugsLineEdit->text().split(QRegularExpression("\\s+")); } bool BazaarCommitWidget::isLocalOptionEnabled() const diff --git a/src/plugins/bazaar/bazaareditor.cpp b/src/plugins/bazaar/bazaareditor.cpp index ac811b16aa0..9bb05329f8b 100644 --- a/src/plugins/bazaar/bazaareditor.cpp +++ b/src/plugins/bazaar/bazaareditor.cpp @@ -62,16 +62,16 @@ QString BazaarEditorWidget::changeUnderCursor(const QTextCursor &cursorIn) const cursor.select(QTextCursor::LineUnderCursor); if (cursor.hasSelection()) { const QString line = cursor.selectedText(); - const int start = m_changesetId.indexIn(line); - if (start > -1) { - const QString match = m_changesetId.cap(0); - const int stop = start + match.length(); + const QRegularExpressionMatch match = m_changesetId.match(line); + if (match.hasMatch()) { + const int start = match.capturedStart(); + const int stop = match.capturedEnd(); if (start <= cursorCol && cursorCol <= stop) { cursor = cursorIn; cursor.select(QTextCursor::WordUnderCursor); if (cursor.hasSelection()) { const QString change = cursor.selectedText(); - if (m_exactChangesetId.exactMatch(change)) + if (m_exactChangesetId.match(change).hasMatch()) return change; } } diff --git a/src/plugins/bazaar/bazaareditor.h b/src/plugins/bazaar/bazaareditor.h index 96a9f1610f9..5421ec5cf46 100644 --- a/src/plugins/bazaar/bazaareditor.h +++ b/src/plugins/bazaar/bazaareditor.h @@ -27,7 +27,7 @@ #include -#include +#include namespace Bazaar { namespace Internal { @@ -44,8 +44,8 @@ private: VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter( const QSet &changes) const override; - mutable QRegExp m_changesetId; - mutable QRegExp m_exactChangesetId; + const QRegularExpression m_changesetId; + const QRegularExpression m_exactChangesetId; }; } // namespace Internal diff --git a/src/plugins/bazaar/constants.h b/src/plugins/bazaar/constants.h index f64c0eb27f7..4b6b6b66639 100644 --- a/src/plugins/bazaar/constants.h +++ b/src/plugins/bazaar/constants.h @@ -41,7 +41,7 @@ const char CHANGESET_ID[] = "^(" "| +[.0-9]+" // short "|[.0-9]+: " // line ")"; -const char CHANGESET_ID_EXACT[] = "([.0-9]+)"; +const char CHANGESET_ID_EXACT[] = "^([.0-9]+)$"; const char ANNOTATE_CHANGESET_ID[] = "([.0-9]+)"; // Base editor parameters