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); log("v nullptr {}", std::get<2>(tup).string);
continue; continue;
} }
int index = 0; QRegularExpression emoteregex(
QString emote = " " + std::get<2>(tup).string + " "; "\\b" + std::get<2>(tup).string + "\\b",
while ((index = midExtendedRef.indexOf(emote, index)) != QRegularExpression::UseUnicodePropertiesOption);
-1) { auto match = emoteregex.match(midExtendedRef);
std::get<0>(tup) = from + index + 1; if (match.hasMatch()) {
index += emote.size() - 1; int last = match.lastCapturedIndex();
twitchEmotes.push_back(tup); 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); log("v nullptr {}", std::get<2>(tup).string);
continue; continue;
} }
int index = 0; QRegularExpression emoteregex(
QString emote = " " + std::get<2>(tup).string + " "; "\\b" + std::get<2>(tup).string + "\\b",
while ((index = midExtendedRef.indexOf(emote, index)) != QRegularExpression::UseUnicodePropertiesOption);
-1) { auto match = emoteregex.match(midExtendedRef);
std::get<0>(tup) = from + index + 1; if (match.hasMatch()) {
index += emote.size() - 1; int last = match.lastCapturedIndex();
twitchEmotes.push_back(tup); for (int i = 0; i <= last; ++i) {
std::get<0>(tup) = from + match.capturedStart();
twitchEmotes.push_back(std::move(tup));
}
} }
} }