1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat: Prefere new line as message break

Fix #4113
This commit is contained in:
Diadlo 2017-11-24 12:31:16 +03:00
parent e74cc37a2d
commit 3b52402fa2
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727

View File

@ -1324,10 +1324,15 @@ QString Core::getFriendUsername(uint32_t friendnumber) const
QStringList Core::splitMessage(const QString& message, int maxLen)
{
QStringList splittedMsgs;
QByteArray ba_message(message.toUtf8());
QByteArray ba_message{message.toUtf8()};
while (ba_message.size() > maxLen) {
int splitPos = ba_message.lastIndexOf(' ', maxLen - 1);
int splitPos = ba_message.lastIndexOf('\n', maxLen - 1);
if (splitPos <= 0) {
splitPos = ba_message.lastIndexOf(' ', maxLen - 1);
}
if (splitPos <= 0) {
splitPos = maxLen;
if (ba_message[splitPos] & 0x80) {
@ -1338,11 +1343,11 @@ QStringList Core::splitMessage(const QString& message, int maxLen)
--splitPos;
}
splittedMsgs.append(QString(ba_message.left(splitPos + 1)));
splittedMsgs.append(QString{ba_message.left(splitPos + 1)});
ba_message = ba_message.mid(splitPos + 1);
}
splittedMsgs.append(QString(ba_message));
splittedMsgs.append(QString{ba_message});
return splittedMsgs;
}