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:
hemirt 2018-10-07 13:18:45 +02:00 committed by pajlada
parent bb6c2b6135
commit 2d3ce59b8b

View file

@ -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));
}
}
}