Qt::convertFromPlainText doesn't do precisely what we want
| 54 | |
| 55 | // Qt::convertFromPlainText doesn't do precisely what we want |
| 56 | static QString |
| 57 | plainTextToHTML(const QString & plain, bool multiLine, bool forceNoQuote = false) |
| 58 | { |
| 59 | int col = 0; |
| 60 | bool quote = false; |
| 61 | QString rich; |
| 62 | for (auto & ch : plain) { |
| 63 | if (ch == QLatin1Char('\n')){ |
| 64 | if (multiLine) { |
| 65 | rich += QLatin1String("<br>\n"); |
| 66 | } else { |
| 67 | rich += QLatin1String("\\n"); |
| 68 | } |
| 69 | col = 0; |
| 70 | quote = true; |
| 71 | } else { |
| 72 | if (ch == QLatin1Char('\t')){ |
| 73 | if (multiLine) { |
| 74 | rich += QChar(0x00a0U); |
| 75 | ++col; |
| 76 | while (col % 8) { |
| 77 | rich += QChar(0x00a0U); |
| 78 | ++col; |
| 79 | } |
| 80 | } else { |
| 81 | rich += QLatin1String("\\t"); |
| 82 | } |
| 83 | quote = true; |
| 84 | } else if (ch.isSpace()) { |
| 85 | rich += QChar(0x00a0U); |
| 86 | quote = true; |
| 87 | } else if (ch == QLatin1Char('<')) { |
| 88 | rich += QLatin1String("<"); |
| 89 | } else if (ch == QLatin1Char('>')) { |
| 90 | rich += QLatin1String(">"); |
| 91 | } else if (ch == QLatin1Char('&')) { |
| 92 | rich += QLatin1String("&"); |
| 93 | } else { |
| 94 | rich += ch; |
| 95 | } |
| 96 | ++col; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (quote && !forceNoQuote) { |
| 101 | return QLatin1String("\"") + rich + QLatin1String("\""); |
| 102 | } |
| 103 | |
| 104 | return rich; |
| 105 | } |
| 106 | |
| 107 | QString |
| 108 | apiVariantToString(const QVariant &variant, bool multiLine) |
no test coverage detected