7 #include <QRegularExpression>
20 const QString iso(isoCode.trimmed().toUpper());
22 return IDatastoreObjectList::findByKey(isoCode);
27 if (candidate.isEmpty()) {
return CCountry(); }
29 thread_local
const QRegularExpression reg(
"^[a-z]+", QRegularExpression::CaseInsensitiveOption);
30 const QRegularExpressionMatch match = reg.match(candidate);
31 const QString cn(match.hasMatch() ? match.captured(0) : candidate);
41 if (c.getName() == cn) {
return c; }
42 if (c.getName().startsWith(cn, Qt::CaseInsensitive)) {
return c; }
43 if (cn.startsWith(c.getName(), Qt::CaseInsensitive)) {
return c; }
45 return countries.
front();
50 if (alias.isEmpty()) {
return CCountry(); }
51 const QString a(alias.toUpper().trimmed());
52 for (
const CCountry &country : (*
this))
54 if (country.matchesAlias(a)) {
return country; }
62 for (
const CCountry &country : (*
this))
64 const QString s = country.getCombinedStringIsoName();
65 if (s.isEmpty()) {
continue; }
75 for (
const CCountry &country : (*
this))
77 const QString s = country.getCombinedStringNameIso();
78 if (s.isEmpty()) {
continue; }
88 for (
const CCountry &country : (*
this))
90 const QString s = country.getName();
91 if (s.isEmpty()) {
continue; }
101 for (
const CCountry &country : (*
this))
103 const QString s = country.getIsoCode();
104 if (s.length() != 2) {
continue; }
107 if (
sorted) { sl.sort(); }
114 for (
const CCountry &country : (*
this))
116 const QString s = country.getIso3Code();
117 if (s.length() != 3) {
continue; }
120 if (
sorted) { sl.sort(); }
127 for (
const QJsonValue &value : array)
bool matchesCountryName(const QString &name) const
Matches country name.
static bool isValidIsoCode(const QString &isoCode)
Valid country iso code.
static CCountry fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
Value object encapsulating a list of countries.
static CCountryList fromDatabaseJson(const QJsonArray &array)
From our database JSON format.
CCountry findFirstByAlias(const QString &alias) const
Find first by alias.
CCountry findBestMatchByCountryName(const QString &candidate) const
Find "best match" by country.
QStringList toIso3List(bool sorted=false) const
All ISO 3 codes.
CCountry findByIsoCode(const QString &isoCode) const
Find by ISO code.
QStringList toIsoNameList(bool sorted=false) const
ISO/name string list.
CCountryList()
Default constructor.
QStringList toNameList(bool sorted=false) const
Name string list.
QStringList toIsoList(bool sorted=false) const
All ISO codes.
QStringList toNameIsoList(bool sorted=false) const
Name/ISO string list.
size_type size() const
Returns number of elements in the sequence.
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
CSequence findBy(Predicate p) const
Return a copy containing only those elements for which a given predicate returns true.
Q_REQUIRED_RESULT CSequence sorted(Predicate p) const
Return a copy sorted by a given comparator predicate.
void push_back(const T &value)
Appends an element at the end of the sequence.
reference front()
Access the first element.
bool isEmpty() const
Synonym for empty.
Free functions in swift::misc.
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.