refactor: move zero width replacement to a function (#5594)

This commit is contained in:
nerix
2024-09-28 14:49:26 +02:00
committed by GitHub
parent e149be3820
commit d0bcf35fdc
7 changed files with 89 additions and 46 deletions
+18
View File
@@ -7,6 +7,18 @@
#include <QRegularExpression>
#include <QUuid>
namespace {
const QString ZERO_WIDTH_JOINER = QStringLiteral("\u200D");
// Note: \U requires /utf-8 for MSVC
// See https://mm2pl.github.io/emoji_rfc.pdf
const QRegularExpression ESCAPE_TAG_REGEX(
QStringLiteral("(?<!\U000E0002)\U000E0002"),
QRegularExpression::UseUnicodePropertiesOption);
} // namespace
namespace chatterino {
namespace helpers::detail {
@@ -283,4 +295,10 @@ bool compareEmoteStrings(const QString &a, const QString &b)
return k < 0;
}
QString unescapeZeroWidthJoiner(QString escaped)
{
escaped.replace(ESCAPE_TAG_REGEX, ZERO_WIDTH_JOINER);
return escaped;
}
} // namespace chatterino
+7
View File
@@ -182,4 +182,11 @@ constexpr std::optional<std::decay_t<T>> makeConditionedOptional(bool condition,
return std::nullopt;
}
/// @brief Unescapes zero width joiners (ZWJ; U+200D) from Twitch messages
///
/// Older Chatterino versions escape ZWJ with an ESCAPE TAG (U+E0002), following
/// https://mm2pl.github.io/emoji_rfc.pdf. This function unescapes all tags with
/// a ZWJ. See also: https://github.com/Chatterino/chatterino2/issues/3384.
QString unescapeZeroWidthJoiner(QString escaped);
} // namespace chatterino