Replaced const char ptr with QString in country structs.

This commit is contained in:
23rd 2021-08-26 19:01:31 +03:00
parent c593f43629
commit 3e80c04da7
4 changed files with 12 additions and 16 deletions

View file

@ -297,18 +297,14 @@ QString CountriesInstance::validPhoneCode(QString fullCode) {
QString CountriesInstance::countryNameByISO2(const QString &iso) { QString CountriesInstance::countryNameByISO2(const QString &iso) {
const auto &listByISO2 = byISO2(); const auto &listByISO2 = byISO2();
const auto i = listByISO2.constFind(iso); const auto i = listByISO2.constFind(iso);
return (i != listByISO2.cend()) return (i != listByISO2.cend()) ? (*i)->name : QString();
? QString::fromUtf8((*i)->name)
: QString();
} }
QString CountriesInstance::countryISO2ByPhone(const QString &phone) { QString CountriesInstance::countryISO2ByPhone(const QString &phone) {
const auto &listByCode = byCode(); const auto &listByCode = byCode();
const auto code = validPhoneCode(phone); const auto code = validPhoneCode(phone);
const auto i = listByCode.find(code); const auto i = listByCode.find(code);
return (i != listByCode.cend()) return (i != listByCode.cend()) ? (*i)->iso2 : QString();
? QString::fromUtf8((*i)->iso2)
: QString();
} }
CountriesInstance &Instance() { CountriesInstance &Instance() {

View file

@ -11,10 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Countries { namespace Countries {
struct Info { struct Info {
const char *name = nullptr; QString name;
const char *iso2 = nullptr; QString iso2;
const char *code = nullptr; QString code;
const char *alternativeName = nullptr; QString alternativeName;
}; };
class CountriesInstance final { class CountriesInstance final {

View file

@ -195,10 +195,10 @@ CountrySelectBox::Inner::Inner(
} }
auto index = 0; auto index = 0;
for (const auto info : _list) { for (const auto info : _list) {
auto full = QString::fromUtf8(info->name) auto full = info->name
+ ' ' + ' '
+ (info->alternativeName + (!info->alternativeName.isEmpty()
? QString::fromUtf8(info->alternativeName) ? info->alternativeName
: QString()); : QString());
const auto namesList = std::move(full).toLower().split( const auto namesList = std::move(full).toLower().split(
QRegularExpression("[\\s\\-]"), QRegularExpression("[\\s\\-]"),
@ -259,7 +259,7 @@ void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
auto code = QString("+") + list[i]->code; auto code = QString("+") + list[i]->code;
auto codeWidth = st::countryRowCodeFont->width(code); auto codeWidth = st::countryRowCodeFont->width(code);
auto name = QString::fromUtf8(list[i]->name); auto name = list[i]->name;
auto nameWidth = st::countryRowNameFont->width(name); auto nameWidth = st::countryRowNameFont->width(name);
auto availWidth = width() - st::countryRowPadding.left() - st::countryRowPadding.right() - codeWidth - st::boxScroll.width; auto availWidth = width() - st::countryRowPadding.left() - st::countryRowPadding.right() - codeWidth - st::boxScroll.width;
if (nameWidth > availWidth) { if (nameWidth > availWidth) {

View file

@ -119,7 +119,7 @@ void CountryInput::onChooseCode(const QString &code) {
if (i != byCode.cend()) { if (i != byCode.cend()) {
const auto info = *i; const auto info = *i;
_chosenIso = LastValidISO = info->iso2; _chosenIso = LastValidISO = info->iso2;
setText(QString::fromUtf8(info->name)); setText(info->name);
} else { } else {
setText(tr::lng_bad_country_code(tr::now)); setText(tr::lng_bad_country_code(tr::now));
} }
@ -139,7 +139,7 @@ bool CountryInput::chooseCountry(const QString &iso) {
_chosenIso = QString(); _chosenIso = QString();
if (info) { if (info) {
_chosenIso = LastValidISO = info->iso2; _chosenIso = LastValidISO = info->iso2;
setText(QString::fromUtf8(info->name)); setText(info->name);
codeChanged(info->code); codeChanged(info->code);
update(); update();
return true; return true;