diff --git a/src/blackcore/vatsim/networkvatlib.cpp b/src/blackcore/vatsim/networkvatlib.cpp index 83d80bf70..72c04a239 100644 --- a/src/blackcore/vatsim/networkvatlib.cpp +++ b/src/blackcore/vatsim/networkvatlib.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include #include @@ -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"; } diff --git a/src/blackcore/vatsim/vatsimdatafilereader.cpp b/src/blackcore/vatsim/vatsimdatafilereader.cpp index e5e13b606..0f5180de0 100644 --- a/src/blackcore/vatsim/vatsimdatafilereader.cpp +++ b/src/blackcore/vatsim/vatsimdatafilereader.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -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)) { diff --git a/src/blackcore/vatsim/vatsimstatusfilereader.cpp b/src/blackcore/vatsim/vatsimstatusfilereader.cpp index db18273cc..a6e154547 100644 --- a/src/blackcore/vatsim/vatsimstatusfilereader.cpp +++ b/src/blackcore/vatsim/vatsimstatusfilereader.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index de68c03ab..46a37bae5 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -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); diff --git a/src/blackgui/components/settingssimulatorbasicscomponent.cpp b/src/blackgui/components/settingssimulatorbasicscomponent.cpp index 7d2c3bce8..a15ccd24f 100644 --- a/src/blackgui/components/settingssimulatorbasicscomponent.cpp +++ b/src/blackgui/components/settingssimulatorbasicscomponent.cpp @@ -13,6 +13,8 @@ #include "blackmisc/logmessage.h" #include "blackconfig/buildconfig.h" +#include + 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); diff --git a/src/blackgui/components/weathercomponent.cpp b/src/blackgui/components/weathercomponent.cpp index d0231c766..2534383c7 100644 --- a/src/blackgui/components/weathercomponent.cpp +++ b/src/blackgui/components/weathercomponent.cpp @@ -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() diff --git a/src/blackgui/guiapplication.cpp b/src/blackgui/guiapplication.cpp index cdfb518ec..d50d505d2 100644 --- a/src/blackgui/guiapplication.cpp +++ b/src/blackgui/guiapplication.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include @@ -244,7 +244,7 @@ namespace BlackGui html += "\n"; } html += ""; - static const QRegExp reg("[ ]{2,}"); + thread_local const QRegularExpression reg("[ ]{2,}"); html += lt.replace(reg, ""); pendingTr = true; } diff --git a/src/blackgui/stylesheetutility.cpp b/src/blackgui/stylesheetutility.cpp index 62219f3cd..e2dad59b2 100644 --- a/src/blackgui/stylesheetutility.cpp +++ b/src/blackgui/stylesheetutility.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -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; } diff --git a/src/blackmisc/aviation/callsign.cpp b/src/blackmisc/aviation/callsign.cpp index 932944abf..563c34c91 100644 --- a/src/blackmisc/aviation/callsign.cpp +++ b/src/blackmisc/aviation/callsign.cpp @@ -10,7 +10,6 @@ #include "blackmisc/aviation/callsign.h" #include "blackmisc/compare.h" -#include #include #include #include @@ -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 diff --git a/src/blackmisc/aviation/transponder.cpp b/src/blackmisc/aviation/transponder.cpp index 8857d7a40..f7d2e5bac 100644 --- a/src/blackmisc/aviation/transponder.cpp +++ b/src/blackmisc/aviation/transponder.cpp @@ -11,7 +11,7 @@ #include "blackmisc/propertyindex.h" #include "blackmisc/variant.h" -#include +#include #include #include @@ -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) diff --git a/src/blackmisc/countrylist.cpp b/src/blackmisc/countrylist.cpp index 0363eb625..a36fe4263 100644 --- a/src/blackmisc/countrylist.cpp +++ b/src/blackmisc/countrylist.cpp @@ -12,6 +12,7 @@ #include #include +#include #include 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); diff --git a/src/blackmisc/db/datastoreutility.cpp b/src/blackmisc/db/datastoreutility.cpp index 1713d071d..35611912a 100644 --- a/src/blackmisc/db/datastoreutility.cpp +++ b/src/blackmisc/db/datastoreutility.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include using namespace BlackMisc; diff --git a/src/blackmisc/db/distribution.cpp b/src/blackmisc/db/distribution.cpp index bc20b48d7..0565973f4 100644 --- a/src/blackmisc/db/distribution.cpp +++ b/src/blackmisc/db/distribution.cpp @@ -8,6 +8,7 @@ */ #include "distribution.h" +#include #include 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)); diff --git a/src/blackmisc/geo/earthangle.cpp b/src/blackmisc/geo/earthangle.cpp index aa80e6a5a..b624eb642 100644 --- a/src/blackmisc/geo/earthangle.cpp +++ b/src/blackmisc/geo/earthangle.cpp @@ -12,7 +12,7 @@ #include "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" -#include +#include #include #include #include @@ -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) { diff --git a/src/blackmisc/network/networkutils.cpp b/src/blackmisc/network/networkutils.cpp index 0ed306c28..62953a148 100644 --- a/src/blackmisc/network/networkutils.cpp +++ b/src/blackmisc/network/networkutils.cpp @@ -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); } diff --git a/src/blackmisc/network/textmessage.cpp b/src/blackmisc/network/textmessage.cpp index 328d5557a..701bf9112 100644 --- a/src/blackmisc/network/textmessage.cpp +++ b/src/blackmisc/network/textmessage.cpp @@ -14,7 +14,7 @@ #include "blackmisc/pq/constants.h" #include "blackmisc/pq/physicalquantity.h" -#include +#include #include #include @@ -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(); diff --git a/src/blackmisc/pq/pqstring.cpp b/src/blackmisc/pq/pqstring.cpp index 97959a5db..86fce5647 100644 --- a/src/blackmisc/pq/pqstring.cpp +++ b/src/blackmisc/pq/pqstring.cpp @@ -21,7 +21,7 @@ #include "blackmisc/pq/units.h" #include -#include +#include #include #include @@ -45,12 +45,10 @@ namespace BlackMisc // check if (vs.isEmpty()) { return v; } - static QThreadStorage 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