Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat: Prefere new line as message break
Browse files Browse the repository at this point in the history
Fix #4113
  • Loading branch information
Diadlo committed Jan 20, 2018
1 parent e74cc37 commit 3b52402
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 3b52402

Please sign in to comment.