mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
csvparser: Add support for old Mac OS line endings
In order to detect the CR characters, the file must be opened in binary mode, otherwise QFile just removes them all. See issue #212.
This commit is contained in:
@@ -125,7 +125,7 @@ void ImportCsvDialog::accept()
|
||||
|
||||
// Parse all csv data
|
||||
QFile file(csvFilename);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
CSVParser csv(ui->checkBoxTrimFields->isChecked(), currentSeparatorChar(), currentQuoteChar());
|
||||
csv.setCSVProgress(new CSVImportProgress(file.size()));
|
||||
@@ -261,7 +261,7 @@ void ImportCsvDialog::updatePreview()
|
||||
|
||||
// Get preview data
|
||||
QFile file(csvFilename);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
CSVParser csv(ui->checkBoxTrimFields->isChecked(), currentSeparatorChar(), currentQuoteChar());
|
||||
|
||||
|
||||
@@ -60,10 +60,16 @@ bool CSVParser::parse(QTextStream& stream, int64_t nMaxRecords)
|
||||
}
|
||||
else if(c == '\r')
|
||||
{
|
||||
// look ahead to check for newline
|
||||
// look ahead to check for linefeed
|
||||
QString::iterator nit = it + 1;
|
||||
|
||||
// no linefeed, so assume that CR represents a newline
|
||||
if(nit != sBuffer.end() && *nit != '\n')
|
||||
fieldbuf.append(c);
|
||||
{
|
||||
addColumn(record, fieldbuf, m_bTrimFields);
|
||||
|
||||
addRow(record);
|
||||
}
|
||||
}
|
||||
else if(c == '\n')
|
||||
{
|
||||
@@ -108,6 +114,19 @@ bool CSVParser::parse(QTextStream& stream, int64_t nMaxRecords)
|
||||
|
||||
addRow(record);
|
||||
}
|
||||
else if(c == '\r')
|
||||
{
|
||||
// look ahead to check for linefeed
|
||||
QString::iterator nit = it + 1;
|
||||
|
||||
// no linefeed, so assume that CR represents a newline
|
||||
if(nit != sBuffer.end() && *nit != '\n')
|
||||
{
|
||||
addColumn(record, fieldbuf, m_bTrimFields);
|
||||
|
||||
addRow(record);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = StateNormal;
|
||||
|
||||
Reference in New Issue
Block a user