diff --git a/td/telegram/CountryInfoManager.cpp b/td/telegram/CountryInfoManager.cpp index 09423ca5f..36ebe8ded 100644 --- a/td/telegram/CountryInfoManager.cpp +++ b/td/telegram/CountryInfoManager.cpp @@ -8,6 +8,7 @@ #include "td/telegram/Global.h" #include "td/telegram/LanguagePackManager.h" +#include "td/telegram/misc.h" #include "td/telegram/Td.h" #include "td/telegram/telegram_api.h" @@ -179,7 +180,7 @@ void CountryInfoManager::do_get_countries(string language_code, bool is_recursiv void CountryInfoManager::get_phone_number_info(string phone_number_prefix, Promise> &&promise) { - td::remove_if(phone_number_prefix, [](char c) { return c < '0' || c > '9'; }); + clean_phone_number(phone_number_prefix); if (phone_number_prefix.empty()) { return promise.set_value(td_api::make_object(nullptr, string(), string())); } @@ -222,7 +223,7 @@ void CountryInfoManager::do_get_phone_number_info(string phone_number_prefix, st td_api::object_ptr CountryInfoManager::get_phone_number_info_sync(const string &language_code, string phone_number_prefix) { - td::remove_if(phone_number_prefix, [](char c) { return !is_digit(c); }); + clean_phone_number(phone_number_prefix); if (phone_number_prefix.empty()) { return td_api::make_object(nullptr, string(), string()); } diff --git a/td/telegram/misc.cpp b/td/telegram/misc.cpp index 685bafdd3..b817a93b6 100644 --- a/td/telegram/misc.cpp +++ b/td/telegram/misc.cpp @@ -51,6 +51,10 @@ string clean_username(string str) { return trim(str); } +void clean_phone_number(string &phone_number) { + td::remove_if(phone_number, [](char c) { return !is_digit(c); }); +} + void replace_offending_characters(string &str) { // "(\xe2\x80\x8f|\xe2\x80\x8e){N}(\xe2\x80\x8f|\xe2\x80\x8e)" -> "(\xe2\x80\x8c){N}$2" auto s = MutableSlice(str).ubegin(); diff --git a/td/telegram/misc.h b/td/telegram/misc.h index bce97b00d..f9b6de664 100644 --- a/td/telegram/misc.h +++ b/td/telegram/misc.h @@ -16,6 +16,9 @@ string clean_name(string str, size_t max_length) TD_WARN_UNUSED_RESULT; // prepares username/stickername for search string clean_username(string str) TD_WARN_UNUSED_RESULT; +// prepares phone number for search +void clean_phone_number(string &phone_number); + // replaces some offending characters without changing string length void replace_offending_characters(string &str);