Mercurial > hg > svcore
changeset 1362:1bf38a4b91c4 3.0-integration
When importing CSV, if the first line doesn't have a separator, continue to leave the separator indeterminate until we arrive at a line that does. Fixes inability to load correctly CSV files in which some lines have more columns than others
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2017 14:18:34 +0000 |
parents | 49b43306778b |
children | 39271c98cbdd |
files | data/fileio/CSVFileReader.h data/fileio/CSVFormat.cpp data/fileio/CSVFormat.h |
diffstat | 3 files changed, 22 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.h Tue Jan 10 11:08:14 2017 +0000 +++ b/data/fileio/CSVFileReader.h Tue Jan 10 14:18:34 2017 +0000 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _CSV_FILE_READER_H_ -#define _CSV_FILE_READER_H_ +#ifndef SV_CSV_FILE_READER_H +#define SV_CSV_FILE_READER_H #include "DataFileReader.h"
--- a/data/fileio/CSVFormat.cpp Tue Jan 10 11:08:14 2017 +0000 +++ b/data/fileio/CSVFormat.cpp Tue Jan 10 14:18:34 2017 +0000 @@ -25,6 +25,8 @@ #include <iostream> +#include "base/Debug.h" + CSVFormat::CSVFormat(QString path) : m_separator(""), m_sampleRate(44100), @@ -92,7 +94,6 @@ return; } } - m_separator = " "; } void @@ -100,7 +101,7 @@ { if (m_separator == "") guessSeparator(line); - QStringList list = StringBits::split(line, m_separator[0], m_allowQuoting); + QStringList list = StringBits::split(line, getSeparator(), m_allowQuoting); int cols = list.size(); if (lineno == 0 || (cols > m_columnCount)) m_columnCount = cols; @@ -182,11 +183,13 @@ } } -// cerr << "Estimated column qualities: "; -// for (int i = 0; i < m_columnCount; ++i) { -// cerr << int(m_columnQualities[i]) << " "; -// } -// cerr << endl; + if (lineno < 10) { + SVDEBUG << "Estimated column qualities for line " << lineno << " (reporting up to first 10): "; + for (int i = 0; i < m_columnCount; ++i) { + SVDEBUG << int(m_columnQualities[i]) << " "; + } + SVDEBUG << endl; + } } void @@ -314,15 +317,15 @@ } } -// cerr << "Estimated column purposes: "; -// for (int i = 0; i < m_columnCount; ++i) { -// cerr << int(m_columnPurposes[i]) << " "; -// } -// cerr << endl; + SVDEBUG << "Estimated column purposes: "; + for (int i = 0; i < m_columnCount; ++i) { + SVDEBUG << int(m_columnPurposes[i]) << " "; + } + SVDEBUG << endl; -// cerr << "Estimated model type: " << m_modelType << endl; -// cerr << "Estimated timing type: " << m_timingType << endl; -// cerr << "Estimated units: " << m_timeUnits << endl; + SVDEBUG << "Estimated model type: " << m_modelType << endl; + SVDEBUG << "Estimated timing type: " << m_timingType << endl; + SVDEBUG << "Estimated units: " << m_timeUnits << endl; } CSVFormat::ColumnPurpose
--- a/data/fileio/CSVFormat.h Tue Jan 10 11:08:14 2017 +0000 +++ b/data/fileio/CSVFormat.h Tue Jan 10 14:18:34 2017 +0000 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _CSV_FORMAT_H_ -#define _CSV_FORMAT_H_ +#ifndef SV_CSV_FORMAT_H +#define SV_CSV_FORMAT_H #include <QString> #include <QStringList>