forked from qt-creator/qt-creator
Gerrit: De-duplicate regular expression matching
Change-Id: I2bc3b2d5261153231204550634ece45d1038e5d9 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
f2b8e9acd1
commit
d32f53e176
@@ -40,10 +40,15 @@
|
|||||||
namespace Gerrit {
|
namespace Gerrit {
|
||||||
namespace Internal {
|
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 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())
|
if (match.hasMatch())
|
||||||
return match.captured(1);
|
return match.captured(1);
|
||||||
return QString();
|
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)
|
static bool replaceEntry(QString &line, const QString &type, const QString &value)
|
||||||
{
|
{
|
||||||
const QRegularExpression regexp("(?:^|\\s)" + type + "\\s(\\S+)");
|
const QRegularExpressionMatch match = entryMatch(line, type);
|
||||||
const QRegularExpressionMatch match = regexp.match(line);
|
|
||||||
if (!match.hasMatch())
|
if (!match.hasMatch())
|
||||||
return false;
|
return false;
|
||||||
line.replace(match.capturedStart(1), match.capturedLength(1), value);
|
line.replace(match.capturedStart(1), match.capturedLength(1), value);
|
||||||
|
Reference in New Issue
Block a user