mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T718, improved country "resolution" in server names/descriptions
This commit is contained in:
committed by
Mat Sutcliffe
parent
009719a7be
commit
bb8f46ed68
@@ -95,7 +95,7 @@ namespace BlackGui
|
||||
const CCountry country(this->findCountry(server));
|
||||
if (country.getName().isEmpty())
|
||||
{
|
||||
this->addItem(d);
|
||||
this->addItem(CIcons::empty16(), d);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -135,7 +135,21 @@ namespace BlackGui
|
||||
{
|
||||
if (!CServerListSelector::knowsAllCountries()) { return CCountry(); }
|
||||
static const CCountryList countries(sGui->getWebDataServices()->getCountries());
|
||||
return countries.findBestMatchByCountryName(server.getName());
|
||||
const CCountry ctryByName = countries.findBestMatchByCountryName(server.getName());
|
||||
if (ctryByName.isValid()) { return ctryByName; }
|
||||
|
||||
// own approach, see if description contains a valid countr name
|
||||
for (const CCountry &testCtry : countries)
|
||||
{
|
||||
if (testCtry.getName().isEmpty()) { continue; }
|
||||
if (server.getDescription().contains(testCtry.getName(), Qt::CaseInsensitive))
|
||||
{
|
||||
return testCtry;
|
||||
}
|
||||
}
|
||||
|
||||
const CCountry ctryByDescription = countries.findBestMatchByCountryName(server.getDescription());
|
||||
return ctryByDescription;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace BlackMisc
|
||||
CCountry findByIsoCode(const QString &isoCode) const;
|
||||
|
||||
//! Find "best match" by country
|
||||
CCountry findBestMatchByCountryName(const QString &countryName) const;
|
||||
CCountry findBestMatchByCountryName(const QString &candidate) const;
|
||||
|
||||
//! Find first by alias
|
||||
CCountry findFirstByAlias(const QString &alias) const;
|
||||
|
||||
Reference in New Issue
Block a user