diff --git a/core/Callsign.cpp b/core/Callsign.cpp index 28ea5132..a31486e2 100644 --- a/core/Callsign.cpp +++ b/core/Callsign.cpp @@ -34,13 +34,13 @@ Callsign::Callsign(const QString &callsign, } } -QRegularExpression Callsign::callsignRegEx() +const QRegularExpression Callsign::callsignRegEx() { FCT_IDENTIFICATION; return QRegularExpression(callsignRegExString(), QRegularExpression::CaseInsensitiveOption); } -QString Callsign::callsignRegExString() +const QString Callsign::callsignRegExString() { FCT_IDENTIFICATION; return QString("^(([A-Z0-9]+)[\\/])?(([A-Z][0-9]|[A-Z]{1,2}|[0-9][A-Z])([0-9]|[0-9]+)([A-Z]+))([\\/]([A-Z0-9]+))?"); @@ -102,3 +102,16 @@ bool Callsign::isValid() const return valid; } +// Based on wiki information +// https://en.wikipedia.org/wiki/Amateur_radio_call_signs +const QStringList Callsign::secondarySpecialSuffixes = +{ + "A", // operator at a secondary location registered with the licensing authorities + "AM", // aeronautical mobile + "M", // mobile operation + "MM", // marine mobile + "P", // portable operation + "QRP", // QRP - unofficial + "R", // repeaters + "B" // beacon +}; diff --git a/core/Callsign.h b/core/Callsign.h index 8b1c100b..3a87f0a3 100644 --- a/core/Callsign.h +++ b/core/Callsign.h @@ -10,8 +10,9 @@ class Callsign : public QObject public: explicit Callsign(const QString &callsign, QObject *parent = nullptr); - static QRegularExpression callsignRegEx(); - static QString callsignRegExString(); + static const QRegularExpression callsignRegEx(); + static const QString callsignRegExString(); + static const QStringList secondarySpecialSuffixes; QString getCallsign() const; QString getHostPrefix() const; diff --git a/data/Data.cpp b/data/Data.cpp index 07f9dab1..c1a35800 100644 --- a/data/Data.cpp +++ b/data/Data.cpp @@ -991,18 +991,23 @@ DxccEntity Data::lookupDxcc(const QString &callsign) } QString lookupPrefix = callsign; // use the callsign with optional prefix as default to find the dxcc - QStringList specialSuffixes = { "AM", "MM", "QRP" }; // a list of suffixes that have a special meaning - Callsign parsedCallsign(callsign); // use Callsign to split the callsign into its parts - if ( parsedCallsign.isValid() ) { + + if ( parsedCallsign.isValid() ) + { QString suffix = parsedCallsign.getSuffix(); - if ( suffix.length() == 1 ) { // some countries add single numbers as suffix to designate a call area, e.g. /4 + if ( suffix.length() == 1 ) // some countries add single numbers as suffix to designate a call area, e.g. /4 + { bool isNumber = false; - int number = suffix.toInt(&isNumber); - if ( isNumber ) { + (void)suffix.toInt(&isNumber); + if ( isNumber ) + { lookupPrefix = parsedCallsign.getBasePrefix() + suffix; // use the call prefix and the number from the suffix to find the dxcc } - } else if ( suffix.length() > 1 && !specialSuffixes.contains(suffix) ) { // if there is more than one character and it is not one of the special suffixes, we definitely have a call prefix as suffix + } + else if ( suffix.length() > 1 + && !parsedCallsign.secondarySpecialSuffixes.contains(suffix) ) // if there is more than one character and it is not one of the special suffixes, we definitely have a call prefix as suffix + { lookupPrefix = suffix; } }