mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Split up emoji parsing in more steps
Re-enable emoji skin variations
This commit is contained in:
parent
3eab6150cf
commit
f542a5b999
|
@ -84,17 +84,20 @@ void Emojis::load()
|
||||||
this->loadEmojis();
|
this->loadEmojis();
|
||||||
|
|
||||||
this->loadEmojiOne2Capabilities();
|
this->loadEmojiOne2Capabilities();
|
||||||
|
|
||||||
|
this->sortEmojis();
|
||||||
|
|
||||||
|
this->loadEmojiSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emojis::loadEmojis()
|
void Emojis::loadEmojis()
|
||||||
{
|
{
|
||||||
static std::map<std::string, QString> toneNames{
|
std::map<std::string, QString> toneNames;
|
||||||
{"1F3FB", "tone1"}, //
|
toneNames["1F3FB"] = "tone1";
|
||||||
{"1F3FC", "tone2"}, //
|
toneNames["1F3FC"] = "tone2";
|
||||||
{"1F3FD", "tone3"}, //
|
toneNames["1F3FD"] = "tone3";
|
||||||
{"1F3FE", "tone4"}, //
|
toneNames["1F3FE"] = "tone4";
|
||||||
{"1F3FF", "tone5"}, //
|
toneNames["1F3FF"] = "tone5";
|
||||||
};
|
|
||||||
|
|
||||||
QFile file(":/emoji.json");
|
QFile file(":/emoji.json");
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
|
@ -120,7 +123,7 @@ void Emojis::loadEmojis()
|
||||||
|
|
||||||
this->emojis.insert(emojiData->unifiedCode, emojiData);
|
this->emojis.insert(emojiData->unifiedCode, emojiData);
|
||||||
|
|
||||||
if (unparsedEmoji.HasMember("skin_variations") && false) {
|
if (unparsedEmoji.HasMember("skin_variations")) {
|
||||||
for (const auto &skinVariation : unparsedEmoji["skin_variations"].GetObject()) {
|
for (const auto &skinVariation : unparsedEmoji["skin_variations"].GetObject()) {
|
||||||
std::string tone = skinVariation.name.GetString();
|
std::string tone = skinVariation.name.GetString();
|
||||||
const auto &variation = skinVariation.value;
|
const auto &variation = skinVariation.value;
|
||||||
|
@ -146,7 +149,43 @@ void Emojis::loadEmojis()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emojis::loadEmojiOne2Capabilities()
|
||||||
|
{
|
||||||
|
QFile file(":/emojidata.txt");
|
||||||
|
file.open(QFile::ReadOnly);
|
||||||
|
QTextStream in(&file);
|
||||||
|
|
||||||
|
uint unicodeBytes[4];
|
||||||
|
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
// Line example: sunglasses 1f60e
|
||||||
|
QString line = in.readLine();
|
||||||
|
|
||||||
|
if (line.at(0) == '#') {
|
||||||
|
// Ignore lines starting with # (comments)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList parts = line.split(' ');
|
||||||
|
if (parts.length() < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString shortCode = parts[0];
|
||||||
|
|
||||||
|
auto emojiIt = this->emojiShortCodeToEmoji.find(shortCode);
|
||||||
|
if (emojiIt != this->emojiShortCodeToEmoji.end()) {
|
||||||
|
std::shared_ptr<EmojiData> emoji = *emojiIt;
|
||||||
|
emoji->capabilities.insert("EmojiOne 2");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emojis::sortEmojis()
|
||||||
|
{
|
||||||
for (auto &p : this->emojiFirstByte) {
|
for (auto &p : this->emojiFirstByte) {
|
||||||
std::stable_sort(p.begin(), p.end(), [](const auto &lhs, const auto &rhs) {
|
std::stable_sort(p.begin(), p.end(), [](const auto &lhs, const auto &rhs) {
|
||||||
return lhs->value.length() > rhs->value.length();
|
return lhs->value.length() > rhs->value.length();
|
||||||
|
@ -156,10 +195,14 @@ void Emojis::loadEmojis()
|
||||||
auto &p = this->shortCodes;
|
auto &p = this->shortCodes;
|
||||||
std::stable_sort(p.begin(), p.end(),
|
std::stable_sort(p.begin(), p.end(),
|
||||||
[](const auto &lhs, const auto &rhs) { return lhs < rhs; });
|
[](const auto &lhs, const auto &rhs) { return lhs < rhs; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emojis::loadEmojiSet()
|
||||||
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
app->settings->emojiSet.connect([=](const auto &emojiSet, auto) {
|
app->settings->emojiSet.connect([=](const auto &emojiSet, auto) {
|
||||||
|
debug::Log("Using emoji set {}", emojiSet);
|
||||||
this->emojis.each([=](const auto &name, std::shared_ptr<EmojiData> &emoji) {
|
this->emojis.each([=](const auto &name, std::shared_ptr<EmojiData> &emoji) {
|
||||||
QString emojiSetToUse = emojiSet;
|
QString emojiSetToUse = emojiSet;
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -197,39 +240,6 @@ void Emojis::loadEmojis()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emojis::loadEmojiOne2Capabilities()
|
|
||||||
{
|
|
||||||
QFile file(":/emojidata.txt");
|
|
||||||
file.open(QFile::ReadOnly);
|
|
||||||
QTextStream in(&file);
|
|
||||||
|
|
||||||
uint unicodeBytes[4];
|
|
||||||
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
// Line example: sunglasses 1f60e
|
|
||||||
QString line = in.readLine();
|
|
||||||
|
|
||||||
if (line.at(0) == '#') {
|
|
||||||
// Ignore lines starting with # (comments)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList parts = line.split(' ');
|
|
||||||
if (parts.length() < 2) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString shortCode = parts[0];
|
|
||||||
|
|
||||||
auto emojiIt = this->emojiShortCodeToEmoji.find(shortCode);
|
|
||||||
if (emojiIt != this->emojiShortCodeToEmoji.end()) {
|
|
||||||
std::shared_ptr<EmojiData> emoji = *emojiIt;
|
|
||||||
emoji->capabilities.insert("EmojiOne 2");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Emojis::parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
|
void Emojis::parse(std::vector<std::tuple<util::EmoteData, QString>> &parsedWords,
|
||||||
const QString &text)
|
const QString &text)
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
private:
|
private:
|
||||||
void loadEmojis();
|
void loadEmojis();
|
||||||
void loadEmojiOne2Capabilities();
|
void loadEmojiOne2Capabilities();
|
||||||
|
void sortEmojis();
|
||||||
|
void loadEmojiSet();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString replaceShortCodes(const QString &text);
|
QString replaceShortCodes(const QString &text);
|
||||||
|
|
Loading…
Reference in a new issue