mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(core): split messages on utf8 multibyte character boundary properly
Fix #4917
This commit is contained in:
parent
04ecfe3f34
commit
869036f3c6
|
@ -1392,15 +1392,17 @@ QStringList Core::splitMessage(const QString& message, int maxLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (splitPos <= 0) {
|
if (splitPos <= 0) {
|
||||||
|
constexpr uint8_t firstOfMultiByteMask = 0xC0;
|
||||||
|
constexpr uint8_t multiByteMask = 0x80;
|
||||||
splitPos = maxLen;
|
splitPos = maxLen;
|
||||||
if (ba_message[splitPos] & 0x80) {
|
// don't split a utf8 character
|
||||||
do {
|
if ((ba_message[splitPos] & multiByteMask) == multiByteMask) {
|
||||||
|
while ((ba_message[splitPos] & firstOfMultiByteMask) != firstOfMultiByteMask) {
|
||||||
--splitPos;
|
--splitPos;
|
||||||
} while (!(ba_message[splitPos] & 0x40));
|
}
|
||||||
}
|
}
|
||||||
--splitPos;
|
--splitPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
splittedMsgs.append(QString{ba_message.left(splitPos + 1)});
|
splittedMsgs.append(QString{ba_message.left(splitPos + 1)});
|
||||||
ba_message = ba_message.mid(splitPos + 1);
|
ba_message = ba_message.mid(splitPos + 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user