Skip to content

Commit

Permalink
Fix csv escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Apr 3, 2024
1 parent 86e1e7b commit ab9b7ea
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/CsvFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ bool CsvFile::readLine(QStringList &line)

bool CsvFile::writeLine(const QStringList &line)
{
QString l;
QString l, esc = QString().append(_quoteCharacter).append(_quoteCharacter);

for (const QString &field: line) {
l.append(_quoteCharacter).append(field).append(_quoteCharacter).append(_fieldSeparator);
for (QString field: line) {
l.append(_quoteCharacter)
.append(field.replace(_quoteCharacter, esc))
.append(_quoteCharacter)
.append(_fieldSeparator);
}

l[l.size() - 1] = '\r';
l.append('\n');

Expand Down

0 comments on commit ab9b7ea

Please sign in to comment.