mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
refactor: Fix clang-tidy warnings
This commit is contained in:
15
.clang-tidy
15
.clang-tidy
@@ -7,11 +7,26 @@ Checks:
|
||||
- '-modernize-use-trailing-return-type'
|
||||
- '-modernize-use-nodiscard'
|
||||
- '-modernize-pass-by-value'
|
||||
- '-modernize-avoid-c-arrays'
|
||||
- 'bugprone-*'
|
||||
- '-bugprone-easily-swappable-parameters'
|
||||
- 'readability-*'
|
||||
- '-readability-identifier-length'
|
||||
- '-readability-implicit-bool-conversion'
|
||||
- '-readability-braces-around-statements'
|
||||
- '-readability-function-cognitive-complexity'
|
||||
- '-readability-convert-member-functions-to-static'
|
||||
- '-readability-math-missing-parentheses'
|
||||
- '-readability-avoid-unconditional-preprocessor-if'
|
||||
- '-readability-magic-numbers'
|
||||
- 'cppcoreguidelines-*'
|
||||
- '-cppcoreguidelines-avoid-magic-numbers'
|
||||
- '-cppcoreguidelines-non-private-member-variables-in-classes'
|
||||
- '-cppcoreguidelines-avoid-c-arrays'
|
||||
- '-cppcoreguidelines-owning-memory'
|
||||
- '-cppcoreguidelines-misleading-capture-default-by-value'
|
||||
- '-cppcoreguidelines-pro-bounds-array-to-pointer-decay'
|
||||
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.ClassCase
|
||||
|
||||
@@ -56,7 +56,8 @@ namespace swift::sample
|
||||
int CSamplesPerformance::samplesMisc(QTextStream &out)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
int ms, number;
|
||||
qint64 ms {};
|
||||
int number {};
|
||||
CSamplesPerformance::copy10kStations(1); // init
|
||||
|
||||
// ATC stations, tradionally created
|
||||
@@ -148,7 +149,10 @@ namespace swift::sample
|
||||
|
||||
// Regex pattern matching with lists of 10000 strings containing random hex numbers
|
||||
auto generator = []() { return QString::number(CMathUtils::randomGenerator().generate(), 16); };
|
||||
QStringList strList1, strList2, strList3, strList4;
|
||||
QStringList strList1;
|
||||
QStringList strList2;
|
||||
QStringList strList3;
|
||||
QStringList strList4;
|
||||
std::generate_n(std::back_inserter(strList1), 100000, generator);
|
||||
std::generate_n(std::back_inserter(strList2), 100000, generator);
|
||||
std::generate_n(std::back_inserter(strList3), 100000, generator);
|
||||
@@ -305,7 +309,7 @@ namespace swift::sample
|
||||
CDatabaseReader::stringToDatastoreResponse(liveryData, response);
|
||||
timer.start();
|
||||
const CLiveryList dbLiveries = CLiveryList::fromDatabaseJson(response);
|
||||
int ms = timer.elapsed();
|
||||
qint64 ms = timer.elapsed();
|
||||
out << "Read via DB JSON format: " << dbLiveries.size() << " liveries in " << ms << "ms" << Qt::endl;
|
||||
|
||||
// does not result in better performance, liveries/airlines have almost a 1:1 ratio
|
||||
@@ -356,7 +360,7 @@ namespace swift::sample
|
||||
std::generate_n(std::back_inserter(strings), 100000, [] {
|
||||
QString s;
|
||||
std::generate_n(std::back_inserter(s), 10,
|
||||
[] { return chars[CMathUtils::randomInteger(0, chars.size() - 1)]; });
|
||||
[] { return chars[CMathUtils::randomInteger(0, static_cast<int>(chars.size() - 1))]; });
|
||||
return s;
|
||||
});
|
||||
QString bigString = strings.join("\n");
|
||||
@@ -720,10 +724,10 @@ namespace swift::sample
|
||||
CCoordinateGeodetic(30.0, 30.0, 30.0), CCoordinateGeodetic(40.0, 40.0, 40.0),
|
||||
CCoordinateGeodetic(50.0, 50.0, 50.0), CCoordinateGeodetic(60.0, 60.0, 60.0),
|
||||
CCoordinateGeodetic(70.0, 70.0, 70.0) });
|
||||
const int s = pos.size();
|
||||
const qsizetype s = pos.size();
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int p = i % s;
|
||||
const qsizetype p = i % s;
|
||||
atc.calculcateAndUpdateRelativeDistance(pos.at(p));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,19 +592,21 @@ namespace swift::core
|
||||
if (log)
|
||||
{
|
||||
static const QString nms = "no model string";
|
||||
CMatchingUtils::addLogDetailsToList(
|
||||
log, remoteAircraft,
|
||||
summary
|
||||
.arg(remoteAircraft.getAircraftIcaoCode().getCombinedType(),
|
||||
matchedModel.getAircraftIcaoCode().getCombinedType(),
|
||||
remoteAircraft.getAircraftIcaoCode().getDesignatorDbKey(),
|
||||
matchedModel.getAircraftIcaoCode().getDesignatorDbKey(),
|
||||
remoteAircraft.getAirlineIcaoCode().getVDesignatorDbKey(),
|
||||
matchedModel.getAirlineIcaoCode().getVDesignatorDbKey())
|
||||
.arg(remoteAircraft.getLivery().getCombinedCodePlusInfoAndId(),
|
||||
matchedModel.getLivery().getCombinedCodePlusInfoAndId(),
|
||||
defaultIfEmpty(remoteAircraft.getModel().getModelStringAndDbKey(), nms),
|
||||
matchedModel.getModelStringAndDbKey(), boolToYesNo(didRunAndModifyMatchingScript)));
|
||||
const QString modelString = remoteAircraft.getModel().getModelStringAndDbKey().isEmpty() ?
|
||||
nms :
|
||||
remoteAircraft.getModel().getModelStringAndDbKey();
|
||||
CMatchingUtils::addLogDetailsToList(log, remoteAircraft,
|
||||
summary
|
||||
.arg(remoteAircraft.getAircraftIcaoCode().getCombinedType(),
|
||||
matchedModel.getAircraftIcaoCode().getCombinedType(),
|
||||
remoteAircraft.getAircraftIcaoCode().getDesignatorDbKey(),
|
||||
matchedModel.getAircraftIcaoCode().getDesignatorDbKey(),
|
||||
remoteAircraft.getAirlineIcaoCode().getVDesignatorDbKey(),
|
||||
matchedModel.getAirlineIcaoCode().getVDesignatorDbKey())
|
||||
.arg(remoteAircraft.getLivery().getCombinedCodePlusInfoAndId(),
|
||||
matchedModel.getLivery().getCombinedCodePlusInfoAndId(),
|
||||
modelString, matchedModel.getModelStringAndDbKey(),
|
||||
boolToYesNo(didRunAndModifyMatchingScript)));
|
||||
} // log
|
||||
|
||||
const QDateTime endTime = QDateTime::currentDateTimeUtc();
|
||||
@@ -1728,18 +1730,11 @@ namespace swift::core
|
||||
}
|
||||
|
||||
CMatchingStatisticsEntry::EntryType type = CMatchingStatisticsEntry::Missing;
|
||||
if (airlineIcaoChecked.hasValidDesignator())
|
||||
{
|
||||
type = m_modelSet.containsModelsWithAircraftAndAirlineIcaoDesignator(aircraftIcao, airlineIcao) ?
|
||||
CMatchingStatisticsEntry::Found :
|
||||
CMatchingStatisticsEntry::Missing;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = m_modelSet.containsModelsWithAircraftAndAirlineIcaoDesignator(aircraftIcao, airlineIcao) ?
|
||||
CMatchingStatisticsEntry::Found :
|
||||
CMatchingStatisticsEntry::Missing;
|
||||
}
|
||||
|
||||
type = m_modelSet.containsModelsWithAircraftAndAirlineIcaoDesignator(aircraftIcao, airlineIcao) ?
|
||||
CMatchingStatisticsEntry::Found :
|
||||
CMatchingStatisticsEntry::Missing;
|
||||
|
||||
m_statistics.addAircraftAirlineCombination(type, sessionId, m_modelSetInfo, description, aircraftIcao,
|
||||
airlineIcao);
|
||||
}
|
||||
|
||||
@@ -85,11 +85,14 @@ namespace swift::core::fsd
|
||||
return cats;
|
||||
}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
|
||||
CFSDClient::CFSDClient(IClientProvider *clientProvider, IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider, QObject *owner)
|
||||
: CContinuousWorker(owner, "FSDClient"), CClientAware(clientProvider), COwnAircraftAware(ownAircraftProvider),
|
||||
CRemoteAircraftAware(remoteAircraftProvider), m_tokenBucket(10, 5000, 1)
|
||||
{
|
||||
// NOLINTEND(cppcoreguidelines-pro-type-member-init)
|
||||
|
||||
initializeMessageTypes();
|
||||
connectSocketSignals();
|
||||
|
||||
@@ -793,7 +796,7 @@ namespace swift::core::fsd
|
||||
void CFSDClient::sendQueuedMessage()
|
||||
{
|
||||
if (m_queuedFsdMessages.isEmpty()) { return; }
|
||||
const int s = m_queuedFsdMessages.size();
|
||||
const qsizetype s = m_queuedFsdMessages.size(); // NOLINT(cppcoreguidelines-init-variables)
|
||||
this->sendMessageString(m_queuedFsdMessages.dequeue());
|
||||
|
||||
// send up to 6 at once
|
||||
@@ -832,7 +835,7 @@ namespace swift::core::fsd
|
||||
|
||||
QString CFSDClient::getConfiguredLiveryString(const CSimulatedAircraft &myAircraft) const
|
||||
{
|
||||
if (!m_sendLiveryString) { return QString(); }
|
||||
if (!m_sendLiveryString) { return {}; }
|
||||
QReadLocker l(&m_lockUserClientBuffered);
|
||||
const QString livery = m_ownLivery.isEmpty() ? myAircraft.getModel().getSwiftLiveryString() : m_ownLivery;
|
||||
return livery;
|
||||
@@ -1329,7 +1332,7 @@ namespace swift::core::fsd
|
||||
const Pong pong = Pong::fromTokens(tokens);
|
||||
const qint64 msecSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
const qint64 elapsedTime = msecSinceEpoch - pong.m_timestamp.toLongLong();
|
||||
emit pongReceived(pong.sender(), elapsedTime);
|
||||
emit pongReceived(pong.sender(), static_cast<double>(elapsedTime));
|
||||
}
|
||||
|
||||
void CFSDClient::handleKillRequest(const QStringList &tokens)
|
||||
@@ -1390,7 +1393,7 @@ namespace swift::core::fsd
|
||||
void CFSDClient::handleClientQuery(const QStringList &tokens)
|
||||
{
|
||||
const ClientQuery clientQuery = ClientQuery::fromTokens(tokens);
|
||||
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if (clientQuery.m_queryType == ClientQueryType::Unknown) { return; }
|
||||
if (clientQuery.m_queryType == ClientQueryType::IsValidATC)
|
||||
{
|
||||
@@ -1468,6 +1471,7 @@ namespace swift::core::fsd
|
||||
const qint64 offsetTimeMs = currentOffsetTime(callsign);
|
||||
emit aircraftConfigReceived(clientQuery.sender(), config, offsetTimeMs);
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
void CFSDClient::handleClientResponse(const QStringList &tokens)
|
||||
@@ -1478,7 +1482,8 @@ namespace swift::core::fsd
|
||||
|
||||
QString responseData1;
|
||||
QString responseData2;
|
||||
if (clientResponse.m_responseData.size() > 0) { responseData1 = clientResponse.m_responseData.at(0); }
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if (!clientResponse.m_responseData.empty()) { responseData1 = clientResponse.m_responseData.at(0); }
|
||||
|
||||
if (clientResponse.m_responseData.size() > 1) { responseData2 = clientResponse.m_responseData.at(1); }
|
||||
|
||||
@@ -1489,9 +1494,8 @@ namespace swift::core::fsd
|
||||
else if (clientResponse.m_queryType == ClientQueryType::Capabilities)
|
||||
{
|
||||
Capabilities capabilities = Capabilities::None;
|
||||
for (int i = 0; i < clientResponse.m_responseData.size(); ++i)
|
||||
for (auto keyValuePair : clientResponse.m_responseData)
|
||||
{
|
||||
const QString keyValuePair = clientResponse.m_responseData.at(i);
|
||||
if (keyValuePair.count('=') != 1) { continue; }
|
||||
|
||||
const QStringList split = keyValuePair.split('=');
|
||||
@@ -1514,7 +1518,7 @@ namespace swift::core::fsd
|
||||
else if (clientResponse.m_queryType == ClientQueryType::Com1Freq)
|
||||
{
|
||||
if (responseData1.isEmpty()) { return; }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
const double freqMHz = responseData1.toDouble(&ok);
|
||||
if (!ok) { return; }
|
||||
emit com1FrequencyResponseReceived(clientResponse.sender(), CFrequency(freqMHz, CFrequencyUnit::MHz()));
|
||||
@@ -1553,6 +1557,7 @@ namespace swift::core::fsd
|
||||
{
|
||||
// Currently not existing.
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
void CFSDClient::handleServerError(const QStringList &tokens)
|
||||
@@ -1675,8 +1680,11 @@ namespace swift::core::fsd
|
||||
{
|
||||
const CServer server = this->getServer();
|
||||
const auto socket = rehostingSocket ? rehostingSocket : m_socket;
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-init-variables)
|
||||
const QString host = rehostingSocket ? rehostingHost : server.getAddress();
|
||||
const quint16 port = rehostingSocket ? m_socket->peerPort() : static_cast<quint16>(getServer().getPort());
|
||||
// NOLINTEND(cppcoreguidelines-init-variables)
|
||||
|
||||
resolveLoadBalancing(host, [=](const QString &host) {
|
||||
socket->connectToHost(host, port);
|
||||
@@ -1925,7 +1933,7 @@ namespace swift::core::fsd
|
||||
m_lastPositionUpdate.insert(callsign, markerTs);
|
||||
return CFsdSetup::c_positionTimeOffsetMsec;
|
||||
}
|
||||
const qint64 oldTs = m_lastPositionUpdate.value(callsign);
|
||||
const qint64 oldTs = m_lastPositionUpdate.value(callsign); // NOLINT(cppcoreguidelines-init-variables)
|
||||
m_lastPositionUpdate[callsign] = markerTs;
|
||||
|
||||
// Ref T297, dynamic offsets
|
||||
@@ -2002,12 +2010,6 @@ namespace swift::core::fsd
|
||||
return qRound(static_cast<double>(sum) / count);
|
||||
}
|
||||
|
||||
qint64 CFSDClient::averageOffsetTimeMs(const CCallsign &callsign, int maxLastValues) const
|
||||
{
|
||||
int count = 0;
|
||||
return this->averageOffsetTimeMs(callsign, maxLastValues, count);
|
||||
}
|
||||
|
||||
bool CFSDClient::isInterimPositionSendingEnabledForServer() const
|
||||
{
|
||||
const CFsdSetup::SendReceiveDetails d = this->getSetupForServer().getSendReceiveDetails();
|
||||
@@ -2149,7 +2151,7 @@ namespace swift::core::fsd
|
||||
callByTime = m_callByTime;
|
||||
}
|
||||
|
||||
if (callStatistics.isEmpty()) { return QString(); }
|
||||
if (callStatistics.isEmpty()) { return {}; }
|
||||
for (const auto [key, value] : makePairsRange(std::as_const(callStatistics)))
|
||||
{
|
||||
// key is pair.first, value is pair.second
|
||||
@@ -2328,7 +2330,7 @@ namespace swift::core::fsd
|
||||
{
|
||||
if (fsdMessageFiltered.startsWith("#AP"))
|
||||
{
|
||||
thread_local const QRegularExpression re("^(#AP\\w+:SERVER:\\d+:)[^:]+(:\\d+:\\d+:\\d+:.+)$");
|
||||
thread_local const QRegularExpression re(R"(^(#AP\w+:SERVER:\d+:)[^:]+(:\d+:\d+:\d+:.+)$)");
|
||||
fsdMessageFiltered.replace(re, "\\1<password>\\2");
|
||||
m_filterPasswordFromLogin = false;
|
||||
}
|
||||
@@ -2365,6 +2367,7 @@ namespace swift::core::fsd
|
||||
m_queuedFsdMessages.clear(); // clear everything before the timer is started
|
||||
|
||||
// interim positions
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if (this->isInterimPositionSendingEnabledForServer())
|
||||
{
|
||||
m_interimPositionUpdateTimer.start(c_updateInterimPositionIntervalMsec);
|
||||
@@ -2375,6 +2378,7 @@ namespace swift::core::fsd
|
||||
m_visualPositionUpdateTimer.start(c_updateVisualPositionIntervalMsec);
|
||||
}
|
||||
else { m_visualPositionUpdateTimer.stop(); }
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
void CFSDClient::stopPositionTimers()
|
||||
@@ -2388,60 +2392,58 @@ namespace swift::core::fsd
|
||||
|
||||
void CFSDClient::updateAtisMap(const QString &callsign, AtisLineType type, const QString &line)
|
||||
{
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if (type == AtisLineType::VoiceRoom)
|
||||
{
|
||||
m_mapAtisMessages[callsign].voiceRoom = line;
|
||||
m_mapAtisMessages[callsign].lineCount++;
|
||||
m_mapAtisMessages[callsign].m_voiceRoom = line;
|
||||
m_mapAtisMessages[callsign].m_lineCount++;
|
||||
return;
|
||||
}
|
||||
else if (type == AtisLineType::TextMessage)
|
||||
if (type == AtisLineType::TextMessage)
|
||||
{
|
||||
m_mapAtisMessages[callsign].textLines.push_back(line);
|
||||
m_mapAtisMessages[callsign].lineCount++;
|
||||
m_mapAtisMessages[callsign].m_textLines.push_back(line);
|
||||
m_mapAtisMessages[callsign].m_lineCount++;
|
||||
return;
|
||||
}
|
||||
else if (type == AtisLineType::ZuluLogoff)
|
||||
if (type == AtisLineType::ZuluLogoff)
|
||||
{
|
||||
m_mapAtisMessages[callsign].zuluLogoff = line;
|
||||
m_mapAtisMessages[callsign].lineCount++;
|
||||
m_mapAtisMessages[callsign].m_zuluLogoff = line;
|
||||
m_mapAtisMessages[callsign].m_lineCount++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
if (!m_mapAtisMessages.contains(callsign)) { return; }
|
||||
|
||||
// Ignore the check for line count.
|
||||
m_mapAtisMessages[callsign].m_lineCount++;
|
||||
|
||||
const CCallsign cs(callsign, CCallsign::Atc);
|
||||
// emit atisVoiceRoomReplyReceived(cs, m_mapAtisMessages[callsign].voiceRoom);
|
||||
emit atisLogoffTimeReplyReceived(cs, m_mapAtisMessages[callsign].m_zuluLogoff);
|
||||
|
||||
CInformationMessage atisMessage(CInformationMessage::ATIS);
|
||||
for (const QString &tm : std::as_const(m_mapAtisMessages[callsign].m_textLines))
|
||||
{
|
||||
if (!m_mapAtisMessages.contains(callsign)) { return; }
|
||||
|
||||
// Ignore the check for line count.
|
||||
m_mapAtisMessages[callsign].lineCount++;
|
||||
|
||||
const CCallsign cs(callsign, CCallsign::Atc);
|
||||
// emit atisVoiceRoomReplyReceived(cs, m_mapAtisMessages[callsign].voiceRoom);
|
||||
emit atisLogoffTimeReplyReceived(cs, m_mapAtisMessages[callsign].zuluLogoff);
|
||||
|
||||
CInformationMessage atisMessage(CInformationMessage::ATIS);
|
||||
for (const QString &tm : std::as_const(m_mapAtisMessages[callsign].textLines))
|
||||
const QString fixed = tm.trimmed();
|
||||
if (!fixed.isEmpty())
|
||||
{
|
||||
const QString fixed = tm.trimmed();
|
||||
if (!fixed.isEmpty())
|
||||
{
|
||||
// detect the stupid z1, z2, z3 placeholders
|
||||
//! \fixme: Anything better as this stupid code here?
|
||||
thread_local const QRegularExpression RegExp("[\\n\\t\\r]");
|
||||
const QString test = fixed.toLower().remove(RegExp);
|
||||
if (test == "z") return;
|
||||
if (test.startsWith("z") && test.length() == 2) return; // z1, z2, ..
|
||||
if (test.length() == 1) return; // sometimes just z
|
||||
// detect the stupid z1, z2, z3 placeholders
|
||||
//! \fixme: Anything better as this stupid code here?
|
||||
thread_local const QRegularExpression RegExp(R"([\n\t\r])");
|
||||
const QString test = fixed.toLower().remove(RegExp);
|
||||
if (test == "z") return;
|
||||
if (test.startsWith("z") && test.length() == 2) return; // z1, z2, ..
|
||||
if (test.length() == 1) return; // sometimes just z
|
||||
|
||||
// append
|
||||
if (!atisMessage.isEmpty()) atisMessage.appendMessage("\n");
|
||||
atisMessage.appendMessage(fixed);
|
||||
}
|
||||
// append
|
||||
if (!atisMessage.isEmpty()) atisMessage.appendMessage("\n");
|
||||
atisMessage.appendMessage(fixed);
|
||||
}
|
||||
|
||||
emit this->atisReplyReceived(cs, atisMessage);
|
||||
|
||||
m_mapAtisMessages.remove(callsign);
|
||||
return;
|
||||
}
|
||||
|
||||
emit this->atisReplyReceived(cs, atisMessage);
|
||||
|
||||
m_mapAtisMessages.remove(callsign);
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
void CFSDClient::pendingTimeoutCheck()
|
||||
@@ -2456,7 +2458,7 @@ namespace swift::core::fsd
|
||||
this->disconnectFromServer();
|
||||
}
|
||||
|
||||
const CLength &CFSDClient::fixAtcRange(const CLength &networkRange, const CCallsign &cs)
|
||||
CLength CFSDClient::fixAtcRange(const CLength &networkRange, const CCallsign &cs)
|
||||
{
|
||||
/** T702, https://discordapp.com/channels/539048679160676382/539846348275449887/597814208125730826
|
||||
DEL 5 NM
|
||||
@@ -2508,7 +2510,7 @@ namespace swift::core::fsd
|
||||
return networkRange;
|
||||
}
|
||||
|
||||
const CLength &CFSDClient::maxOrNotNull(const CLength &l1, const CLength &l2)
|
||||
CLength CFSDClient::maxOrNotNull(const CLength &l1, const CLength &l2)
|
||||
{
|
||||
if (l1.isNull()) { return l2; }
|
||||
if (l2.isNull()) { return l1; }
|
||||
|
||||
@@ -47,10 +47,10 @@
|
||||
|
||||
//! @{
|
||||
//! Protocol version
|
||||
#define PROTOCOL_REVISION_CLASSIC 9
|
||||
#define PROTOCOL_REVISION_VATSIM_ATC 10
|
||||
#define PROTOCOL_REVISION_VATSIM_AUTH 100
|
||||
#define PROTOCOL_REVISION_VATSIM_VELOCITY 101
|
||||
constexpr int PROTOCOL_REVISION_CLASSIC = 9;
|
||||
constexpr int PROTOCOL_REVISION_VATSIM_ATC = 10;
|
||||
constexpr int PROTOCOL_REVISION_VATSIM_AUTH = 100;
|
||||
constexpr int PROTOCOL_REVISION_VATSIM_VELOCITY = 101;
|
||||
//! @}
|
||||
|
||||
class QNetworkReply;
|
||||
@@ -516,10 +516,6 @@ namespace swift::core::fsd
|
||||
qint64 averageOffsetTimeMs(const swift::misc::aviation::CCallsign &callsign, int &count,
|
||||
int maxLastValues = c_maxOffsetTimes) const;
|
||||
|
||||
//! Average offset time in ms
|
||||
qint64 averageOffsetTimeMs(const swift::misc::aviation::CCallsign &callsign,
|
||||
int maxLastValues = c_maxOffsetTimes) const;
|
||||
|
||||
bool isInterimPositionSendingEnabledForServer() const;
|
||||
bool isInterimPositionReceivingEnabledForServer() const;
|
||||
bool isVisualPositionSendingEnabledForServer() const;
|
||||
@@ -552,12 +548,12 @@ namespace swift::core::fsd
|
||||
void pendingTimeoutCheck();
|
||||
|
||||
//! Fix ATC station range
|
||||
static const swift::misc::physical_quantities::CLength &
|
||||
static swift::misc::physical_quantities::CLength
|
||||
fixAtcRange(const swift::misc::physical_quantities::CLength &networkRange,
|
||||
const swift::misc::aviation::CCallsign &cs);
|
||||
|
||||
//! Max or 1st non-null value
|
||||
static const swift::misc::physical_quantities::CLength &
|
||||
static swift::misc::physical_quantities::CLength
|
||||
maxOrNotNull(const swift::misc::physical_quantities::CLength &l1,
|
||||
const swift::misc::physical_quantities::CLength &l2);
|
||||
|
||||
@@ -605,10 +601,10 @@ namespace swift::core::fsd
|
||||
//! ATIS message
|
||||
struct AtisMessage
|
||||
{
|
||||
QString voiceRoom;
|
||||
QStringList textLines;
|
||||
QString zuluLogoff;
|
||||
int lineCount = 0;
|
||||
QString m_voiceRoom;
|
||||
QStringList m_textLines;
|
||||
QString m_zuluLogoff;
|
||||
int m_lineCount = 0;
|
||||
};
|
||||
|
||||
QMap<QString, AtisMessage> m_mapAtisMessages;
|
||||
|
||||
@@ -180,7 +180,6 @@ namespace swift::core::fsd
|
||||
case SimType::P3Dv3: return "30";
|
||||
case SimType::P3Dv4: return "30";
|
||||
|
||||
// future versions
|
||||
// future versions
|
||||
case SimType::XPLANE12:
|
||||
case SimType::P3Dv5: return "0";
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace swift::gui::editors
|
||||
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CFsdSetupForm::resetToDefaultValues);
|
||||
}
|
||||
|
||||
CFsdSetupForm::~CFsdSetupForm() {}
|
||||
CFsdSetupForm::~CFsdSetupForm() = default;
|
||||
|
||||
CFsdSetup CFsdSetupForm::getValue() const
|
||||
{
|
||||
|
||||
@@ -536,10 +536,8 @@ namespace swift::gui
|
||||
QLayoutItem *item { nullptr };
|
||||
while ((item = layout->takeAt(0)))
|
||||
{
|
||||
QLayout *sublayout { nullptr };
|
||||
QWidget *widget { nullptr };
|
||||
if ((sublayout = item->layout())) { deleteLayout(sublayout, deleteWidgets); }
|
||||
else if ((widget = item->widget()))
|
||||
if (QLayout *sublayout = item->layout(); sublayout) { deleteLayout(sublayout, deleteWidgets); }
|
||||
else if (QWidget *widget = item->widget(); widget)
|
||||
{
|
||||
widget->hide();
|
||||
if (deleteWidgets) { delete widget; }
|
||||
|
||||
@@ -369,7 +369,7 @@ namespace swift::misc
|
||||
m_originalTimestamps.clear();
|
||||
|
||||
QFile revisionFile(CFileUtils::appendFilePaths(m_basename, ".rev"));
|
||||
if ((m_found = revisionFile.exists()))
|
||||
if (m_found = revisionFile.exists(); m_found)
|
||||
{
|
||||
if (!revisionFile.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
|
||||
@@ -18,10 +18,10 @@ SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::network, CFsdSetup)
|
||||
|
||||
namespace swift::misc::network
|
||||
{
|
||||
CFsdSetup::CFsdSetup(SendReceiveDetails sendReceive) : m_sendReceive(sendReceive) {}
|
||||
CFsdSetup::CFsdSetup(SendReceiveDetails sendReceive) : m_sendReceive(static_cast<int>(sendReceive)) {}
|
||||
|
||||
CFsdSetup::CFsdSetup(const QString &codec, SendReceiveDetails sendReceive)
|
||||
: m_textCodec(codec), m_sendReceive(sendReceive)
|
||||
: m_textCodec(codec), m_sendReceive(static_cast<int>(sendReceive))
|
||||
{}
|
||||
|
||||
CFsdSetup::SendReceiveDetails CFsdSetup::getSendReceiveDetails() const
|
||||
@@ -98,7 +98,7 @@ namespace swift::misc::network
|
||||
QVariant CFsdSetup::propertyByIndex(swift::misc::CPropertyIndexRef index) const
|
||||
{
|
||||
if (index.isMyself()) { return QVariant::fromValue(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const auto i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTextCodec: return QVariant::fromValue(m_textCodec);
|
||||
@@ -114,7 +114,7 @@ namespace swift::misc::network
|
||||
(*this) = variant.value<CFsdSetup>();
|
||||
return;
|
||||
}
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const auto i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTextCodec: this->setTextCodec(variant.value<QString>()); break;
|
||||
@@ -126,7 +126,7 @@ namespace swift::misc::network
|
||||
int CFsdSetup::comparePropertyByIndex(CPropertyIndexRef index, const CFsdSetup &compareValue) const
|
||||
{
|
||||
if (index.isMyself()) { return this->convertToQString(true).compare(compareValue.convertToQString()); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const auto i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTextCodec: return this->getTextCodec().compare(compareValue.getTextCodec());
|
||||
|
||||
@@ -1404,7 +1404,7 @@ namespace swift::misc::simulation
|
||||
|
||||
if (!model.hasFileName())
|
||||
{
|
||||
if (ignoreEmptyFileNames) { continue; }
|
||||
if (ignoreEmptyFileNames) { break; }
|
||||
msgs.push_back(CStatusMessage(this).validationError(u"'%1', no file name")
|
||||
<< model.getModelStringAndDbKey());
|
||||
break;
|
||||
|
||||
@@ -618,10 +618,7 @@ namespace swift::misc::simulation::fscommon
|
||||
const QString pathUp = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Lockheed Martin");
|
||||
const QDir d(pathUp);
|
||||
if (!d.exists()) { continue; }
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config dir: '%1'") << d.absolutePath();
|
||||
}
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config dir: '%1'") << d.absolutePath();
|
||||
|
||||
// all versions sub directories
|
||||
// looking for "add-ons.cfg" or simobjects.cfg
|
||||
@@ -636,10 +633,7 @@ namespace swift::misc::simulation::fscommon
|
||||
if (fi.exists())
|
||||
{
|
||||
files.insert(f);
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config file: '%1'") << f;
|
||||
}
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config file: '%1'") << f;
|
||||
}
|
||||
} // contains
|
||||
} // entries
|
||||
@@ -650,7 +644,7 @@ namespace swift::misc::simulation::fscommon
|
||||
QSet<QString> CFsDirectories::allConfigFilesPathValues(const QStringList &configFiles, bool checked,
|
||||
const QString &pathPrefix)
|
||||
{
|
||||
if (configFiles.isEmpty()) { return QSet<QString>(); }
|
||||
if (configFiles.isEmpty()) { return {}; }
|
||||
QSet<QString> paths;
|
||||
for (const QString &configFile : configFiles)
|
||||
{
|
||||
@@ -661,7 +655,7 @@ namespace swift::misc::simulation::fscommon
|
||||
static const QString p("Path=");
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
const qsizetype i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i < 0 || line.endsWith('=')) { continue; }
|
||||
const QStringView path = line.mid(i + p.length());
|
||||
const QDir dir(QDir::fromNativeSeparators(
|
||||
@@ -675,7 +669,7 @@ namespace swift::misc::simulation::fscommon
|
||||
|
||||
QSet<QString> CFsDirectories::allP3dAddOnXmlSimObjectPaths(const QStringList &addOnPaths, bool checked)
|
||||
{
|
||||
if (addOnPaths.isEmpty()) { return QSet<QString>(); }
|
||||
if (addOnPaths.isEmpty()) { return {}; }
|
||||
QSet<QString> simObjectPaths;
|
||||
for (const QString &addOnPath : addOnPaths)
|
||||
{
|
||||
@@ -683,11 +677,9 @@ namespace swift::misc::simulation::fscommon
|
||||
QDomDocument doc;
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file)) { continue; }
|
||||
if (CFsDirectories::logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Reading '%1' from addon path: '%2'")
|
||||
<< file.fileName() << addOnPath;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Reading '%1' from addon path: '%2'")
|
||||
<< file.fileName() << addOnPath;
|
||||
|
||||
const QDomNodeList components = doc.elementsByTagName("AddOn.Component");
|
||||
for (int i = 0; i < components.size(); i++)
|
||||
@@ -706,18 +698,15 @@ namespace swift::misc::simulation::fscommon
|
||||
const QString fp = QStringView { pathValue }.left(3).contains(':') ?
|
||||
pathValue :
|
||||
CFileUtils::appendFilePaths(addOnPath, pathValue);
|
||||
if (CFsDirectories::logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Testing '%1' as addon path: '%2'")
|
||||
<< fp << addOnPath;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Testing '%1' as addon path: '%2'")
|
||||
<< fp << addOnPath;
|
||||
|
||||
if (!checked || QDir(fp).exists())
|
||||
{
|
||||
simObjectPaths.insert(CFileUtils::normalizeFilePathToQtStandard(fp));
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D SimObjects path: '%1'") << fp;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D SimObjects path: '%1'") << fp;
|
||||
}
|
||||
} // components
|
||||
} // paths
|
||||
@@ -754,11 +743,9 @@ namespace swift::misc::simulation::fscommon
|
||||
if (fi.exists())
|
||||
{
|
||||
files.push_back(fi.absoluteFilePath());
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX config file: '%1'")
|
||||
<< fi.absoluteFilePath();
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX config file: '%1'")
|
||||
<< fi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
return files;
|
||||
@@ -784,7 +771,7 @@ namespace swift::misc::simulation::fscommon
|
||||
QSet<QString> CFsDirectories::fsxSimObjectsPaths(const QString &fsxFile, bool checked)
|
||||
{
|
||||
const QString fileContent = CFileUtils::readFileToString(fsxFile);
|
||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||
if (fileContent.isEmpty()) { return {}; }
|
||||
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("SimObjectPaths.");
|
||||
|
||||
@@ -794,17 +781,15 @@ namespace swift::misc::simulation::fscommon
|
||||
QSet<QString> paths;
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
const qsizetype i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i1 < 0) { continue; }
|
||||
const int i2 = line.lastIndexOf('=');
|
||||
const qsizetype i2 = line.lastIndexOf('=');
|
||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||
const QStringView path = line.mid(i2 + 1);
|
||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path checked: '%1' in '%2'")
|
||||
<< line << fsxFile;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path checked: '%1' in '%2'")
|
||||
<< line << fsxFile;
|
||||
|
||||
// ignore exclude patterns
|
||||
if (containsAny(soPath, CFsDirectories::fsxSimObjectsExcludeDirectoryPatterns(), Qt::CaseInsensitive))
|
||||
@@ -822,33 +807,29 @@ namespace swift::misc::simulation::fscommon
|
||||
if (checked && !dir.exists())
|
||||
{
|
||||
// skip, not existing
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
|
||||
<< dir.absolutePath() << fsxFile;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
|
||||
<< dir.absolutePath() << fsxFile;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString afp = dir.absolutePath().toLower();
|
||||
if (!CDirectoryUtils::containsFileInDir(afp, airFileFilter(), true))
|
||||
{
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
|
||||
<< afp << fsxFile << airFileFilter();
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
|
||||
<< afp << fsxFile << airFileFilter();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
paths.insert(afp);
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
|
||||
<< afp << fsxFile;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
|
||||
<< afp << fsxFile;
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
@@ -856,7 +837,7 @@ namespace swift::misc::simulation::fscommon
|
||||
QSet<QString> CFsDirectories::msfsSimObjectsPaths(const QString &msfsFile, bool checked)
|
||||
{
|
||||
const QString fileContent = CFileUtils::readFileToString(msfsFile);
|
||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||
if (fileContent.isEmpty()) { return {}; }
|
||||
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("SimObjectPaths.");
|
||||
|
||||
@@ -866,17 +847,15 @@ namespace swift::misc::simulation::fscommon
|
||||
QSet<QString> paths;
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
const qsizetype i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i1 < 0) { continue; }
|
||||
const int i2 = line.lastIndexOf('=');
|
||||
const qsizetype i2 = line.lastIndexOf('=');
|
||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||
const QStringView path = line.mid(i2 + 1);
|
||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"MSFS SimObjects path checked: '%1' in '%2'")
|
||||
<< line << msfsFile;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"MSFS SimObjects path checked: '%1' in '%2'")
|
||||
<< line << msfsFile;
|
||||
|
||||
// ignore exclude patterns
|
||||
if (containsAny(soPath, CFsDirectories::fsxSimObjectsExcludeDirectoryPatterns(), Qt::CaseInsensitive))
|
||||
@@ -891,33 +870,28 @@ namespace swift::misc::simulation::fscommon
|
||||
if (checked && !dir.exists())
|
||||
{
|
||||
// skip, not existing
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
|
||||
<< dir.absolutePath() << msfsFile;
|
||||
}
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
|
||||
<< dir.absolutePath() << msfsFile;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString afp = dir.absolutePath().toLower();
|
||||
if (!CDirectoryUtils::containsFileInDir(afp, airFileFilter(), true))
|
||||
{
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
|
||||
<< afp << msfsFile << airFileFilter();
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr))
|
||||
.info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
|
||||
<< afp << msfsFile << airFileFilter();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
paths.insert(afp);
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
|
||||
<< afp << msfsFile;
|
||||
}
|
||||
|
||||
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
|
||||
<< afp << msfsFile;
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
@@ -928,5 +902,4 @@ namespace swift::misc::simulation::fscommon
|
||||
return a;
|
||||
}
|
||||
|
||||
bool CFsDirectories::logConfigPathReading() { return true; }
|
||||
} // namespace swift::misc::simulation::fscommon
|
||||
|
||||
@@ -169,9 +169,6 @@ namespace swift::misc::simulation::fscommon
|
||||
//! Utility functions
|
||||
static QSet<QString> findP3dConfigFiles(const QString &configFile, const QString &versionHint = "v5");
|
||||
//! @}
|
||||
|
||||
//! Log the reading of config files
|
||||
static bool logConfigPathReading();
|
||||
};
|
||||
} // namespace swift::misc::simulation::fscommon
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace swift::misc
|
||||
{
|
||||
const auto pc = std::find(it, format.end(), u'%');
|
||||
temp.append(&*it, std::distance(it, pc));
|
||||
if ((it = pc) == format.end()) { break; }
|
||||
if (it = pc; it == format.end()) { break; }
|
||||
if (++it == format.end())
|
||||
{
|
||||
temp += u'%';
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "misc/stringutils.h"
|
||||
|
||||
#include <any>
|
||||
|
||||
#include <QChar>
|
||||
#include <QRegularExpression>
|
||||
#include <QStringBuilder>
|
||||
@@ -156,8 +158,8 @@ namespace swift::misc
|
||||
const QString bStr = str1.length() >= str2.length() ? str2 : str1;
|
||||
|
||||
// starts/ends with
|
||||
const double s1 = aStr.length();
|
||||
const double s2 = bStr.length();
|
||||
const auto s1 = static_cast<double>(aStr.length());
|
||||
const auto s2 = static_cast<double>(bStr.length());
|
||||
if (aStr.endsWith(bStr, cs)) { return qRound(s1 / s2 * 100); }
|
||||
if (aStr.startsWith(bStr, cs)) { return qRound(s1 / s2 * 100); }
|
||||
|
||||
@@ -195,17 +197,17 @@ namespace swift::misc
|
||||
|
||||
QString intToHex(int value, int digits)
|
||||
{
|
||||
QString hex(QString::number(value, 16).toUpper());
|
||||
int l = hex.length();
|
||||
const QString hex(QString::number(value, 16).toUpper());
|
||||
const qsizetype l = hex.length();
|
||||
if (l >= digits) { return hex.right(digits); }
|
||||
int d = digits - l;
|
||||
const qsizetype d = digits - l;
|
||||
return QString(d, '0') + hex;
|
||||
}
|
||||
|
||||
QString stripDesignatorFromCompleterString(const QString &candidate)
|
||||
{
|
||||
const QString s(candidate.trimmed().toUpper());
|
||||
if (s.isEmpty()) { return QString(); }
|
||||
if (s.isEmpty()) { return {}; }
|
||||
return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ namespace swift::misc
|
||||
for (int i = 0; i < candidate.length(); i++)
|
||||
{
|
||||
const QChar c = candidate[i];
|
||||
int dIndex = diacriticLetters.indexOf(c);
|
||||
const qsizetype dIndex = diacriticLetters.indexOf(c);
|
||||
if (dIndex < 0) { output.append(c); }
|
||||
else
|
||||
{
|
||||
@@ -268,7 +270,7 @@ namespace swift::misc
|
||||
|
||||
QDateTime fromStringUtc(const QString &dateTimeString, const QString &format)
|
||||
{
|
||||
if (dateTimeString.isEmpty() || format.isEmpty()) { return QDateTime(); }
|
||||
if (dateTimeString.isEmpty() || format.isEmpty()) { return {}; }
|
||||
QDateTime dt = QDateTime::fromString(dateTimeString, format);
|
||||
if (!dt.isValid()) { return dt; }
|
||||
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
|
||||
@@ -277,7 +279,7 @@ namespace swift::misc
|
||||
|
||||
QDateTime fromStringUtc(const QString &dateTimeString, Qt::DateFormat format)
|
||||
{
|
||||
if (dateTimeString.isEmpty()) { return QDateTime(); }
|
||||
if (dateTimeString.isEmpty()) { return {}; }
|
||||
QDateTime dt = QDateTime::fromString(dateTimeString, format);
|
||||
if (!dt.isValid()) { return dt; }
|
||||
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
|
||||
@@ -286,7 +288,7 @@ namespace swift::misc
|
||||
|
||||
QDateTime fromStringUtc(const QString &dateTimeString, const QLocale &locale, QLocale::FormatType format)
|
||||
{
|
||||
if (dateTimeString.isEmpty()) { return QDateTime(); }
|
||||
if (dateTimeString.isEmpty()) { return {}; }
|
||||
QDateTime dt = locale.toDateTime(dateTimeString, format);
|
||||
if (!dt.isValid()) { return dt; }
|
||||
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
|
||||
@@ -295,7 +297,7 @@ namespace swift::misc
|
||||
|
||||
QDateTime parseMultipleDateTimeFormats(const QString &dateTimeString)
|
||||
{
|
||||
if (dateTimeString.isEmpty()) { return QDateTime(); }
|
||||
if (dateTimeString.isEmpty()) { return {}; }
|
||||
if (isDigitsOnlyString(dateTimeString))
|
||||
{
|
||||
// 2017 0301 124421 321
|
||||
@@ -303,7 +305,7 @@ namespace swift::misc
|
||||
if (dateTimeString.length() == 14) { return fromStringUtc(dateTimeString, "yyyyMMddHHmmss"); }
|
||||
if (dateTimeString.length() == 12) { return fromStringUtc(dateTimeString, "yyyyMMddHHmm"); }
|
||||
if (dateTimeString.length() == 8) { return fromStringUtc(dateTimeString, "yyyyMMdd"); }
|
||||
return QDateTime();
|
||||
return {};
|
||||
}
|
||||
|
||||
// remove simple separators and check if digits only again
|
||||
@@ -331,12 +333,12 @@ namespace swift::misc
|
||||
|
||||
// SystemLocaleShortDate,
|
||||
// SystemLocaleLongDate,
|
||||
return QDateTime();
|
||||
return {};
|
||||
}
|
||||
|
||||
QDateTime parseDateTimeStringOptimized(const QString &dateTimeString)
|
||||
{
|
||||
if (dateTimeString.length() < 8) { return QDateTime(); }
|
||||
if (dateTimeString.length() < 8) { return {}; }
|
||||
|
||||
// yyyyMMddHHmmsszzz
|
||||
// 01234567890123456
|
||||
@@ -393,12 +395,12 @@ namespace swift::misc
|
||||
return question % u'?';
|
||||
}
|
||||
|
||||
int nthIndexOf(const QString &string, QChar ch, int nth, Qt::CaseSensitivity cs)
|
||||
qsizetype nthIndexOf(const QString &string, QChar ch, int nth, Qt::CaseSensitivity cs)
|
||||
{
|
||||
if (nth < 1 || string.isEmpty() || nth > string.length()) { return -1; }
|
||||
|
||||
int from = 0;
|
||||
int ci = -1;
|
||||
qsizetype from = 0;
|
||||
qsizetype ci = -1;
|
||||
for (int t = 0; t < nth; ++t)
|
||||
{
|
||||
ci = string.indexOf(ch, from, cs);
|
||||
@@ -423,7 +425,7 @@ namespace swift::misc
|
||||
for (const QStringView &l : lines)
|
||||
{
|
||||
if (l.isEmpty()) { continue; }
|
||||
const int i = l.indexOf('=');
|
||||
const qsizetype i = l.indexOf('=');
|
||||
if (i < 0 || i >= l.length() + 1) { continue; }
|
||||
|
||||
const QString key = l.left(i).trimmed().toString();
|
||||
@@ -452,7 +454,7 @@ namespace swift::misc
|
||||
{
|
||||
QString copy(in);
|
||||
|
||||
thread_local const QRegularExpression re1("\\/\\*(.|\\n)*?\\*\\/");
|
||||
thread_local const QRegularExpression re1(R"(\/\*(.|\n)*?\*\/)");
|
||||
if (removeSlashStar) { copy.remove(re1); }
|
||||
|
||||
thread_local const QRegularExpression re2("\\/\\/.*");
|
||||
@@ -461,33 +463,23 @@ namespace swift::misc
|
||||
return copy;
|
||||
}
|
||||
|
||||
const QString &defaultIfEmpty(const QString &candidate, const QString &defaultIfEmpty)
|
||||
{
|
||||
if (candidate.isEmpty()) { return defaultIfEmpty; }
|
||||
return candidate;
|
||||
}
|
||||
|
||||
bool containsAny(const QString &testString, const QStringList &any, Qt::CaseSensitivity cs)
|
||||
{
|
||||
if (testString.isEmpty() || any.isEmpty()) { return false; }
|
||||
for (const QString &a : any)
|
||||
{
|
||||
if (testString.contains(a, cs)) { return true; }
|
||||
}
|
||||
return false;
|
||||
return std::any_of(any.begin(), any.end(), [&](const QString &a) { return testString.contains(a, cs); });
|
||||
}
|
||||
|
||||
bool hasBalancedQuotes(const QString &in, char quote)
|
||||
{
|
||||
if (in.isEmpty()) { return true; }
|
||||
const int c = in.count(quote);
|
||||
const qsizetype c = in.count(quote);
|
||||
return (c % 2) == 0;
|
||||
}
|
||||
|
||||
double parseFraction(const QString &fraction, double failDefault)
|
||||
{
|
||||
if (fraction.isEmpty()) { return failDefault; }
|
||||
bool ok;
|
||||
bool ok {};
|
||||
|
||||
double r = failDefault;
|
||||
if (fraction.contains('/'))
|
||||
@@ -513,9 +505,9 @@ namespace swift::misc
|
||||
QString cleanNumber(const QString &number)
|
||||
{
|
||||
QString n = number.trimmed();
|
||||
if (n.isEmpty()) { return QString(); }
|
||||
if (n.isEmpty()) { return {}; }
|
||||
|
||||
int dp = n.indexOf('.');
|
||||
qsizetype dp = n.indexOf('.');
|
||||
if (dp < 0) { dp = n.indexOf(','); }
|
||||
|
||||
// clean all trailing stuff
|
||||
@@ -527,7 +519,7 @@ namespace swift::misc
|
||||
n.chop(1);
|
||||
continue;
|
||||
}
|
||||
else if (l == '.' || l == ',') { n.chop(1); }
|
||||
if (l == '.' || l == ',') { n.chop(1); }
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace swift::misc
|
||||
}
|
||||
|
||||
//! nth index of ch
|
||||
SWIFT_MISC_EXPORT int nthIndexOf(const QString &string, QChar ch, int nth = 1,
|
||||
Qt::CaseSensitivity cs = Qt::CaseInsensitive);
|
||||
SWIFT_MISC_EXPORT qsizetype nthIndexOf(const QString &string, QChar ch, int nth = 1,
|
||||
Qt::CaseSensitivity cs = Qt::CaseInsensitive);
|
||||
|
||||
//! Split a string into multiple strings, using a predicate function to identify the split points.
|
||||
//! \warning The returned refs are only valid during the lifetime of the original string.
|
||||
@@ -92,7 +92,7 @@ namespace swift::misc
|
||||
{
|
||||
QList<QStringView> result;
|
||||
auto notPredicate = [=](auto c) { return !predicate(c); };
|
||||
auto begin = s.begin();
|
||||
const auto *begin = s.begin();
|
||||
while (true)
|
||||
{
|
||||
begin = std::find_if(begin, s.end(), notPredicate);
|
||||
@@ -302,9 +302,6 @@ namespace swift::misc
|
||||
//! Remove comments such as /** **/ or //
|
||||
SWIFT_MISC_EXPORT QString removeComments(const QString &in, bool removeSlash, bool removeDoubleSlash);
|
||||
|
||||
//! Default string if string is empty
|
||||
SWIFT_MISC_EXPORT const QString &defaultIfEmpty(const QString &candidate, const QString &defaultIfEmpty);
|
||||
|
||||
//! Contains any string of the list?
|
||||
SWIFT_MISC_EXPORT bool containsAny(const QString &testString, const QStringList &any, Qt::CaseSensitivity cs);
|
||||
|
||||
|
||||
@@ -138,21 +138,18 @@ namespace swift::misc
|
||||
try
|
||||
{
|
||||
const void *casted = nullptr;
|
||||
if ((casted = aMeta->upCastTo(a.data(), bMeta->getMetaTypeId())))
|
||||
if (casted = aMeta->upCastTo(a.data(), bMeta->getMetaTypeId()); casted)
|
||||
{
|
||||
return bMeta->compareImpl(casted, b.data());
|
||||
}
|
||||
else if ((casted = bMeta->upCastTo(b.data(), aMeta->getMetaTypeId())))
|
||||
if (casted = bMeta->upCastTo(b.data(), aMeta->getMetaTypeId()); casted)
|
||||
{
|
||||
return aMeta->compareImpl(a.data(), casted);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(&a).warning(
|
||||
u"Comparing two CVariants containing unrelated value objects: %1 (%2) and %3 (%4)")
|
||||
<< a.typeName() << a.userType() << b.typeName() << b.userType();
|
||||
return 0;
|
||||
}
|
||||
CLogMessage(&a).warning(
|
||||
u"Comparing two CVariants containing unrelated value objects: %1 (%2) and %3 (%4)")
|
||||
<< a.typeName() << a.userType() << b.typeName() << b.userType();
|
||||
return 0;
|
||||
}
|
||||
catch (const private_ns::CVariantException &ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user