From e2771c0cd75c774f0b42f417ad196a53f1ff9c60 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 1 Oct 2017 21:44:07 +0000 Subject: [PATCH] Fix cty.dat lookups that were not honouring exact match flags git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8152 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- logbook/countrydat.cpp | 52 ++++++++++++++++++++++++------------------ logbook/countrydat.h | 1 + 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/logbook/countrydat.cpp b/logbook/countrydat.cpp index d0d976d69..7f3d613ba 100644 --- a/logbook/countrydat.cpp +++ b/logbook/countrydat.cpp @@ -51,7 +51,6 @@ void CountryDat::_removeBrackets(QString &line, const QString a, const QString b QStringList CountryDat::_extractPrefix(QString &line, bool &more) const { line = line.remove(" \n"); - line = line.replace("=",""); line = line.replace(" ",""); _removeBrackets(line,"(",")"); @@ -117,29 +116,38 @@ void CountryDat::load() } // return country name else "" -QString CountryDat::find(QString prefix) const +QString CountryDat::find(QString call) const { - prefix = prefix.toUpper (); - auto pf = prefix; - while (pf.size () >= 1) - { - if (_data.contains (pf)) + 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)) { - QString country {_data.value (pf)}; - - // - // 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 (prefix.startsWith ("KG4") && prefix.size () != 5) - { - country.replace ("Guantanamo Bay", "United States"); - } - - return country; + return fixup (_data.value (prefix), call); } - pf = pf.left (pf.size () - 1); + 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; +} diff --git a/logbook/countrydat.h b/logbook/countrydat.h index 383e783f1..d04308924 100644 --- a/logbook/countrydat.h +++ b/logbook/countrydat.h @@ -26,6 +26,7 @@ private: QString _extractName(const QString line) const; void _removeBrackets(QString &line, const QString a, const QString b) const; QStringList _extractPrefix(QString &line, bool &more) const; + QString fixup (QString country, QString const& call) const; QString _filename; QStringList _countryNames;