MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / escapeCsvField

Function escapeCsvField

app/src/CSV/Export.cpp:37–47  ·  view source on GitHub ↗

* @brief Escapes a CSV field per RFC 4180, quoting only when special characters require it. */

Source from the content-addressed store, hash-verified

35 * @brief Escapes a CSV field per RFC 4180, quoting only when special characters require it.
36 */
37static 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

Callers 4

processItemsMethod · 0.85
createCsvFileMethod · 0.85
publishBatchAsCsvMethod · 0.85
rebuildCsvSchemaMethod · 0.85

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected