QList<CString> Core::splitMessage(const QString &message) { QList<CString> splittedMsgs; QByteArray ba_message(message.toUtf8()); while (ba_message.size() > TOX_MAX_MESSAGE_LENGTH) { int splitPos = ba_message.lastIndexOf(' ', TOX_MAX_MESSAGE_LENGTH - 1); if (splitPos <= 0) { splitPos = TOX_MAX_MESSAGE_LENGTH; if (ba_message[splitPos] & 0x80) { do { splitPos--; } while (!(ba_message[splitPos] & 0x40)); } splitPos--; } splittedMsgs.push_back(CString(ba_message.left(splitPos + 1))); ba_message = ba_message.mid(splitPos + 1); } splittedMsgs.push_back(CString(ba_message)); return splittedMsgs; }
QStringList Core::splitMessage(const QString& message, int maxLen) { QStringList splittedMsgs; QByteArray ba_message(message.toUtf8()); while (ba_message.size() > maxLen) { int splitPos = ba_message.lastIndexOf(' ', maxLen - 1); if (splitPos <= 0) { splitPos = maxLen; if (ba_message[splitPos] & 0x80) { do { --splitPos; } while (!(ba_message[splitPos] & 0x40)); } --splitPos; } splittedMsgs.append(QString(ba_message.left(splitPos + 1))); ba_message = ba_message.mid(splitPos + 1); } splittedMsgs.append(QString(ba_message)); return splittedMsgs; }