Replace QRegExp with QRegularExpression

Reviewers: kbasan, msutcliffe

Reviewed By: kbasan, msutcliffe

Subscribers: jenkins

Differential Revision: https://dev.swift-project.org/D11
This commit is contained in:
Mathew Sutcliffe
2017-05-05 22:35:25 +01:00
parent 94fbfeefdb
commit d5ab73e1bc
17 changed files with 55 additions and 54 deletions

View File

@@ -49,7 +49,7 @@
#include <QJsonParseError>
#include <QJsonValue>
#include <QList>
#include <QRegExp>
#include <QRegularExpression>
#include <QTextCodec>
#include <QVector>
#include <Qt>
@@ -1062,7 +1062,7 @@ namespace BlackCore
{
// detect the stupid z1, z2, z3 placeholders
//! \fixme: Anything better as this stupid code here?
const QString test = fixed.toLower().remove(QRegExp("[\\n\\t\\r]"));
const QString test = fixed.toLower().remove(QRegularExpression("[\\n\\t\\r]"));
if (test == "z") return;
if (test.startsWith("z") && test.length() == 2) return; // z1, z2, ..
if (test.length() == 1) return; // sometimes just z
@@ -1088,8 +1088,8 @@ namespace BlackCore
}
auto cruiseAltString = cbvar_cast(cbvar)->fromFSD(fp->cruiseAltitude);
static const QRegExp withUnit("\\D+");
if (!cruiseAltString.isEmpty() && withUnit.indexIn(cruiseAltString) < 0)
thread_local const QRegularExpression withUnit("\\D+");
if (!cruiseAltString.isEmpty() && !withUnit.match(cruiseAltString).hasMatch())
{
cruiseAltString += "ft";
}

View File

@@ -35,7 +35,6 @@
#include <QMetaObject>
#include <QNetworkReply>
#include <QReadLocker>
#include <QRegExp>
#include <QRegularExpression>
#include <QScopedPointer>
#include <QScopedPointerDeleteLater>
@@ -317,7 +316,7 @@ namespace BlackCore
{
// http://uk.flightaware.com/about/faq_aircraft_flight_plan_suffix.rvt
// we expect something like H/B772/F B773 B773/F
static const QRegularExpression reg("/.");
thread_local const QRegularExpression reg("/.");
aircraftIcaoCode = aircraftIcaoCode.replace(reg, "").trimmed().toUpper();
if (CAircraftIcaoCode::isValidDesignator(aircraftIcaoCode))
{

View File

@@ -20,7 +20,6 @@
#include <QList>
#include <QMetaObject>
#include <QNetworkReply>
#include <QRegExp>
#include <QScopedPointer>
#include <QScopedPointerDeleteLater>
#include <QString>

View File

@@ -37,7 +37,7 @@
#include <QPlainTextEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QTabBar>
#include <QCompleter>
#include <Qt>
@@ -270,9 +270,9 @@ namespace BlackGui
flightPlan.setTakeoffTimePlanned(v);
}
static const QRegExp withUnit("\\D+");
thread_local const QRegularExpression withUnit("\\D+");
v = ui->le_CrusingAltitude->text().trimmed();
if (!v.isEmpty() && withUnit.indexIn(v) < 0)
if (!v.isEmpty() && !withUnit.match(v).hasMatch())
{
v += "ft";
ui->le_CrusingAltitude->setText(v);

View File

@@ -13,6 +13,8 @@
#include "blackmisc/logmessage.h"
#include "blackconfig/buildconfig.h"
#include <QRegularExpression>
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::FsCommon;
@@ -176,7 +178,7 @@ namespace BlackGui
const QString raw = rawString.trimmed();
if (raw.isEmpty()) { return QStringList(); }
QStringList dirs;
const QStringList rawLines = raw.split(QRegExp("\n|\r\n|\r"));
const QStringList rawLines = raw.split(QRegularExpression("\n|\r\n|\r"));
for (const QString &l : rawLines)
{
const QString normalized = CFileUtils::normalizeFilePathToQtStandard(l);

View File

@@ -229,10 +229,10 @@ namespace BlackGui
void CWeatherComponent::setupInputValidators()
{
QRegExp reIcaoOrLatitude("^[a-zA-Z]{4}|-?\\d{1,2}[,.]?\\d+$", Qt::CaseInsensitive);
ui->le_LatOrIcao->setValidator(new QRegExpValidator(reIcaoOrLatitude, this));
QRegExp reLongitude("^-?\\d{1,2}[,.]?\\d+$", Qt::CaseInsensitive);
ui->le_Lon->setValidator(new QRegExpValidator(reLongitude, this));
QRegularExpression reIcaoOrLatitude("^[a-zA-Z]{4}|-?\\d{1,2}[,.]?\\d+$", QRegularExpression::CaseInsensitiveOption);
ui->le_LatOrIcao->setValidator(new QRegularExpressionValidator(reIcaoOrLatitude, this));
QRegularExpression reLongitude("^-?\\d{1,2}[,.]?\\d+$", QRegularExpression::CaseInsensitiveOption);
ui->le_Lon->setValidator(new QRegularExpressionValidator(reLongitude, this));
}
void CWeatherComponent::setupCompleter()

View File

@@ -39,7 +39,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QProcess>
#include <QRegExp>
#include <QRegularExpression>
#include <QSplashScreen>
#include <QStyleFactory>
#include <QStringList>
@@ -244,7 +244,7 @@ namespace BlackGui
html += "</td></tr>\n";
}
html += "<tr><td>";
static const QRegExp reg("[ ]{2,}");
thread_local const QRegularExpression reg("[ ]{2,}");
html += lt.replace(reg, "</td><td>");
pendingTr = true;
}

View File

@@ -21,7 +21,7 @@
#include <QFlags>
#include <QFont>
#include <QIODevice>
#include <QRegExp>
#include <QRegularExpression>
#include <QStyleOption>
#include <QStylePainter>
#include <QTextStream>
@@ -101,9 +101,8 @@ namespace BlackGui
{
const QString s = this->style(fileNameFonts()).toLower();
if (!s.contains("color:")) return "red";
QRegExp rx("color:\\s*(#*\\w+);");
rx.indexIn(s);
const QString c = rx.cap(1);
thread_local const QRegularExpression rx("color:\\s*(#*\\w+);");
const QString c = rx.match(s).captured(1);
return c.isEmpty() ? "red" : c;
}

View File

@@ -10,7 +10,6 @@
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/compare.h"
#include <QRegExp>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QStringList>
@@ -126,10 +125,10 @@ namespace BlackMisc
if (this->m_callsign.length() < 3) { return ""; }
if (this->isAtcCallsign()) { return ""; }
static const QRegExp regExp("^[A-Z]{3,}");
const int pos = regExp.indexIn(this->m_callsign);
if (pos < 0) { return ""; }
const QString airline = regExp.cap(0);
thread_local const QRegularExpression regExp("^[A-Z]{3,}");
QRegularExpressionMatch match = regExp.match(this->m_callsign);
if (!match.hasMatch()) { return QString(); }
const QString airline = match.captured(0);
if (airline.length() == 3) { return airline; } // we allow 3 letters
if (airline.length() == 4 && airline.startsWith('V')) { return airline; } // we allow virtual 4 letter codes, e.g. VDLD
return ""; // invalid

View File

@@ -11,7 +11,7 @@
#include "blackmisc/propertyindex.h"
#include "blackmisc/variant.h"
#include <QRegExp>
#include <QRegularExpression>
#include <Qt>
#include <QtDebug>
@@ -131,8 +131,8 @@ namespace BlackMisc
qint32 tc = transponderCode.toInt(&number);
if (!number) return false;
if (tc < 0 || tc > 7777) return false;
QRegExp rx("[0-7]{1,4}");
return rx.exactMatch(transponderCode);
thread_local const QRegularExpression rx("^[0-7]{1,4}$");
return rx.match(transponderCode).hasMatch();
}
bool CTransponder::isValidTransponderCode(qint32 transponderCode)

View File

@@ -12,6 +12,7 @@
#include <QJsonObject>
#include <QJsonValue>
#include <QRegularExpression>
#include <Qt>
namespace BlackMisc
@@ -33,9 +34,9 @@ namespace BlackMisc
{
if (countryName.isEmpty()) { return CCountry(); }
static const QRegExp reg("^[a-z]+", Qt::CaseInsensitive);
int pos = reg.indexIn(countryName);
const QString cn(pos >= 0 ? reg.cap(0) : countryName);
thread_local const QRegularExpression reg("^[a-z]+", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = reg.match(countryName);
const QString cn(match.hasMatch() ? match.captured(0) : countryName);
CCountryList countries = this->findBy([&](const CCountry & country)
{
return country.matchesCountryName(cn);

View File

@@ -20,7 +20,6 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QRegExp>
#include <QTimeZone>
using namespace BlackMisc;

View File

@@ -8,6 +8,7 @@
*/
#include "distribution.h"
#include <QRegularExpression>
#include <QStringBuilder>
using namespace BlackConfig;
@@ -230,23 +231,25 @@ namespace BlackMisc
if (filename.isEmpty()) { return QVersionNumber(); }
// swift-installer-linux-64-0.7.3_2017-03-25_11-24-50.run
static const QRegExp firstSegments("\\d+\\.\\d+\\.\\d+");
if (firstSegments.indexIn(filename) < 0)
thread_local const QRegularExpression firstSegments("\\d+\\.\\d+\\.\\d+");
QRegularExpressionMatch firstSegmentsMatch = firstSegments.match(filename);
if (!firstSegmentsMatch.hasMatch())
{
return QVersionNumber(); // no version, invalid
}
QString v = firstSegments.cap(0); // first 3 segments, like 0.9.3
QString v = firstSegmentsMatch.captured(0); // first 3 segments, like 0.9.3
if (!v.endsWith('.')) { v += '.'; }
static const QRegExp ts1("\\d{4}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}");
if (ts1.indexIn(filename) < 0)
thread_local const QRegularExpression ts1("\\d{4}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}");
QRegularExpressionMatch ts1Match = ts1.match(filename);
if (!ts1Match.hasMatch())
{
// version without timestamp
v += "0";
return QVersionNumber::fromString(v);
}
const QString versionTimestampString = BlackMisc::digitOnlyString(ts1.cap(0));
const QString versionTimestampString = BlackMisc::digitOnlyString(ts1Match.captured(0));
const QDateTime versionTimestamp = QDateTime::fromString(versionTimestampString, "yyyyMMddHHmmss");
const QString lastSegment = QString::number(CBuildConfig::buildTimestampAsVersionSegment(versionTimestamp));

View File

@@ -12,7 +12,7 @@
#include "blackmisc/geo/latitude.h"
#include "blackmisc/geo/longitude.h"
#include <QRegExp>
#include <QRegularExpression>
#include <Qt>
#include <QtGlobal>
#include <QtMath>
@@ -72,7 +72,7 @@ namespace BlackMisc
{
// http://www.regular-expressions.info/floatingpoint.html
const QString wgs = wgsCoordinate.simplified().trimmed();
QRegExp rx("([-+]?[0-9]*\\.?[0-9]+)");
thread_local const QRegularExpression rx("([-+]?[0-9]*\\.?[0-9]+)");
qint32 deg = 0;
qint32 min = 0;
double sec = 0.0;
@@ -80,10 +80,11 @@ namespace BlackMisc
int fragmentLength = 0;
int c = 0;
int pos = 0;
while ((pos = rx.indexIn(wgs, pos)) != -1)
QRegularExpressionMatch match = rx.match(wgs, pos);
while (match.hasMatch())
{
QString cap = rx.cap(1);
pos += rx.matchedLength();
QString cap = match.captured(1);
pos += match.capturedLength(1);
switch (c++)
{
case 0:
@@ -102,6 +103,7 @@ namespace BlackMisc
default:
break;
}
match = rx.match(wgs, pos);
}
if (fragmentLength > 0)
{

View File

@@ -346,7 +346,7 @@ namespace BlackMisc
{
if (errorMessage.isEmpty()) { return errorMessage; }
QString phpError(errorMessage);
static const QRegularExpression regEx("<[^>]*>");
thread_local const QRegularExpression regEx("<[^>]*>");
return phpError.remove(regEx);
}

View File

@@ -14,7 +14,7 @@
#include "blackmisc/pq/constants.h"
#include "blackmisc/pq/physicalquantity.h"
#include <QRegExp>
#include <QRegularExpression>
#include <Qt>
#include <QtGlobal>
@@ -176,7 +176,7 @@ namespace BlackMisc
if (this->isEmpty()) return invalid;
if (this->isPrivateMessage()) return invalid;
if (this->m_message.length() > 15 || this->m_message.length() < 10) return invalid; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
QString candidate = this->m_message.toUpper().remove(QRegExp("[^A-Z]")); // SELCALABCD
QString candidate = this->m_message.toUpper().remove(QRegularExpression("[^A-Z]")); // SELCALABCD
if (candidate.length() != 10) return invalid;
if (!candidate.startsWith("SELCAL")) return invalid;
return candidate.right(4).toUpper();

View File

@@ -21,7 +21,7 @@
#include "blackmisc/pq/units.h"
#include <QLocale>
#include <QRegExp>
#include <QRegularExpression>
#include <QThreadStorage>
#include <QtDebug>
@@ -45,12 +45,10 @@ namespace BlackMisc
// check
if (vs.isEmpty()) { return v; }
static QThreadStorage<QRegExp> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegExp("([-+]?[0-9]*[\\.,]?[0-9]+)\\s*(\\D*)$")); }
const auto &regex = tsRegex.localData();
if (regex.indexIn(value) < 0) { return v; } // not a valid number
QString unit = regex.cap(2).trimmed();
thread_local const QRegularExpression regex("([-+]?[0-9]*[\\.,]?[0-9]+)\\s*(\\D*)$");
auto match = regex.match(value);
if (!match.hasMatch()) { return v; } // not a valid number
QString unit = match.captured(2).trimmed();
QString number = QString(value).replace(unit, "");
unit = unit.trimmed(); // trim after replace, not before