From d32f53e176c0c1bd3ed17b131a32336dfd59b98f Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 2 Mar 2017 08:36:28 +0200 Subject: Gerrit: De-duplicate regular expression matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2bc3b2d5261153231204550634ece45d1038e5d9 Reviewed-by: André Hartmann --- src/plugins/git/gerrit/authenticationdialog.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/plugins/git/gerrit/authenticationdialog.cpp') diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp index c51b47bbc0..435177802f 100644 --- a/src/plugins/git/gerrit/authenticationdialog.cpp +++ b/src/plugins/git/gerrit/authenticationdialog.cpp @@ -40,10 +40,15 @@ namespace Gerrit { namespace Internal { -static QString findEntry(const QString &line, const QString &type) +static QRegularExpressionMatch entryMatch(const QString &line, const QString &type) { const QRegularExpression regexp("(?:^|\\s)" + type + "\\s(\\S+)"); - const QRegularExpressionMatch match = regexp.match(line); + return regexp.match(line); +} + +static QString findEntry(const QString &line, const QString &type) +{ + const QRegularExpressionMatch match = entryMatch(line, type); if (match.hasMatch()) return match.captured(1); return QString(); @@ -51,8 +56,7 @@ static QString findEntry(const QString &line, const QString &type) static bool replaceEntry(QString &line, const QString &type, const QString &value) { - const QRegularExpression regexp("(?:^|\\s)" + type + "\\s(\\S+)"); - const QRegularExpressionMatch match = regexp.match(line); + const QRegularExpressionMatch match = entryMatch(line, type); if (!match.hasMatch()) return false; line.replace(match.capturedStart(1), match.capturedLength(1), value); -- cgit v1.2.1