Simplified some names in countries.

This commit is contained in:
23rd 2021-08-26 17:53:59 +03:00
parent df02bbb0a3
commit a230e83778
6 changed files with 28 additions and 28 deletions

View file

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Countries {
namespace {
const std::array<CountryInfo, 231> List = { {
const std::array<Info, 231> FallbackList = { {
{ "Afghanistan", "AF", "93" },
{ "Albania", "AL", "355" },
{ "Algeria", "DZ", "213" },
@ -244,29 +244,29 @@ const std::array<CountryInfo, 231> List = { {
{ "Zimbabwe", "ZW", "263" },
} };
QHash<QString, const CountryInfo *> ByCode;
QHash<QString, const CountryInfo *> ByISO2;
QHash<QString, const Info *> ByCode;
QHash<QString, const Info *> ByISO2;
} // namespace
const std::array<CountryInfo, 231> &Countries() {
return List;
const std::array<Info, 231> &List() {
return FallbackList;
}
const QHash<QString, const CountryInfo *> &CountriesByCode() {
const QHash<QString, const Info *> &InfoByCode() {
if (ByCode.isEmpty()) {
ByCode.reserve(List.size());
for (const auto &entry : List) {
ByCode.reserve(FallbackList.size());
for (const auto &entry : FallbackList) {
ByCode.insert(entry.code, &entry);
}
}
return ByCode;
}
const QHash<QString, const CountryInfo *> &CountriesByISO2() {
const QHash<QString, const Info *> &InfoByISO2() {
if (ByISO2.isEmpty()) {
ByISO2.reserve(List.size());
for (const auto &entry : List) {
ByISO2.reserve(FallbackList.size());
for (const auto &entry : FallbackList) {
ByISO2.insert(entry.iso2, &entry);
}
}
@ -274,7 +274,7 @@ const QHash<QString, const CountryInfo *> &CountriesByISO2() {
}
QString ValidPhoneCode(QString fullCode) {
const auto &byCode = CountriesByCode();
const auto &byCode = InfoByCode();
while (fullCode.length()) {
const auto i = byCode.constFind(fullCode);
if (i != byCode.cend()) {
@ -286,13 +286,13 @@ QString ValidPhoneCode(QString fullCode) {
}
QString CountryNameByISO2(const QString &iso) {
const auto &byISO2 = CountriesByISO2();
const auto &byISO2 = InfoByISO2();
const auto i = byISO2.constFind(iso);
return (i != byISO2.cend()) ? QString::fromUtf8((*i)->name) : QString();
}
QString CountryISO2ByPhone(const QString &phone) {
const auto &byCode = CountriesByCode();
const auto &byCode = InfoByCode();
const auto code = ValidPhoneCode(phone);
const auto i = byCode.find(code);
return (i != byCode.cend()) ? QString::fromUtf8((*i)->iso2) : QString();

View file

@ -10,17 +10,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Countries {
struct CountryInfo {
struct Info {
const char *name = nullptr;
const char *iso2 = nullptr;
const char *code = nullptr;
const char *alternativeName = nullptr;
};
[[nodiscard]] const std::array<CountryInfo, 231> &Countries();
[[nodiscard]] const std::array<Info, 231> &List();
[[nodiscard]] const QHash<QString, const CountryInfo *> &CountriesByCode();
[[nodiscard]] const QHash<QString, const CountryInfo *> &CountriesByISO2();
[[nodiscard]] const QHash<QString, const Info *> &InfoByCode();
[[nodiscard]] const QHash<QString, const Info *> &InfoByISO2();
[[nodiscard]] QString ValidPhoneCode(QString fullCode);
[[nodiscard]] QString CountryNameByISO2(const QString &iso);

View file

@ -64,7 +64,7 @@ private:
void updateSelectedRow();
void updateRow(int index);
void setPressed(int pressed);
const std::vector<not_null<const Countries::CountryInfo*>> &current() const;
const std::vector<not_null<const Countries::Info*>> &current() const;
Type _type = Type::Phones;
int _rowHeight = 0;
@ -76,8 +76,8 @@ private:
std::vector<std::unique_ptr<RippleAnimation>> _ripples;
std::vector<not_null<const Countries::CountryInfo*>> _list;
std::vector<not_null<const Countries::CountryInfo*>> _filtered;
std::vector<not_null<const Countries::Info*>> _list;
std::vector<not_null<const Countries::Info*>> _filtered;
base::flat_map<QChar, std::vector<int>> _byLetter;
std::vector<std::vector<QString>> _namesList;
@ -174,7 +174,7 @@ CountrySelectBox::Inner::Inner(
, _rowHeight(st::countryRowHeight) {
setAttribute(Qt::WA_OpaquePaintEvent);
const auto &byISO2 = Countries::CountriesByISO2();
const auto &byISO2 = Countries::InfoByISO2();
if (byISO2.contains(iso)) {
LastValidISO = iso;
@ -188,7 +188,7 @@ CountrySelectBox::Inner::Inner(
if (lastValid) {
_list.emplace_back(lastValid);
}
for (const auto &entry : Countries::Countries()) {
for (const auto &entry : Countries::List()) {
if (&entry != lastValid) {
_list.emplace_back(&entry);
}
@ -424,7 +424,7 @@ void CountrySelectBox::Inner::updateSelected(QPoint localPos) {
}
auto CountrySelectBox::Inner::current() const
-> const std::vector<not_null<const Countries::CountryInfo*>> & {
-> const std::vector<not_null<const Countries::Info*>> & {
return _filter.isEmpty() ? _list : _filtered;
}

View file

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_widgets.h"
namespace Countries {
struct CountryInfo;
struct Info;
} // namespace Countries
namespace Ui {

View file

@ -114,7 +114,7 @@ void CountryInput::onChooseCode(const QString &code) {
Ui::hideLayer();
_chosenIso = QString();
if (code.length()) {
const auto &byCode = Countries::CountriesByCode();
const auto &byCode = Countries::InfoByCode();
const auto i = byCode.constFind(code);
if (i != byCode.cend()) {
const auto info = *i;
@ -132,7 +132,7 @@ void CountryInput::onChooseCode(const QString &code) {
bool CountryInput::chooseCountry(const QString &iso) {
Ui::hideLayer();
const auto &byISO2 = Countries::CountriesByISO2();
const auto &byISO2 = Countries::InfoByISO2();
const auto i = byISO2.constFind(iso);
const auto info = (i != byISO2.cend()) ? (*i) : nullptr;

View file

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_widgets.h"
namespace Data {
struct CountryInfo;
struct Info;
} // namespace Data
namespace Ui {