summaryrefslogtreecommitdiff
path: root/logbook/countrydat.cpp
diff options
context:
space:
mode:
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;
+}