util/MenuText.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | // S106-280: native QMenu/QAction labels treat '&' as a mnemonic marker and a | ||
| 3 | // tab as the start of the shortcut column. Labels that carry untrusted text | ||
| 4 | // (contact names, address-book and list names, senders, folders, labels) | ||
| 5 | // go through plain() so "AT&T" stays "AT&T". Header-only and pure; the | ||
| 6 | // QML fallback menus render their text verbatim and need no escaping. | ||
| 7 | |||
| 8 | #include <QString> | ||
| 9 | |||
| 10 | namespace MenuText { | ||
| 11 | |||
| 12 | // '&' doubled; tabs, line breaks and other control characters become spaces. | ||
| 13 | 601 | inline QString plain(const QString &text) { | |
| 14 | 601 | QString result; | |
| 15 |
1/1✓ Branch 3 → 4 taken 601 times.
|
601 | result.reserve(text.size() + 4); |
| 16 |
2/2✓ Branch 25 → 6 taken 7553 times.
✓ Branch 25 → 26 taken 601 times.
|
8154 | for (const QChar ch : text) { |
| 17 |
2/2✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 17 taken 7550 times.
|
7553 | if (ch == QLatin1Char('&')) |
| 18 |
1/1✓ Branch 13 → 14 taken 3 times.
|
3 | result += QStringLiteral("&&"); |
| 19 |
2/2✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 23 taken 7548 times.
|
7550 | else if (ch.category() == QChar::Other_Control) |
| 20 |
1/1✓ Branch 21 → 22 taken 2 times.
|
2 | result += QLatin1Char(' '); |
| 21 | else | ||
| 22 |
1/1✓ Branch 23 → 24 taken 7548 times.
|
7548 | result += ch; |
| 23 | } | ||
| 24 | 601 | return result; | |
| 25 | ✗ | } | |
| 26 | |||
| 27 | } // namespace MenuText | ||
| 28 |