Simplify adding new entities.
GitOrigin-RevId: 9595a284ae710299161bab639df10f49d49cb386
This commit is contained in:
parent
824c861e7a
commit
bde94f0940
@ -1206,40 +1206,22 @@ vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool onl
|
|||||||
vector<MessageEntity> entities;
|
vector<MessageEntity> entities;
|
||||||
|
|
||||||
if (!only_urls) {
|
if (!only_urls) {
|
||||||
auto mentions = find_mentions(text);
|
auto add_entities = [&entities, &text](MessageEntity::Type type, vector<Slice> (*find_entities)(Slice)) mutable {
|
||||||
for (auto &mention : mentions) {
|
auto new_entities = find_entities(text);
|
||||||
entities.emplace_back(MessageEntity::Type::Mention, narrow_cast<int32>(mention.begin() - text.begin()),
|
for (auto &entity : new_entities) {
|
||||||
narrow_cast<int32>(mention.size()));
|
auto offset = narrow_cast<int32>(entity.begin() - text.begin());
|
||||||
}
|
auto length = narrow_cast<int32>(entity.size());
|
||||||
|
entities.emplace_back(type, offset, length);
|
||||||
if (!skip_bot_commands) {
|
|
||||||
auto bot_commands = find_bot_commands(text);
|
|
||||||
for (auto &bot_command : bot_commands) {
|
|
||||||
entities.emplace_back(MessageEntity::Type::BotCommand, narrow_cast<int32>(bot_command.begin() - text.begin()),
|
|
||||||
narrow_cast<int32>(bot_command.size()));
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
add_entities(MessageEntity::Type::Mention, find_mentions);
|
||||||
|
if (!skip_bot_commands) {
|
||||||
|
add_entities(MessageEntity::Type::BotCommand, find_bot_commands);
|
||||||
}
|
}
|
||||||
|
add_entities(MessageEntity::Type::Hashtag, find_hashtags);
|
||||||
auto hashtags = find_hashtags(text);
|
add_entities(MessageEntity::Type::Cashtag, find_cashtags);
|
||||||
for (auto &hashtag : hashtags) {
|
|
||||||
entities.emplace_back(MessageEntity::Type::Hashtag, narrow_cast<int32>(hashtag.begin() - text.begin()),
|
|
||||||
narrow_cast<int32>(hashtag.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto cashtags = find_cashtags(text);
|
|
||||||
for (auto &cashtag : cashtags) {
|
|
||||||
entities.emplace_back(MessageEntity::Type::Cashtag, narrow_cast<int32>(cashtag.begin() - text.begin()),
|
|
||||||
narrow_cast<int32>(cashtag.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO find_phone_numbers
|
// TODO find_phone_numbers
|
||||||
|
add_entities(MessageEntity::Type::BankCardNumber, find_bank_card_numbers);
|
||||||
auto bank_card_numbers = find_bank_card_numbers(text);
|
|
||||||
for (auto &bank_card_number : bank_card_numbers) {
|
|
||||||
entities.emplace_back(MessageEntity::Type::BankCardNumber,
|
|
||||||
narrow_cast<int32>(bank_card_number.begin() - text.begin()),
|
|
||||||
narrow_cast<int32>(bank_card_number.size()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto urls = find_urls(text);
|
auto urls = find_urls(text);
|
||||||
|
Reference in New Issue
Block a user