mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Improved VATSIM datafile parsing
* removed empty split value at end * some formatting * columns to lower case at 1st parsing, not always
This commit is contained in:
@@ -149,9 +149,9 @@ namespace BlackCore
|
||||
CUser user;
|
||||
for (int v = 0; v < bookingNodeValues.size(); v++)
|
||||
{
|
||||
QDomNode bookingNodeValue = bookingNodeValues.at(v);
|
||||
QString name = bookingNodeValue.nodeName().toLower();
|
||||
QString value = bookingNodeValue.toElement().text();
|
||||
const QDomNode bookingNodeValue = bookingNodeValues.at(v);
|
||||
const QString name = bookingNodeValue.nodeName().toLower();
|
||||
const QString value = bookingNodeValue.toElement().text();
|
||||
if (name == "id")
|
||||
{
|
||||
// could be used as unique key
|
||||
@@ -182,7 +182,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
// time checks
|
||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
if (now.msecsTo(bookedStation.getBookedUntilUtc()) < (1000 * 60 * 15)) { continue; } // until n mins in past
|
||||
if (now.msecsTo(bookedStation.getBookedFromUtc()) > (1000 * 60 * 60 * 24)) { continue; } // to far in the future, n hours
|
||||
bookedStation.setController(user);
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace BlackCore
|
||||
// ; !CLIENTS section
|
||||
int i = currentLine.lastIndexOf(' ');
|
||||
const QVector<QStringRef> attributes = currentLine.midRef(i).trimmed().split(':', QString::SkipEmptyParts);
|
||||
for (const QStringRef &attr : attributes) { clientSectionAttributes.push_back(attr.toString()); }
|
||||
for (const QStringRef &attr : attributes) { clientSectionAttributes.push_back(attr.toString().trimmed().toLower()); }
|
||||
section = SectionNone; // reset
|
||||
}
|
||||
continue;
|
||||
@@ -447,14 +447,20 @@ namespace BlackCore
|
||||
{
|
||||
QMap<QString, QString> parts;
|
||||
if (currentLine.isEmpty()) { return parts; }
|
||||
const QStringList clientParts = currentLine.split(':');
|
||||
QStringList clientParts = currentLine.split(':');
|
||||
|
||||
// remove last empty item if required
|
||||
if (currentLine.endsWith(':')) { clientParts.removeLast(); }
|
||||
if (clientParts.size() != clientSectionAttributes.size())
|
||||
{
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, "Wrong parts size");
|
||||
return parts;
|
||||
}
|
||||
|
||||
for (int i = 0; i < clientSectionAttributes.size(); i++)
|
||||
{
|
||||
// section attributes are the column names
|
||||
// more column names than parts
|
||||
const QString attribute(clientSectionAttributes.at(i).toLower());
|
||||
BLACK_VERIFY_X(i < clientParts.size(), Q_FUNC_INFO, "Wrong parts size");
|
||||
if (i < clientSectionAttributes.size() || i < clientParts.size()) { continue; }
|
||||
const QString attribute(clientSectionAttributes.at(i));
|
||||
parts.insert(attribute, clientParts.at(i));
|
||||
}
|
||||
return parts;
|
||||
|
||||
@@ -148,6 +148,7 @@ namespace BlackCore
|
||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Network::CVoiceCapabilities> m_voiceCapabilities;
|
||||
|
||||
//! Split line and assign values to their corresponding attribute names
|
||||
//! \remark attributes expected as lower case
|
||||
static const QMap<QString, QString> clientPartsToMap(const QString ¤tLine, const QStringList &clientSectionAttributes);
|
||||
|
||||
//! Section in file
|
||||
|
||||
@@ -97,11 +97,11 @@ namespace BlackMisc
|
||||
static QThreadStorage<QRegularExpression> tsRegex;
|
||||
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("(-\\s*|\\s)([A-Z]{4})$")); }
|
||||
const auto ®ex = tsRegex.localData();
|
||||
QRegularExpressionMatch match = regex.match(rn);
|
||||
const QRegularExpressionMatch match = regex.match(rn);
|
||||
if (match.hasMatch())
|
||||
{
|
||||
int pos = match.capturedStart(0);
|
||||
QString icao = match.captured(0).trimmed().right(4);
|
||||
const int pos = match.capturedStart(0);
|
||||
const QString icao = match.captured(0).trimmed().right(4);
|
||||
rn = rn.leftRef(pos).trimmed().toString();
|
||||
this->setHomeBase(CAirportIcaoCode(icao));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user