From 27eb2d8abc0018ca4f18092607580d9049dbe9af Mon Sep 17 00:00:00 2001 From: hemirt Date: Thu, 15 Nov 2018 21:11:50 +0100 Subject: [PATCH] fix surrogatepairs messing position of emotes to be removed (mismatch between actual position, and position in unicode codepoints) --- src/providers/twitch/TwitchMessageBuilder.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 10ca6ba12..38595c70f 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -183,9 +183,18 @@ MessagePtr TwitchMessageBuilder::build() auto app = getApp(); const auto &phrases = app->ignores->phrases.getVector(); auto removeEmotesInRange = - [](int pos, int len, + [&message = this->originalMessage_](int pos, int len, std::vector> &twitchEmotes) mutable { + int emotePos = 0; + for(int i = 0; i < pos; ++i) { + ++emotePos; + if (message.at(i).isLowSurrogate()) { + --emotePos; + } + } + pos = emotePos; + auto it = std::partition(twitchEmotes.begin(), twitchEmotes.end(), [pos, len](const auto &item) {