Wat copy paste code en csvwriter alvast toegevoegd maar nog uitgeschakeld.

This commit is contained in:
Eelke Klein 2017-01-13 19:09:58 +01:00
parent cc5bbab0f5
commit be1892ac52
6 changed files with 90 additions and 4 deletions

30
csvwriter.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "csvwriter.h"
CsvWriter::CsvWriter()
{
}
//int complexField = (strchr(field, csvWriter->delimiter_) || strchr(field, '\n') || strchr(field, '\"')) ? 1 : 0;
void CsvWriter::writeField(QString field) {
// if field contains any of seperator quote or newline then it needs to be quoted
// when quoted quotes need to be doubled to escape them
bool needs_quotes = false;
int new_len = field.length();
for (auto ch : field) {
if (ch == m_quote) {
++new_len;
}
if (ch == '\n' || ch == m_seperator || ch == m_quote) {
needs_quotes = true;
}
}
if (needs_quotes) {
new_len += 2;
}
}