| 393 | // --- Messages: ":ADDRESSEE:text{NN" (ch. 14) ------------------------------ |
| 394 | |
| 395 | bool parseMessage(const QString& body, Packet& pkt) |
| 396 | { |
| 397 | // body excludes the ':' DTI. Addressee field is exactly 9 chars + ':'. |
| 398 | if (body.size() < 10 || body.at(9) != QLatin1Char(':')) |
| 399 | return false; |
| 400 | pkt.addressee = body.left(9).trimmed().toUpper(); |
| 401 | if (pkt.addressee.isEmpty()) |
| 402 | return false; |
| 403 | QString text = body.mid(10); |
| 404 | |
| 405 | static const QRegularExpression ackRej( |
| 406 | QStringLiteral("^(ack|rej)([A-Za-z0-9]{1,5})$")); |
| 407 | const QRegularExpressionMatch m = ackRej.match(text); |
| 408 | if (m.hasMatch()) { |
| 409 | pkt.type = (m.captured(1) == QLatin1String("ack")) |
| 410 | ? PacketType::MessageAck : PacketType::MessageRej; |
| 411 | pkt.messageNo = m.captured(2); |
| 412 | return true; |
| 413 | } |
| 414 | |
| 415 | const int brace = text.lastIndexOf(QLatin1Char('{')); |
| 416 | if (brace >= 0 && text.size() - brace - 1 >= 1 && text.size() - brace - 1 <= 5) { |
| 417 | pkt.messageNo = text.mid(brace + 1); |
| 418 | text.truncate(brace); |
| 419 | } |
| 420 | pkt.type = PacketType::Message; |
| 421 | pkt.messageText = text; |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | } // namespace |
| 426 |
no test coverage detected