mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
ref #701, "improved countries"
* utility function for "accent free" strings * added 3 letter ISO, alias names * improved searching in countries
This commit is contained in:
@@ -33,13 +33,14 @@ namespace BlackMisc
|
||||
{
|
||||
if (countryName.isEmpty()) { return CCountry(); }
|
||||
|
||||
static const QRegExp reg("[^a-z]", Qt::CaseInsensitive);
|
||||
QString cn(countryName);
|
||||
cn.remove(reg);
|
||||
static const QRegExp reg("^[a-z]+", Qt::CaseInsensitive);
|
||||
int pos = reg.indexIn(countryName);
|
||||
const QString cn(pos >= 0 ? reg.cap(0) : countryName);
|
||||
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(); }
|
||||
|
||||
// find best match by further reducing
|
||||
@@ -52,6 +53,17 @@ namespace BlackMisc
|
||||
return countries.front();
|
||||
}
|
||||
|
||||
CCountry CCountryList::findFirstByAlias(const QString &alias) const
|
||||
{
|
||||
if (alias.isEmpty()) { return CCountry(); }
|
||||
const QString a(alias.toUpper().trimmed());
|
||||
for (const CCountry &country : (*this))
|
||||
{
|
||||
if (country.matchesAlias(a)) { return country;}
|
||||
}
|
||||
return CCountry();
|
||||
}
|
||||
|
||||
QStringList CCountryList::toIsoNameList() const
|
||||
{
|
||||
QStringList sl;
|
||||
@@ -88,7 +100,6 @@ namespace BlackMisc
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
CCountryList CCountryList::fromDatabaseJson(const QJsonArray &array)
|
||||
{
|
||||
CCountryList countries;
|
||||
@@ -99,5 +110,4 @@ namespace BlackMisc
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user