Skip to content

Commit

Permalink
Fixed #226 - US call area suffixes not handled correctly
Browse files Browse the repository at this point in the history
Only minor changes and merge of Florian Thienel PR #227
  • Loading branch information
foldynl committed Jul 24, 2023
1 parent c5a2a68 commit 12dd9f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
17 changes: 15 additions & 2 deletions core/Callsign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]+))?");
Expand Down Expand Up @@ -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
};
5 changes: 3 additions & 2 deletions core/Callsign.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions data/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 12dd9f9

Please sign in to comment.