Move remove_emoji_modifiers to emoji.h.

This commit is contained in:
levlam 2021-09-21 06:32:34 +03:00
parent 3af0059b94
commit b6bde1e4c5
9 changed files with 40 additions and 34 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -307,31 +307,4 @@ string get_emoji_fingerprint(uint64 num) {
return emojis[static_cast<size_t>((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

View File

@ -35,10 +35,4 @@ int64 get_vector_hash(const vector<uint64> &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

View File

@ -6,6 +6,8 @@
//
#include "td/utils/emoji.h"
#include "td/utils/misc.h"
#include <unordered_set>
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

View File

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