fixes twitch emotes position

changes the position in unicodepoints to position in char16 array
(qstring)
This commit is contained in:
hemirt 2018-11-17 11:00:44 +01:00
parent 27eb2d8abc
commit d2e43d78fc
2 changed files with 16 additions and 28 deletions

View file

@ -174,11 +174,18 @@ MessagePtr TwitchMessageBuilder::build()
if (iterator != this->tags.end()) if (iterator != this->tags.end())
{ {
QStringList emoteString = iterator.value().toString().split('/'); QStringList emoteString = iterator.value().toString().split('/');
std::vector<int> correctPositions;
for (int i = 0; i < this->originalMessage_.size(); ++i) {
if (!this->originalMessage_.at(i).isLowSurrogate()) {
correctPositions.push_back(i);
}
}
for (QString emote : emoteString) for (QString emote : emoteString)
{ {
this->appendTwitchEmote(emote, twitchEmotes); this->appendTwitchEmote(emote, twitchEmotes, correctPositions);
} }
} }
auto app = getApp(); auto app = getApp();
const auto &phrases = app->ignores->phrases.getVector(); const auto &phrases = app->ignores->phrases.getVector();
@ -186,15 +193,6 @@ MessagePtr TwitchMessageBuilder::build()
[&message = this->originalMessage_](int pos, int len, [&message = this->originalMessage_](int pos, int len,
std::vector<std::tuple<int, EmotePtr, EmoteName>> std::vector<std::tuple<int, EmotePtr, EmoteName>>
&twitchEmotes) mutable { &twitchEmotes) mutable {
int emotePos = 0;
for(int i = 0; i < pos; ++i) {
++emotePos;
if (message.at(i).isLowSurrogate()) {
--emotePos;
}
}
pos = emotePos;
auto it = auto it =
std::partition(twitchEmotes.begin(), twitchEmotes.end(), std::partition(twitchEmotes.begin(), twitchEmotes.end(),
[pos, len](const auto &item) { [pos, len](const auto &item) {
@ -461,17 +459,7 @@ void TwitchMessageBuilder::addWords(
variant); variant);
} }
for (int j = 0; j < word.size(); j++) i += word.size() + 1;
{
i++;
if (word.at(j).isHighSurrogate())
{
j++;
}
}
i++;
} }
} }
@ -944,7 +932,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
void TwitchMessageBuilder::appendTwitchEmote( void TwitchMessageBuilder::appendTwitchEmote(
const QString &emote, const QString &emote,
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec) std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec,
std::vector<int> & correctPositions)
{ {
auto app = getApp(); auto app = getApp();
if (!emote.contains(':')) if (!emote.contains(':'))
@ -972,8 +961,8 @@ void TwitchMessageBuilder::appendTwitchEmote(
return; return;
} }
auto start = coords.at(0).toInt(); auto start = correctPositions[coords.at(0).toInt()];
auto end = coords.at(1).toInt(); auto end = correctPositions[coords.at(1).toInt()];
if (start >= end || start < 0 || end > this->originalMessage_.length()) if (start >= end || start < 0 || end > this->originalMessage_.length())
{ {

View file

@ -55,9 +55,8 @@ private:
void appendUsername(); void appendUsername();
void parseHighlights(bool isPastMsg); void parseHighlights(bool isPastMsg);
void appendTwitchEmote( void appendTwitchEmote(const QString &emote,
const QString &emote, std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec, std::vector<int> &correctPositions);
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec);
Outcome tryAppendEmote(const EmoteName &name); Outcome tryAppendEmote(const EmoteName &name);
void addWords( void addWords(