diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-01-21 04:18:17 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-01-21 04:18:17 +0100 |
commit | 79e4e2e6e106c472a79fd91e1e7c8816719914eb (patch) | |
tree | 13f5308e8465e196189948c7e0c2be61d6e6134c /src/Utils.cpp | |
parent | Linkify links before sending (diff) | |
download | nheko-79e4e2e6e106c472a79fd91e1e7c8816719914eb.tar.xz |
Improve emoji escaping
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r-- | src/Utils.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index 5e8e1a16..ab8631f7 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -39,13 +39,23 @@ utils::replaceEmoji(const QString &body) QSettings settings; QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + bool insideFontBlock = true; for (auto &code : utf32_string) { // TODO: Be more precise here. - if (code > 9000) - fmtBody += QString("<font face=\"" + userFontFamily + "\">") + - QString::fromUcs4(&code, 1) + "</font>"; - else - fmtBody += QString::fromUcs4(&code, 1); + if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) || + (code >= 0x1f000 && code <= 0x1f64f) || (code >= 0x1f680 && code <= 0x1f6ff)) { + if (!insideFontBlock) { + fmtBody += QString("<font face=\"" + userFontFamily + "\">"); + insideFontBlock = true; + } + + } else { + if (insideFontBlock) { + fmtBody += "</font>"; + insideFontBlock = false; + } + } + fmtBody += QString::fromUcs4(&code, 1); } return fmtBody; |