aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/vcsbase
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2020-02-19 23:26:24 +0200
committerOrgad Shaneh <orgads@gmail.com>2020-02-21 08:28:34 +0000
commita83f0c5d74e45899f2412def152959147a12e2b1 (patch)
treea14abcccd87b0169f3f15e803ed50467ca05fcb6 /src/plugins/vcsbase
parente445f7aac3600b36af6b604852583891e473fcfe (diff)
VCS: Replace QRegExp with QRegularExpression in VcsBaseEditor
Change-Id: I8e8a6649e441597e29e88506d494ec69260bebd1 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: André Hartmann <aha_1980@gmx.de>
Diffstat (limited to 'src/plugins/vcsbase')
-rw-r--r--src/plugins/vcsbase/diffandloghighlighter.cpp18
-rw-r--r--src/plugins/vcsbase/diffandloghighlighter.h5
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.cpp71
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.h5
4 files changed, 54 insertions, 45 deletions
diff --git a/src/plugins/vcsbase/diffandloghighlighter.cpp b/src/plugins/vcsbase/diffandloghighlighter.cpp
index afdc72cc67..a2f0836f35 100644
--- a/src/plugins/vcsbase/diffandloghighlighter.cpp
+++ b/src/plugins/vcsbase/diffandloghighlighter.cpp
@@ -30,7 +30,7 @@
#include <utils/qtcassert.h>
#include <QDebug>
-#include <QRegExp>
+#include <QRegularExpression>
/*!
\class VcsBase::DiffAndLogHighlighter
@@ -88,8 +88,9 @@ static inline QTextCharFormat invertedColorFormat(const QTextCharFormat &in)
class DiffAndLogHighlighterPrivate
{
public:
- DiffAndLogHighlighterPrivate(DiffAndLogHighlighter *q_, const QRegExp &filePattern,
- const QRegExp &changePattern) :
+ DiffAndLogHighlighterPrivate(DiffAndLogHighlighter *q_,
+ const QRegularExpression &filePattern,
+ const QRegularExpression &changePattern) :
q(q_),
m_filePattern(filePattern),
m_changePattern(changePattern),
@@ -106,8 +107,8 @@ public:
DiffAndLogHighlighter *const q;
- mutable QRegExp m_filePattern;
- mutable QRegExp m_changePattern;
+ const QRegularExpression m_filePattern;
+ const QRegularExpression m_changePattern;
const QString m_locationIndicator;
const QChar m_diffInIndicator;
const QChar m_diffOutIndicator;
@@ -120,9 +121,9 @@ TextEditor::TextStyle DiffAndLogHighlighterPrivate::analyzeLine(const QString &t
{
// Do not match on git "--- a/" as a deleted line, check
// file first
- if (m_filePattern.indexIn(text) == 0)
+ if (m_filePattern.match(text).capturedStart() == 0)
return TextEditor::C_DIFF_FILE;
- if (m_changePattern.indexIn(text) == 0)
+ if (m_changePattern.match(text).capturedStart() == 0)
return TextEditor::C_LOG_CHANGE_LINE;
if (text.startsWith(m_diffInIndicator))
return TextEditor::C_ADDED_LINE;
@@ -141,7 +142,8 @@ void DiffAndLogHighlighterPrivate::updateOtherFormats()
}
// --- DiffAndLogHighlighter
-DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern) :
+DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegularExpression &filePattern,
+ const QRegularExpression &changePattern) :
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(nullptr)),
d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern))
{
diff --git a/src/plugins/vcsbase/diffandloghighlighter.h b/src/plugins/vcsbase/diffandloghighlighter.h
index 3847f287ba..c43f4a510d 100644
--- a/src/plugins/vcsbase/diffandloghighlighter.h
+++ b/src/plugins/vcsbase/diffandloghighlighter.h
@@ -30,7 +30,7 @@
#include <texteditor/syntaxhighlighter.h>
QT_BEGIN_NAMESPACE
-class QRegExp;
+class QRegularExpression;
class QTextCharFormat;
QT_END_NAMESPACE
@@ -45,7 +45,8 @@ class VCSBASE_EXPORT DiffAndLogHighlighter : public TextEditor::SyntaxHighlighte
Q_OBJECT
public:
- explicit DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern);
+ explicit DiffAndLogHighlighter(const QRegularExpression &filePattern,
+ const QRegularExpression &changePattern);
~DiffAndLogHighlighter() override;
void highlightBlock(const QString &text) override;
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp
index aae366dcb4..0c1e1eab24 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditor.cpp
@@ -51,7 +51,6 @@
#include <QFileInfo>
#include <QFile>
#include <QRegularExpression>
-#include <QRegExp>
#include <QSet>
#include <QTextCodec>
#include <QUrl>
@@ -403,7 +402,7 @@ private:
};
UrlData m_urlData;
- QRegExp m_pattern;
+ QRegularExpression m_pattern;
};
UrlTextCursorHandler::UrlTextCursorHandler(VcsBaseEditorWidget *editorWidget)
@@ -425,16 +424,17 @@ bool UrlTextCursorHandler::findContentsUnderCursor(const QTextCursor &cursor)
const QString line = cursorForUrl.selectedText();
const int cursorCol = cursor.columnNumber();
int urlMatchIndex = -1;
- do {
- urlMatchIndex = m_pattern.indexIn(line, urlMatchIndex + 1);
- if (urlMatchIndex != -1) {
- const QString url = m_pattern.cap(0);
- if (urlMatchIndex <= cursorCol && cursorCol <= urlMatchIndex + url.length()) {
- m_urlData.startColumn = urlMatchIndex;
- m_urlData.url = url;
- }
+ QRegularExpressionMatchIterator i = m_pattern.globalMatch(line);
+ while (i.hasNext()) {
+ const QRegularExpressionMatch match = i.next();
+ urlMatchIndex = match.capturedStart();
+ const QString url = match.captured(0);
+ if (urlMatchIndex <= cursorCol && cursorCol <= urlMatchIndex + url.length()) {
+ m_urlData.startColumn = urlMatchIndex;
+ m_urlData.url = url;
+ break;
}
- } while (urlMatchIndex != -1 && m_urlData.startColumn == -1);
+ };
}
return m_urlData.startColumn != -1;
@@ -475,7 +475,7 @@ QString UrlTextCursorHandler::currentContents() const
void UrlTextCursorHandler::setUrlPattern(const QString &pattern)
{
- m_pattern = QRegExp(pattern);
+ m_pattern = QRegularExpression(pattern);
QTC_ASSERT(m_pattern.isValid(), return);
}
@@ -555,8 +555,8 @@ public:
QString m_workingDirectory;
- QRegExp m_diffFilePattern;
- QRegExp m_logEntryPattern;
+ QRegularExpression m_diffFilePattern;
+ QRegularExpression m_logEntryPattern;
QRegularExpression m_annotationEntryPattern;
QRegularExpression m_annotationSeparatorPattern;
QList<int> m_entrySections; // line number where this section starts
@@ -652,30 +652,34 @@ void VcsBaseEditorWidget::setParameters(const VcsBaseEditorParameters *parameter
d->m_parameters = parameters;
}
-void VcsBaseEditorWidget::setDiffFilePattern(const QRegExp &pattern)
+static void regexpFromString(
+ const QString &pattern,
+ QRegularExpression *regexp,
+ QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption)
{
- QTC_ASSERT(pattern.isValid() && pattern.captureCount() >= 1, return);
- d->m_diffFilePattern = pattern;
+ const QRegularExpression re(pattern, options);
+ QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return);
+ *regexp = re;
}
-void VcsBaseEditorWidget::setLogEntryPattern(const QRegExp &pattern)
+void VcsBaseEditorWidget::setDiffFilePattern(const QString &pattern)
{
- QTC_ASSERT(pattern.isValid() && pattern.captureCount() >= 1, return);
- d->m_logEntryPattern = pattern;
+ regexpFromString(pattern, &d->m_diffFilePattern);
+}
+
+void VcsBaseEditorWidget::setLogEntryPattern(const QString &pattern)
+{
+ regexpFromString(pattern, &d->m_logEntryPattern);
}
void VcsBaseEditorWidget::setAnnotationEntryPattern(const QString &pattern)
{
- const QRegularExpression re(pattern, QRegularExpression::MultilineOption);
- QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return);
- d->m_annotationEntryPattern = re;
+ regexpFromString(pattern, &d->m_annotationEntryPattern, QRegularExpression::MultilineOption);
}
void VcsBaseEditorWidget::setAnnotationSeparatorPattern(const QString &pattern)
{
- const QRegularExpression re(pattern);
- QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return);
- d->m_annotationSeparatorPattern = re;
+ regexpFromString(pattern, &d->m_annotationSeparatorPattern);
}
bool VcsBaseEditorWidget::supportChangeLinks() const
@@ -881,7 +885,7 @@ void VcsBaseEditorWidget::slotPopulateDiffBrowser()
for (QTextBlock it = document()->begin(); it != cend; it = it.next(), lineNumber++) {
const QString text = it.text();
// Check for a new diff section (not repeating the last filename)
- if (d->m_diffFilePattern.indexIn(text) == 0) {
+ if (d->m_diffFilePattern.match(text).capturedStart() == 0) {
const QString file = fileNameFromDiffSpecification(it);
if (!file.isEmpty() && lastFileName != file) {
lastFileName = file;
@@ -905,9 +909,10 @@ void VcsBaseEditorWidget::slotPopulateLogBrowser()
for (QTextBlock it = document()->begin(); it != cend; it = it.next(), lineNumber++) {
const QString text = it.text();
// Check for a new log section (not repeating the last filename)
- if (d->m_logEntryPattern.indexIn(text) != -1) {
+ const QRegularExpressionMatch match = d->m_logEntryPattern.match(text);
+ if (match.hasMatch()) {
d->m_entrySections.push_back(d->m_entrySections.empty() ? 0 : lineNumber);
- QString entry = d->m_logEntryPattern.cap(1);
+ QString entry = match.captured(1);
QString subject = revisionSubject(it);
if (!subject.isEmpty()) {
if (subject.length() > 100) {
@@ -1215,7 +1220,8 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
unicode.append(QLatin1Char('\n'));
for (block = block.next() ; block.isValid() ; block = block.next()) {
const QString line = block.text();
- if (checkChunkLine(line, &chunkStart) || d->m_diffFilePattern.indexIn(line) == 0) {
+ if (checkChunkLine(line, &chunkStart)
+ || d->m_diffFilePattern.match(line).capturedStart() == 0) {
break;
} else {
unicode += line;
@@ -1535,8 +1541,9 @@ QString VcsBaseEditorWidget::fileNameFromDiffSpecification(const QTextBlock &inB
QString fileName;
for (QTextBlock block = inBlock; block.isValid(); block = block.previous()) {
const QString line = block.text();
- if (d->m_diffFilePattern.indexIn(line) != -1) {
- QString cap = d->m_diffFilePattern.cap(1);
+ const QRegularExpressionMatch match = d->m_diffFilePattern.match(line);
+ if (match.hasMatch()) {
+ QString cap = match.captured(1);
if (header)
header->prepend(line + QLatin1String("\n"));
if (fileName.isEmpty() && !cap.isEmpty())
diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h
index caf2d4575d..6e32037b68 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.h
+++ b/src/plugins/vcsbase/vcsbaseeditor.h
@@ -32,7 +32,6 @@
#include <QSet>
QT_BEGIN_NAMESPACE
-class QRegExp;
class QTextCodec;
class QTextCursor;
QT_END_NAMESPACE
@@ -145,9 +144,9 @@ protected:
// virtual functions).
VcsBaseEditorWidget();
// Pattern for diff header. File name must be in the first capture group
- void setDiffFilePattern(const QRegExp &pattern);
+ void setDiffFilePattern(const QString &pattern);
// Pattern for log entry. hash/revision number must be in the first capture group
- void setLogEntryPattern(const QRegExp &pattern);
+ void setLogEntryPattern(const QString &pattern);
// Pattern for annotation entry. hash/revision number must be in the first capture group
void setAnnotationEntryPattern(const QString &pattern);
// Pattern for annotation separator. Lookup will stop on match.