Ref T26, 1st implementation using flight plan remarks

This commit is contained in:
Klaus Basan
2017-06-27 00:36:58 +02:00
committed by Mathew Sutcliffe
parent ae2eb66721
commit e3fd0e20c1
4 changed files with 79 additions and 7 deletions

View File

@@ -14,9 +14,45 @@ namespace BlackMisc
{
namespace Aviation
{
void CFlightPlanUtils::parseFlightPlanRemarks(const QString &remarks)
CFlightPlanUtils::AirlineRemarks CFlightPlanUtils::parseFlightPlanAirlineRemarks(const QString &remarks)
{
if (remarks.isEmpty()) { return; }
AirlineRemarks ar;
if (remarks.isEmpty()) { return ar; }
const QString r = remarks.toUpper();
if (r.contains("/CALLSIGN"))
{
// used similar to radio telephony
ar.radioTelephony = cut(r, "/CALLSIGN");
}
else if (r.contains("/RT"))
{
// radio telephony designator
ar.radioTelephony = cut(r, "/RT");
}
if (r.contains("/OPR"))
{
// operator, e.g. British airways
ar.flightOperator = cut(r, "/OPR");
}
return ar;
}
QString CFlightPlanUtils::cut(const QString &remarks, const QString &marker)
{
const int maxIndex = remarks.size() - 1;
int f = remarks.indexOf(marker);
if (f < 0) { return ""; }
f += marker.length();
if (maxIndex <= f) { return ""; }
int to = remarks.indexOf(' ', f + 1);
if (to < 0) { to = maxIndex; } // no more spaces
const QString cut = remarks.mid(f, to - f).replace('/', ' '); // variations like /OPR/EASYJET/
// problem is that this cuts something like "Uzbekistan airways"
return cut;
}
} // namespace
} // namespace
// RT/KESTREL OPR/MYTRAVEL REG/G-DAJC SEL/FP-ES PER/C NAV/RNP10
// VFPS = VATSIM Flightplan Prefile System
// OPR/UAL CALLSIGN/UNITED

View File

@@ -13,6 +13,7 @@
#define BLACKMISC_AVIATION_FLIGHTPLANUTILS_H
#include "blackmisc/blackmiscexport.h"
#include <QString>
namespace BlackMisc
{
@@ -22,11 +23,28 @@ namespace BlackMisc
class BLACKMISC_EXPORT CFlightPlanUtils
{
public:
//! Useful value in flight plan remarks
struct AirlineRemarks
{
QString radioTelephony; //!< radio telephony designator
QString flightOperator; //!< operator, i.e. normally the airline name
//! Any remarks available
bool hasAnyRemarks() const
{
return !radioTelephony.isEmpty() || !flightOperator.isEmpty();
}
};
//! Constructor
CFlightPlanUtils() = delete;
//! Parse remarks from a flight plan
static void parseFlightPlanRemarks(const QString &remarks);
static AirlineRemarks parseFlightPlanAirlineRemarks(const QString &remarks);
private:
//! Cut the remarks part
static QString cut(const QString &remarks, const QString &marker);
};
} // namespace
} // namespace