Add clean_phone_number.

This commit is contained in:
levlam 2022-02-18 16:57:08 +03:00
parent ad22bf1174
commit 0939ad3db3
3 changed files with 10 additions and 2 deletions

View File

@ -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<td_api::object_ptr<td_api::phoneNumberInfo>> &&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<td_api::phoneNumberInfo>(nullptr, string(), string()));
}
@ -222,7 +223,7 @@ void CountryInfoManager::do_get_phone_number_info(string phone_number_prefix, st
td_api::object_ptr<td_api::phoneNumberInfo> 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<td_api::phoneNumberInfo>(nullptr, string(), string());
}

View File

@ -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();

View File

@ -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);