Perforce: Remove QRegExp use

Task-number: QTCREATORBUG-24098
Change-Id: Id234cc2206afd3e1372c25749e73d7c31c7ebd7f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2020-06-23 16:02:54 +02:00
parent 15ab47cb3c
commit 8b3e0d7122
2 changed files with 17 additions and 15 deletions

View File

@@ -66,6 +66,7 @@
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QRegularExpression>
#include <QSettings>
#include <QTextCodec>
@@ -783,7 +784,7 @@ void PerforcePluginPrivate::startSubmitProject()
QStringList filesLines = filesResult.stdOut.split(QLatin1Char('\n'));
QStringList depotFileNames;
foreach (const QString &line, filesLines) {
depotFileNames.append(line.left(line.lastIndexOf(QRegExp(QLatin1String("#[0-9]+\\s-\\s")))));
depotFileNames.append(line.left(line.lastIndexOf(QRegularExpression("#[0-9]+\\s-\\s"))));
}
if (depotFileNames.isEmpty()) {
VcsOutputWindow::appendWarning(tr("Project has no files"));
@@ -1635,9 +1636,9 @@ QString PerforcePluginPrivate::clientFilePath(const QString &serverFilePath)
if (response.error)
return QString();
QRegExp r(QLatin1String("\\.\\.\\.\\sclientFile\\s(.+)\n"));
r.setMinimal(true);
return r.indexIn(response.stdOut) != -1 ? r.cap(1).trimmed() : QString();
const QRegularExpression r("\\.\\.\\.\\sclientFile\\s(.+?)\n");
const QRegularExpressionMatch match = r.match(response.stdOut);
return match.hasMatch() ? match.captured(1).trimmed() : QString();
}
QString PerforcePluginPrivate::pendingChangesData()
@@ -1650,10 +1651,10 @@ QString PerforcePluginPrivate::pendingChangesData()
if (userResponse.error)
return QString();
QRegExp r(QLatin1String("User\\sname:\\s(\\S+)\\s*\n"));
const QRegularExpression r("User\\sname:\\s(\\S+?)\\s*?\n");
QTC_ASSERT(r.isValid(), return QString());
r.setMinimal(true);
const QString user = r.indexIn(userResponse.stdOut) != -1 ? r.cap(1).trimmed() : QString();
const QRegularExpressionMatch match = r.match(userResponse.stdOut);
const QString user = match.hasMatch() ? match.captured(1).trimmed() : QString();
if (user.isEmpty())
return QString();
args.clear();

View File

@@ -31,6 +31,8 @@
#include <vcsbase/submitfilemodel.h>
#include <utils/qtcassert.h>
#include <QRegularExpression>
namespace Perforce {
namespace Internal {
@@ -69,10 +71,9 @@ bool PerforceSubmitEditor::setFileContents(const QByteArray &contents)
bool PerforceSubmitEditor::parseText(QString text)
{
QRegExp formField(QLatin1String("^\\S+:"));
QRegularExpression formField(QLatin1String("^\\S+:"));
const QString newLine = QString(QLatin1Char('\n'));
int match;
int matchLen;
QTextStream stream(&text, QIODevice::ReadOnly);
QString line;
@@ -80,14 +81,14 @@ bool PerforceSubmitEditor::parseText(QString text)
QString value;
line = stream.readLine();
while (!stream.atEnd()) {
match = formField.indexIn(line);
if (match == 0) {
matchLen = formField.matchedLength();
const QRegularExpressionMatch match = formField.match(line);
if (match.hasMatch()) {
matchLen = match.capturedLength();
key = line.left(matchLen-1);
value = line.mid(matchLen) + newLine;
while (!stream.atEnd()) {
line = stream.readLine();
if (formField.indexIn(line) != -1)
if (line.indexOf(formField) != -1)
break;
value += line + newLine;
}
@@ -116,7 +117,7 @@ void PerforceSubmitEditor::updateFields()
lines.removeFirst(); // that is the line break after 'Description:'
lines.removeLast(); // that is the empty line at the end
const QRegExp leadingTabPattern = QRegExp(QLatin1String("^\\t"));
const QRegularExpression leadingTabPattern("^\\t");
QTC_CHECK(leadingTabPattern.isValid());
lines.replaceInStrings(leadingTabPattern, QString());
@@ -144,7 +145,7 @@ void PerforceSubmitEditor::updateEntries()
while (!lines.empty() && lines.last().isEmpty())
lines.removeLast();
// Description
lines.replaceInStrings(QRegExp(QLatin1String("^")), tab);
lines.replaceInStrings(QRegularExpression("^"), tab);
m_entries.insert(QLatin1String("Description"), newLine + lines.join(newLine) + QLatin1String("\n\n"));
QString files = newLine;
// Re-build the file spec '<tab>file#add' from the user data