diff --git a/td/telegram/DialogAction.cpp b/td/telegram/DialogAction.cpp index 129c97359..64f0ded56 100644 --- a/td/telegram/DialogAction.cpp +++ b/td/telegram/DialogAction.cpp @@ -9,6 +9,7 @@ #include "td/telegram/misc.h" #include "td/telegram/ServerMessageId.h" +#include "td/utils/emoji.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index 13386c6e3..e276b73f4 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -7,9 +7,9 @@ #include "td/telegram/DialogFilter.h" #include "td/telegram/DialogId.h" -#include "td/telegram/misc.h" #include "td/utils/algorithm.h" +#include "td/utils/emoji.h" #include "td/utils/format.h" #include "td/utils/logging.h" diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index eece9216b..0e844447a 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -74,6 +74,7 @@ #include "td/actor/PromiseFuture.h" #include "td/utils/algorithm.h" +#include "td/utils/emoji.h" #include "td/utils/format.h" #include "td/utils/HttpUrl.h" #include "td/utils/logging.h" diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 2e0ebf5e0..cb8a0a103 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -42,6 +42,7 @@ #include "td/actor/SleepActor.h" #include "td/utils/algorithm.h" +#include "td/utils/emoji.h" #include "td/utils/format.h" #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" diff --git a/td/telegram/StickersManager.hpp b/td/telegram/StickersManager.hpp index bf76e9f56..6253ea623 100644 --- a/td/telegram/StickersManager.hpp +++ b/td/telegram/StickersManager.hpp @@ -12,6 +12,7 @@ #include "td/telegram/misc.h" #include "td/telegram/Photo.hpp" +#include "td/utils/emoji.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" diff --git a/td/telegram/misc.cpp b/td/telegram/misc.cpp index 5f5cf8ac5..2886fa0cc 100644 --- a/td/telegram/misc.cpp +++ b/td/telegram/misc.cpp @@ -307,31 +307,4 @@ string get_emoji_fingerprint(uint64 num) { return emojis[static_cast((num & 0x7FFFFFFFFFFFFFFF) % emojis.size())].str(); } -Slice remove_emoji_modifiers(Slice emoji) { - static const Slice modifiers[] = {u8"\uFE0E" /* variation selector-15 */, - u8"\uFE0F" /* variation selector-16 */, - u8"\u200D\u2640" /* zero width joiner + female sign */, - u8"\u200D\u2642" /* zero width joiner + male sign */, - u8"\U0001F3FB" /* emoji modifier fitzpatrick type-1-2 */, - u8"\U0001F3FC" /* emoji modifier fitzpatrick type-3 */, - u8"\U0001F3FD" /* emoji modifier fitzpatrick type-4 */, - u8"\U0001F3FE" /* emoji modifier fitzpatrick type-5 */, - u8"\U0001F3FF" /* emoji modifier fitzpatrick type-6 */}; - bool found = true; - while (found) { - found = false; - for (auto &modifier : modifiers) { - if (ends_with(emoji, modifier) && emoji.size() > modifier.size()) { - emoji.remove_suffix(modifier.size()); - found = true; - } - } - } - return emoji; -} - -void remove_emoji_modifiers_in_place(string &emoji) { - emoji.resize(remove_emoji_modifiers(emoji).size()); -} - } // namespace td diff --git a/td/telegram/misc.h b/td/telegram/misc.h index 8c1ab6740..169c9d1bd 100644 --- a/td/telegram/misc.h +++ b/td/telegram/misc.h @@ -35,10 +35,4 @@ int64 get_vector_hash(const vector &numbers) TD_WARN_UNUSED_RESULT; // returns emoji corresponding to the specified number string get_emoji_fingerprint(uint64 num); -// removes all emoji modifiers -Slice remove_emoji_modifiers(Slice emoji); - -// removes all emoji modifiers in place -void remove_emoji_modifiers_in_place(string &emoji); - } // namespace td diff --git a/tdutils/td/utils/emoji.cpp b/tdutils/td/utils/emoji.cpp index a5b73bcb6..918aff2ff 100644 --- a/tdutils/td/utils/emoji.cpp +++ b/tdutils/td/utils/emoji.cpp @@ -6,6 +6,8 @@ // #include "td/utils/emoji.h" +#include "td/utils/misc.h" + #include namespace td { @@ -837,4 +839,31 @@ bool is_emoji(Slice str) { return emojis.count(str) != 0; } +Slice remove_emoji_modifiers(Slice emoji) { + static const Slice modifiers[] = {u8"\uFE0E" /* variation selector-15 */, + u8"\uFE0F" /* variation selector-16 */, + u8"\u200D\u2640" /* zero width joiner + female sign */, + u8"\u200D\u2642" /* zero width joiner + male sign */, + u8"\U0001F3FB" /* emoji modifier fitzpatrick type-1-2 */, + u8"\U0001F3FC" /* emoji modifier fitzpatrick type-3 */, + u8"\U0001F3FD" /* emoji modifier fitzpatrick type-4 */, + u8"\U0001F3FE" /* emoji modifier fitzpatrick type-5 */, + u8"\U0001F3FF" /* emoji modifier fitzpatrick type-6 */}; + bool found = true; + while (found) { + found = false; + for (auto &modifier : modifiers) { + if (ends_with(emoji, modifier) && emoji.size() > modifier.size()) { + emoji.remove_suffix(modifier.size()); + found = true; + } + } + } + return emoji; +} + +void remove_emoji_modifiers_in_place(string &emoji) { + emoji.resize(remove_emoji_modifiers(emoji).size()); +} + } // namespace td diff --git a/tdutils/td/utils/emoji.h b/tdutils/td/utils/emoji.h index 0851e8481..4a0020187 100644 --- a/tdutils/td/utils/emoji.h +++ b/tdutils/td/utils/emoji.h @@ -14,4 +14,10 @@ namespace td { // checks whether the string is an emoji; variation selectors are ignored bool is_emoji(Slice str); +// removes all emoji modifiers from the end of the string +Slice remove_emoji_modifiers(Slice emoji); + +// removes all emoji modifiers from the end of the string in place +void remove_emoji_modifiers_in_place(string &emoji); + } // namespace td