* @brief Escapes a CSV field per RFC 4180, quoting only when special characters require it. */
| 35 | * @brief Escapes a CSV field per RFC 4180, quoting only when special characters require it. |
| 36 | */ |
| 37 | static QString escapeCsvField(const QString& s) |
| 38 | { |
| 39 | const bool needs = s.contains(QChar(',')) || s.contains(QChar('"')) || s.contains(QChar('\n')) |
| 40 | || s.contains(QChar('\r')) || s.contains(QChar('\t')); |
| 41 | if (!needs) |
| 42 | return s; |
| 43 | |
| 44 | QString out = s; |
| 45 | out.replace(QChar('"'), QStringLiteral("\"\"")); |
| 46 | return QStringLiteral("\"%1\"").arg(out); |
| 47 | } |
| 48 | |
| 49 | //-------------------------------------------------------------------------------------------------- |
| 50 | // ExportWorker implementation |
no test coverage detected