Bazaar: Replace QRegExp

Task-number: QTCREATORBUG-24098
Change-Id: I450d5756359596495f501759670970c9c541d4d9
Reviewed-by: Hugues Delorme <delorme.hugues@fougue.pro>
This commit is contained in:
hjk
2020-06-23 16:36:59 +02:00
parent f7242cdce9
commit a6fe2efd4e
7 changed files with 35 additions and 26 deletions

View File

@@ -26,6 +26,8 @@
#include "annotationhighlighter.h" #include "annotationhighlighter.h"
#include "constants.h" #include "constants.h"
#include <QRegularExpression>
using namespace Bazaar::Internal; using namespace Bazaar::Internal;
using namespace Bazaar; using namespace Bazaar;
@@ -37,7 +39,8 @@ BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &ch
QString BazaarAnnotationHighlighter::changeNumber(const QString &block) const QString BazaarAnnotationHighlighter::changeNumber(const QString &block) const
{ {
if (m_changeset.indexIn(block) != -1) const QRegularExpressionMatch match = m_changeset.match(block);
return m_changeset.cap(1); if (match.hasMatch())
return match.captured(1);
return QString(); return QString();
} }

View File

@@ -26,7 +26,7 @@
#pragma once #pragma once
#include <vcsbase/baseannotationhighlighter.h> #include <vcsbase/baseannotationhighlighter.h>
#include <QRegExp> #include <QRegularExpression>
namespace Bazaar { namespace Bazaar {
namespace Internal { namespace Internal {
@@ -39,7 +39,7 @@ public:
private: private:
QString changeNumber(const QString &block) const override; QString changeNumber(const QString &block) const override;
mutable QRegExp m_changeset; const QRegularExpression m_changeset;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -36,7 +36,7 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QRegExp> #include <QRegularExpression>
#include <QTextStream> #include <QTextStream>
#include <QDebug> #include <QDebug>
@@ -123,14 +123,18 @@ BranchInfo BazaarClient::synchronousBranchQuery(const QString &repositoryRoot) c
QTextStream ts(&branchConfFile); QTextStream ts(&branchConfFile);
QString branchLocation; QString branchLocation;
QString isBranchBound; QString isBranchBound;
QRegExp branchLocationRx(QLatin1String("bound_location\\s*=\\s*(.+)$")); QRegularExpression branchLocationRx("bound_location\\s*=\\s*(.+)$");
QRegExp isBranchBoundRx(QLatin1String("bound\\s*=\\s*(.+)$")); QRegularExpression isBranchBoundRx("bound\\s*=\\s*(.+)$");
while (!ts.atEnd() && (branchLocation.isEmpty() || isBranchBound.isEmpty())) { while (!ts.atEnd() && (branchLocation.isEmpty() || isBranchBound.isEmpty())) {
const QString line = ts.readLine(); const QString line = ts.readLine();
if (branchLocationRx.indexIn(line) != -1) QRegularExpressionMatch match = branchLocationRx.match(line);
branchLocation = branchLocationRx.cap(1); if (match.hasMatch()) {
else if (isBranchBoundRx.indexIn(line) != -1) branchLocation = match.captured(1);
isBranchBound = isBranchBoundRx.cap(1); } else {
QRegularExpressionMatch match = isBranchBoundRx.match(line);
if (match.hasMatch())
isBranchBound = match.captured(1);
}
} }
if (isBranchBound.simplified().toLower() == QLatin1String("true")) if (isBranchBound.simplified().toLower() == QLatin1String("true"))
return BranchInfo(branchLocation, true); return BranchInfo(branchLocation, true);

View File

@@ -35,7 +35,7 @@
#include <QTextEdit> #include <QTextEdit>
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QRegularExpression>
//see the git submit widget for details of the syntax Highlighter //see the git submit widget for details of the syntax Highlighter
@@ -62,7 +62,7 @@ public:
private: private:
enum State { Header, Comment, Other }; enum State { Header, Comment, Other };
const QTextCharFormat m_commentFormat; const QTextCharFormat m_commentFormat;
QRegExp m_keywordPattern; QRegularExpression m_keywordPattern;
const QChar m_hashChar; const QChar m_hashChar;
}; };
@@ -97,16 +97,18 @@ void BazaarSubmitHighlighter::highlightBlock(const QString &text)
case Comment: case Comment:
setFormat(0, text.size(), m_commentFormat); setFormat(0, text.size(), m_commentFormat);
break; break;
case Other: case Other: {
// Format key words ("Task:") italic // 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); QTextCharFormat charFormat = format(0);
charFormat.setFontItalic(true); charFormat.setFontItalic(true);
setFormat(0, m_keywordPattern.matchedLength(), charFormat); setFormat(0, match.capturedLength(), charFormat);
} }
break; break;
} }
} }
}
BazaarCommitWidget::BazaarCommitWidget() : m_bazaarCommitPanel(new QWidget) BazaarCommitWidget::BazaarCommitWidget() : m_bazaarCommitPanel(new QWidget)
@@ -143,7 +145,7 @@ QString BazaarCommitWidget::committer() const
QStringList BazaarCommitWidget::fixedBugs() 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 bool BazaarCommitWidget::isLocalOptionEnabled() const

View File

@@ -62,16 +62,16 @@ QString BazaarEditorWidget::changeUnderCursor(const QTextCursor &cursorIn) const
cursor.select(QTextCursor::LineUnderCursor); cursor.select(QTextCursor::LineUnderCursor);
if (cursor.hasSelection()) { if (cursor.hasSelection()) {
const QString line = cursor.selectedText(); const QString line = cursor.selectedText();
const int start = m_changesetId.indexIn(line); const QRegularExpressionMatch match = m_changesetId.match(line);
if (start > -1) { if (match.hasMatch()) {
const QString match = m_changesetId.cap(0); const int start = match.capturedStart();
const int stop = start + match.length(); const int stop = match.capturedEnd();
if (start <= cursorCol && cursorCol <= stop) { if (start <= cursorCol && cursorCol <= stop) {
cursor = cursorIn; cursor = cursorIn;
cursor.select(QTextCursor::WordUnderCursor); cursor.select(QTextCursor::WordUnderCursor);
if (cursor.hasSelection()) { if (cursor.hasSelection()) {
const QString change = cursor.selectedText(); const QString change = cursor.selectedText();
if (m_exactChangesetId.exactMatch(change)) if (m_exactChangesetId.match(change).hasMatch())
return change; return change;
} }
} }

View File

@@ -27,7 +27,7 @@
#include <vcsbase/vcsbaseeditor.h> #include <vcsbase/vcsbaseeditor.h>
#include <QRegExp> #include <QRegularExpression>
namespace Bazaar { namespace Bazaar {
namespace Internal { namespace Internal {
@@ -44,8 +44,8 @@ private:
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter( VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(
const QSet<QString> &changes) const override; const QSet<QString> &changes) const override;
mutable QRegExp m_changesetId; const QRegularExpression m_changesetId;
mutable QRegExp m_exactChangesetId; const QRegularExpression m_exactChangesetId;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -41,7 +41,7 @@ const char CHANGESET_ID[] = "^("
"| +[.0-9]+" // short "| +[.0-9]+" // short
"|[.0-9]+: " // line "|[.0-9]+: " // line
")"; ")";
const char CHANGESET_ID_EXACT[] = "([.0-9]+)"; const char CHANGESET_ID_EXACT[] = "^([.0-9]+)$";
const char ANNOTATE_CHANGESET_ID[] = "([.0-9]+)"; const char ANNOTATE_CHANGESET_ID[] = "([.0-9]+)";
// Base editor parameters // Base editor parameters