summaryrefslogtreecommitdiff
path: root/logbook/countrydat.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
commit37f727ac0746fd85504aa46c1f023c09b3eff33a (patch)
treec8a7ce04545040a8f161ba279528730bd9a3e6ab /logbook/countrydat.cpp
parentd63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff)
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'logbook/countrydat.cpp')
-rw-r--r--logbook/countrydat.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/logbook/countrydat.cpp b/logbook/countrydat.cpp
index 1d88e059..7f3d613b 100644
--- a/logbook/countrydat.cpp
+++ b/logbook/countrydat.cpp
@@ -26,7 +26,7 @@ void CountryDat::init(const QString filename)
_data.clear();
}
-QString CountryDat::_extractName(const QString line)
+QString CountryDat::_extractName(const QString line) const
{
int s1 = line.indexOf(':');
if (s1>=0)
@@ -37,7 +37,7 @@ QString CountryDat::_extractName(const QString line)
return "";
}
-void CountryDat::_removeBrackets(QString &line, const QString a, const QString b)
+void CountryDat::_removeBrackets(QString &line, const QString a, const QString b) const
{
int s1 = line.indexOf(a);
while (s1 >= 0)
@@ -48,10 +48,9 @@ void CountryDat::_removeBrackets(QString &line, const QString a, const QString b
}
}
-QStringList CountryDat::_extractPrefix(QString &line, bool &more)
+QStringList CountryDat::_extractPrefix(QString &line, bool &more) const
{
line = line.remove(" \n");
- line = line.replace("=","");
line = line.replace(" ","");
_removeBrackets(line,"(",")");
@@ -117,20 +116,38 @@ void CountryDat::load()
}
// return country name else ""
-QString CountryDat::find(const QString prefix)
+QString CountryDat::find(QString call) const
{
- QString pf = prefix.toUpper();
- while(pf.length() >= 1)
- {
- if (_data.contains(pf))
- {
- QString country = _data.value(pf);
- return country;
- }
- pf = pf.left(pf.length()-1);
- }
- return "";
-}
-
-
+ call = call.toUpper ();
+ // check for exact match first
+ if (_data.contains ("=" + call))
+ {
+ return fixup (_data.value ("=" + call), call);
+ }
+
+ auto prefix = call;
+ while (prefix.size () >= 1)
+ {
+ if (_data.contains (prefix))
+ {
+ return fixup (_data.value (prefix), call);
+ }
+ prefix = prefix.left (prefix.size () - 1);
+ }
+ return QString {};
+}
+
+QString CountryDat::fixup (QString country, QString const& call) const
+{
+ //
+ // deal with special rules that cty.dat does not cope with
+ //
+
+ // KG4 2x1 and 2x3 calls that map to Gitmo are mainland US not Gitmo
+ if (call.startsWith ("KG4") && call.size () != 5)
+ {
+ country.replace ("Guantanamo Bay", "United States");
+ }
+ return country;
+}