mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QRegExp>
|
||||
#include <QTimeZone>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 ®ex = 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user