2018-06-05 18:53:49 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/ConcurrentMap.hpp"
|
2018-06-05 18:53:49 +02:00
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
#include <QRegularExpression>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <boost/variant.hpp>
|
2018-06-05 18:53:49 +02:00
|
|
|
#include <map>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2018-06-05 18:53:49 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
struct Emote;
|
|
|
|
using EmotePtr = std::shared_ptr<const Emote>;
|
|
|
|
|
2018-06-05 18:53:49 +02:00
|
|
|
struct EmojiData {
|
2018-08-06 21:17:03 +02:00
|
|
|
// actual byte-representation of the emoji (i.e. \154075\156150 which is
|
|
|
|
// :male:)
|
2018-06-05 18:53:49 +02:00
|
|
|
QString value;
|
|
|
|
|
2018-06-06 01:29:43 +02:00
|
|
|
// i.e. 204e-50a2
|
|
|
|
QString unifiedCode;
|
|
|
|
QString nonQualifiedCode;
|
2018-06-05 18:53:49 +02:00
|
|
|
|
|
|
|
// i.e. thinking
|
2018-06-22 22:42:53 +02:00
|
|
|
std::vector<QString> shortCodes;
|
2018-06-05 18:53:49 +02:00
|
|
|
|
2018-06-06 01:29:43 +02:00
|
|
|
std::set<QString> capabilities;
|
|
|
|
|
|
|
|
std::vector<EmojiData> variations;
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
EmotePtr emote;
|
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:
|
2018-06-06 01:29:43 +02:00
|
|
|
void initialize();
|
2018-07-06 19:23:47 +02:00
|
|
|
void load();
|
2018-08-02 14:23:27 +02:00
|
|
|
std::vector<boost::variant<EmotePtr, QString>> parse(const QString &text);
|
2018-06-06 01:29:43 +02:00
|
|
|
|
2018-06-05 18:53:49 +02:00
|
|
|
EmojiMap emojis;
|
2018-06-07 13:10:07 +02:00
|
|
|
std::vector<QString> shortCodes;
|
2018-07-06 19:23:47 +02:00
|
|
|
QString replaceShortCodes(const QString &text);
|
2018-06-06 01:29:43 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void loadEmojis();
|
2018-06-06 11:43:02 +02:00
|
|
|
void sortEmojis();
|
|
|
|
void loadEmojiSet();
|
2018-06-06 01:29:43 +02:00
|
|
|
|
2018-06-05 18:53:49 +02:00
|
|
|
/// Emojis
|
2018-07-06 19:23:47 +02:00
|
|
|
QRegularExpression findShortCodesRegex_{":([-+\\w]+):"};
|
2018-06-05 18:53:49 +02:00
|
|
|
|
|
|
|
// shortCodeToEmoji maps strings like "sunglasses" to its emoji
|
2018-07-06 19:23:47 +02:00
|
|
|
QMap<QString, std::shared_ptr<EmojiData>> emojiShortCodeToEmoji_;
|
2018-06-05 18:53:49 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// Maps the first character of the emoji unicode string to a vector of
|
|
|
|
// possible emojis
|
2018-07-06 19:23:47 +02:00
|
|
|
QMap<QChar, QVector<std::shared_ptr<EmojiData>>> emojiFirstByte_;
|
2018-06-05 18:53:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|