mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
Ref T562, fix 2-letter aircraft ICAO codes
* added constexpr for aircraft ICAO min/max length * use ICAO designator in FP if there is no "getCombinedPrefixIcaoSuffix"
This commit is contained in:
committed by
Mat Sutcliffe
parent
e31fa91052
commit
a4dc89a295
@@ -672,7 +672,7 @@ namespace BlackMisc
|
||||
|
||||
bool CAircraftIcaoCode::isValidDesignator(const QString &designator)
|
||||
{
|
||||
if (designator.length() < 2 || designator.length() > 5) { return false; }
|
||||
if (designator.length() < DesignatorMinLength || designator.length() > DesignatorMaxLength) { return false; }
|
||||
if (!designator[0].isUpper()) { return false; }
|
||||
return !containsChar(designator, [](QChar c) { return !c.isUpper() && !c.isDigit(); });
|
||||
}
|
||||
|
||||
@@ -345,6 +345,9 @@ namespace BlackMisc
|
||||
//! From our database JSON format
|
||||
static CAircraftIcaoCode fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
|
||||
|
||||
static constexpr int DesignatorMinLength = 2; //!< designator length (min)
|
||||
static constexpr int DesignatorMaxLength = 5; //!< designator length (max)
|
||||
|
||||
private:
|
||||
QString m_designator; //!< "B737"
|
||||
QString m_iataCode; //!< "320"
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BlackMisc
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::findByDesignator(const QString &designator, int fuzzySearch) const
|
||||
{
|
||||
if (!fuzzySearch && !CAircraftIcaoCode::isValidDesignator(designator)) { return CAircraftIcaoCodeList(); }
|
||||
if (fuzzySearch && designator.length() < 3) { return CAircraftIcaoCodeList(); }
|
||||
if (fuzzySearch && designator.length() < CAircraftIcaoCode::DesignatorMinLength) { return CAircraftIcaoCodeList(); }
|
||||
return this->findBy([&](const CAircraftIcaoCode & code)
|
||||
{
|
||||
return code.matchesDesignator(designator, fuzzySearch);
|
||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
||||
|
||||
CAircraftIcaoCode CAircraftIcaoCodeList::findBestFuzzyMatchOrDefault(const QString &designator, int cutoff) const
|
||||
{
|
||||
if (designator.length() < 3) { return CAircraftIcaoCode(); }
|
||||
if (designator.length() < CAircraftIcaoCode::DesignatorMinLength) { return CAircraftIcaoCode(); }
|
||||
int best = 0;
|
||||
int current = 0;
|
||||
CAircraftIcaoCode found;
|
||||
|
||||
Reference in New Issue
Block a user