Ref T718, improved country "resolution" in server names/descriptions

This commit is contained in:
Klaus Basan
2019-08-29 18:13:48 +02:00
committed by Mat Sutcliffe
parent 009719a7be
commit bb8f46ed68
3 changed files with 22 additions and 7 deletions

View File

@@ -29,17 +29,18 @@ namespace BlackMisc
return IDatastoreObjectList::findByKey(isoCode);
}
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
CCountry CCountryList::findBestMatchByCountryName(const QString &candidate) const
{
if (countryName.isEmpty()) { return CCountry(); }
if (candidate.isEmpty()) { return CCountry(); }
thread_local const QRegularExpression reg("^[a-z]+", QRegularExpression::CaseInsensitiveOption);
const QRegularExpressionMatch match = reg.match(countryName);
const QString cn(match.hasMatch() ? match.captured(0) : countryName);
const QRegularExpressionMatch match = reg.match(candidate);
const QString cn(match.hasMatch() ? match.captured(0) : candidate);
const CCountryList countries = this->findBy([&](const CCountry & country)
{
return country.matchesCountryName(cn);
});
if (countries.isEmpty()) { return this->findFirstByAlias(cn); }
if (countries.size() < 2) { return countries.frontOrDefault(); }