mirror-chatterino2/src/providers/emoji/Emojis.hpp

68 lines
1.4 KiB
C++
Raw Normal View History

2018-06-05 18:53:49 +02:00
#pragma once
2018-06-26 17:20:03 +02:00
#include "common/Emotemap.hpp"
2018-06-26 15:33:51 +02:00
#include "common/SignalVector.hpp"
2018-06-26 14:09:39 +02:00
#include "util/ConcurrentMap.hpp"
2018-06-05 18:53:49 +02:00
#include <QMap>
#include <QRegularExpression>
#include <map>
namespace chatterino {
struct EmojiData {
// actual byte-representation of the emoji (i.e. \154075\156150 which is :male:)
QString value;
// i.e. 204e-50a2
QString unifiedCode;
QString nonQualifiedCode;
2018-06-05 18:53:49 +02:00
// i.e. thinking
std::vector<QString> shortCodes;
2018-06-05 18:53:49 +02:00
std::set<QString> capabilities;
std::vector<EmojiData> variations;
2018-06-26 17:06:17 +02:00
EmoteData emoteData;
2018-06-05 18:53:49 +02:00
};
2018-06-26 17:06:17 +02:00
using EmojiMap = ConcurrentMap<QString, std::shared_ptr<EmojiData>>;
2018-06-05 18:53:49 +02:00
class Emojis
{
public:
void initialize();
2018-06-05 18:53:49 +02:00
EmojiMap emojis;
std::vector<QString> shortCodes;
2018-06-05 18:53:49 +02:00
void load();
private:
void loadEmojis();
void loadEmojiOne2Capabilities();
void sortEmojis();
void loadEmojiSet();
public:
2018-06-05 18:53:49 +02:00
QString replaceShortCodes(const QString &text);
2018-06-26 17:06:17 +02:00
void parse(std::vector<std::tuple<EmoteData, QString>> &parsedWords, const QString &text);
2018-06-05 18:53:49 +02:00
private:
/// Emojis
QRegularExpression findShortCodesRegex{":([-+\\w]+):"};
// shortCodeToEmoji maps strings like "sunglasses" to its emoji
QMap<QString, std::shared_ptr<EmojiData>> emojiShortCodeToEmoji;
2018-06-05 18:53:49 +02:00
// Maps the first character of the emoji unicode string to a vector of possible emojis
QMap<QChar, QVector<std::shared_ptr<EmojiData>>> emojiFirstByte;
2018-06-05 18:53:49 +02:00
};
} // namespace chatterino