mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fix emote replacement to render emotes correctly (#768)
* fix emote replacement rendering from inside the caught string * \b -> \\b, while -> if i actually wanted the regex identifier \b and you need to escape the escape character \ an error in judgement made me use while, as if the api was meant to be "consume"-like interface that boost regex uses Fixes #26
This commit is contained in:
parent
bb6c2b6135
commit
2d3ce59b8b
1 changed files with 20 additions and 14 deletions
|
@ -260,13 +260,16 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
log("v nullptr {}", std::get<2>(tup).string);
|
||||
continue;
|
||||
}
|
||||
int index = 0;
|
||||
QString emote = " " + std::get<2>(tup).string + " ";
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) !=
|
||||
-1) {
|
||||
std::get<0>(tup) = from + index + 1;
|
||||
index += emote.size() - 1;
|
||||
twitchEmotes.push_back(tup);
|
||||
QRegularExpression emoteregex(
|
||||
"\\b" + std::get<2>(tup).string + "\\b",
|
||||
QRegularExpression::UseUnicodePropertiesOption);
|
||||
auto match = emoteregex.match(midExtendedRef);
|
||||
if (match.hasMatch()) {
|
||||
int last = match.lastCapturedIndex();
|
||||
for (int i = 0; i <= last; ++i) {
|
||||
std::get<0>(tup) = from + match.capturedStart();
|
||||
twitchEmotes.push_back(std::move(tup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,13 +317,16 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
log("v nullptr {}", std::get<2>(tup).string);
|
||||
continue;
|
||||
}
|
||||
int index = 0;
|
||||
QString emote = " " + std::get<2>(tup).string + " ";
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) !=
|
||||
-1) {
|
||||
std::get<0>(tup) = from + index + 1;
|
||||
index += emote.size() - 1;
|
||||
twitchEmotes.push_back(tup);
|
||||
QRegularExpression emoteregex(
|
||||
"\\b" + std::get<2>(tup).string + "\\b",
|
||||
QRegularExpression::UseUnicodePropertiesOption);
|
||||
auto match = emoteregex.match(midExtendedRef);
|
||||
if (match.hasMatch()) {
|
||||
int last = match.lastCapturedIndex();
|
||||
for (int i = 0; i <= last; ++i) {
|
||||
std::get<0>(tup) = from + match.capturedStart();
|
||||
twitchEmotes.push_back(std::move(tup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue