mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Removed old formatting of phone numbers.
This commit is contained in:
parent
6ff0cb853d
commit
963fda69a8
3 changed files with 4 additions and 36 deletions
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text/format_values.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "numbers.h" // phoneNumberParse
|
||||
#include "countries/countries_instance.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QtCore/QLocale>
|
||||
|
@ -371,45 +371,14 @@ QString FormatImageSizeText(const QSize &size) {
|
|||
+ QString::number(size.height());
|
||||
}
|
||||
|
||||
QString FormatPhone(QString phone) {
|
||||
QString FormatPhone(const QString &phone) {
|
||||
if (phone.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
if (phone.at(0) == '0') {
|
||||
return phone;
|
||||
}
|
||||
|
||||
auto number = phone;
|
||||
{
|
||||
const auto *ch = phone.constData();
|
||||
const auto *e = ch + phone.size();
|
||||
const auto regExp = QRegularExpression(u"[^\\d]"_q);
|
||||
for (; ch != e; ++ch) {
|
||||
if (ch->unicode() < '0' || ch->unicode() > '9') {
|
||||
number = phone.replace(regExp, QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto groups = phoneNumberParse(number);
|
||||
if (groups.isEmpty()) {
|
||||
return '+' + number;
|
||||
}
|
||||
|
||||
QString result;
|
||||
result.reserve(number.size() + groups.size() + 1);
|
||||
result.append('+');
|
||||
int32 sum = 0;
|
||||
for (const auto &group : groups) {
|
||||
result.append(number.midRef(sum, group));
|
||||
sum += group;
|
||||
if (sum < number.size()) {
|
||||
result.append(' ');
|
||||
}
|
||||
}
|
||||
if (sum < number.size()) {
|
||||
result.append(number.midRef(sum));
|
||||
}
|
||||
return result;
|
||||
return Countries::Instance().format({ .phone = phone }).formatted;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -23,7 +23,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
|
|||
[[nodiscard]] QString FormatGifAndSizeText(qint64 size);
|
||||
[[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration);
|
||||
[[nodiscard]] QString FormatImageSizeText(const QSize &size);
|
||||
[[nodiscard]] QString FormatPhone(QString phone);
|
||||
[[nodiscard]] QString FormatPhone(const QString &phone);
|
||||
|
||||
struct CurrencyRule {
|
||||
const char *international = "";
|
||||
|
|
|
@ -41,7 +41,6 @@ set(dependent_style_files
|
|||
)
|
||||
|
||||
generate_styles(td_ui ${src_loc} "${style_files}" "${dependent_style_files}")
|
||||
generate_numbers(td_ui ${res_loc}/numbers.txt)
|
||||
|
||||
target_precompile_headers(td_ui PRIVATE ${src_loc}/ui/ui_pch.h)
|
||||
nice_target_sources(td_ui ${src_loc}
|
||||
|
|
Loading…
Add table
Reference in a new issue