Don't remove emoji selectors in search_stickers.
This commit is contained in:
parent
833c7c30da
commit
587a882270
@ -4750,7 +4750,7 @@ void StickersManager::search_stickers(StickerType sticker_type, string emoji, in
|
||||
limit = MAX_FOUND_STICKERS;
|
||||
}
|
||||
|
||||
remove_emoji_modifiers_in_place(emoji);
|
||||
remove_emoji_modifiers_in_place(emoji, false);
|
||||
if (emoji.empty() || sticker_type == StickerType::Mask) {
|
||||
return promise.set_value(get_stickers_object({}));
|
||||
}
|
||||
|
@ -327,13 +327,13 @@ Slice remove_fitzpatrick_modifier(Slice emoji) {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
string remove_emoji_modifiers(Slice emoji) {
|
||||
string remove_emoji_modifiers(Slice emoji, bool remove_selectors) {
|
||||
string result = emoji.str();
|
||||
remove_emoji_modifiers_in_place(result);
|
||||
remove_emoji_modifiers_in_place(result, remove_selectors);
|
||||
return result;
|
||||
}
|
||||
|
||||
void remove_emoji_modifiers_in_place(string &emoji) {
|
||||
void remove_emoji_modifiers_in_place(string &emoji, bool remove_selectors) {
|
||||
static const Slice modifiers[] = {u8"\uFE0F" /* variation selector-16 */,
|
||||
u8"\u200D\u2640" /* zero width joiner + female sign */,
|
||||
u8"\u200D\u2642" /* zero width joiner + male sign */,
|
||||
@ -342,13 +342,14 @@ void remove_emoji_modifiers_in_place(string &emoji) {
|
||||
u8"\U0001F3FD" /* emoji modifier fitzpatrick type-4 */,
|
||||
u8"\U0001F3FE" /* emoji modifier fitzpatrick type-5 */,
|
||||
u8"\U0001F3FF" /* emoji modifier fitzpatrick type-6 */};
|
||||
const size_t start_index = remove_selectors ? 0 : 1;
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < emoji.size();) {
|
||||
bool is_found = false;
|
||||
for (auto &modifier : modifiers) {
|
||||
auto length = modifier.size();
|
||||
if (i + length <= emoji.size() && Slice(&emoji[i], length) == modifier) {
|
||||
// skip modifier
|
||||
for (size_t k = start_index; k < sizeof(modifiers) / sizeof(*modifiers); k++) {
|
||||
auto length = modifiers[k].size();
|
||||
if (i + length <= emoji.size() && Slice(&emoji[i], length) == modifiers[k]) {
|
||||
// skip the modifier
|
||||
i += length;
|
||||
is_found = true;
|
||||
break;
|
||||
|
@ -21,10 +21,10 @@ int get_fitzpatrick_modifier(Slice emoji);
|
||||
Slice remove_fitzpatrick_modifier(Slice emoji);
|
||||
|
||||
// removes all emoji modifiers from the string
|
||||
string remove_emoji_modifiers(Slice emoji);
|
||||
string remove_emoji_modifiers(Slice emoji, bool remove_selectors = true);
|
||||
|
||||
// removes all emoji modifiers from the string in-place
|
||||
void remove_emoji_modifiers_in_place(string &emoji);
|
||||
void remove_emoji_modifiers_in_place(string &emoji, bool remove_selectors = true);
|
||||
|
||||
// removes all emoji selectors from the string if it is an emoji
|
||||
string remove_emoji_selectors(Slice emoji);
|
||||
|
@ -70,17 +70,18 @@ TEST(Emoji, get_fitzpatrick_modifier) {
|
||||
test_get_fitzpatrick_modifier("π§βπ", 0);
|
||||
}
|
||||
|
||||
static void test_remove_emoji_modifiers(td::string emoji, const td::string &result) {
|
||||
ASSERT_STREQ(result, td::remove_emoji_modifiers(emoji));
|
||||
td::remove_emoji_modifiers_in_place(emoji);
|
||||
static void test_remove_emoji_modifiers(td::string emoji, const td::string &result, bool remove_selectors = true) {
|
||||
ASSERT_STREQ(result, td::remove_emoji_modifiers(emoji, remove_selectors));
|
||||
td::remove_emoji_modifiers_in_place(emoji, remove_selectors);
|
||||
ASSERT_STREQ(result, emoji);
|
||||
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji));
|
||||
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji, remove_selectors));
|
||||
}
|
||||
|
||||
TEST(Emoji, remove_emoji_modifiers) {
|
||||
test_remove_emoji_modifiers("", "");
|
||||
test_remove_emoji_modifiers("π©πΌββ€βπβπ©π»", "π©ββ€βπβπ©");
|
||||
test_remove_emoji_modifiers("π©πΌββ€οΈβπβπ©π»", "π©ββ€βπβπ©");
|
||||
test_remove_emoji_modifiers("π©πΌββ€οΈβπβπ©π»", "π©ββ€οΈβπβπ©", false);
|
||||
test_remove_emoji_modifiers("ππ»", "π");
|
||||
test_remove_emoji_modifiers("ππΌ", "π");
|
||||
test_remove_emoji_modifiers("ππ½", "π");
|
||||
|
Loadingβ¦
Reference in New Issue
Block a user