refs #533, fix callsign validation and split into functions for ATC/aircraft

This commit is contained in:
Klaus Basan
2015-12-08 06:50:07 +01:00
parent 6ac1808d25
commit f9c160d625
7 changed files with 60 additions and 12 deletions

View File

@@ -187,26 +187,60 @@ namespace BlackMisc
return 0;
}
bool CCallsign::isValidCallsign(const QString &callsign)
bool CCallsign::isValid() const
{
switch (m_typeHint)
{
case Atc:
return isValidAtcCallsign(*this);
case Aircraft:
return isValidAircraftCallsign(*this);
default:
return !this->isEmpty();
}
}
bool CCallsign::isValidAircraftCallsign(const QString &callsign)
{
// We allow all number callsigns
if (callsign.length() < 2 || callsign.length() > 10) { return false; }
// We allow all number callsigns
static QThreadStorage<QRegularExpression> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z0-9]*$")); }
const QRegularExpression &regexp = tsRegex.localData();
return (regexp.match(callsign).hasMatch());
}
bool CCallsign::isValidAircraftCallsign(const CCallsign &callsign)
{
return isValidAircraftCallsign(callsign.asString());
}
bool CCallsign::isValidAtcCallsign(const QString &callsign)
{
if (callsign.length() < 2 || callsign.length() > 10) { return false; }
// We allow all number callsigns
static QThreadStorage<QRegularExpression> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z0-9_]*$")); }
const QRegularExpression &regexp = tsRegex.localData();
return (regexp.match(callsign).hasMatch());
}
bool CCallsign::isValidAtcCallsign(const CCallsign &callsign)
{
return isValidAtcCallsign(callsign.asString());
}
const QStringList &CCallsign::atcCallsignSuffixes()
{
static const QStringList a( { "APP", "GND", "TWR", "DEL", "CTR" });
static const QStringList a({ "APP", "GND", "TWR", "DEL", "CTR" });
return a;
}
const QStringList &CCallsign::atcAlikeCallsignSuffixes()
{
static const QStringList a( { "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS" });
static const QStringList a({ "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS" });
return a;
}

View File

@@ -78,7 +78,7 @@ namespace BlackMisc
//! Supervisor?
bool isSupervisorCallsign() const;
//! Get callsign.
//! Get callsign (normalized)
const QString &asString() const { return this->m_callsign; }
//! Get callsign.
@@ -121,7 +121,19 @@ namespace BlackMisc
int comparePropertyByIndex(const CCallsign &compareValue, const CPropertyIndex &index) const;
//! Valid callsign?
static bool isValidCallsign(const QString &callsign);
bool isValid() const;
//! Valid callsign?
static bool isValidAircraftCallsign(const QString &callsign);
//! Valid callsign?
static bool isValidAircraftCallsign(const CCallsign &callsign);
//! Valid callsign?
static bool isValidAtcCallsign(const QString &callsign);
//! Valid callsign?
static bool isValidAtcCallsign(const CCallsign &callsign);
//! List of real ATC suffixes (e.g. TWR);
static const QStringList &atcCallsignSuffixes();

View File

@@ -140,7 +140,7 @@ namespace BlackMisc
bool hasAircraftAndAirlineDesignator() const;
//! Valid callsign?
bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidCallsign(this->getCallsign().asString()); }
bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidAircraftCallsign(this->getCallsign().asString()); }
//! Callsign not empty, no further checks
bool hasCallsign() const { return !getCallsign().isEmpty(); }