Mercurial > hg > svcore
diff data/fileio/CSVFileReader.cpp @ 390:21e79997e80f
* Fix failure to handle scientific notation for time field; tidy up some
warnings and handling of empty fields
author | Chris Cannam |
---|---|
date | Thu, 13 Mar 2008 12:41:20 +0000 |
parents | 14e0f60435b8 |
children | 183ee2a55fc7 |
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp Thu Mar 13 10:12:14 2008 +0000 +++ b/data/fileio/CSVFileReader.cpp Thu Mar 13 12:41:20 2008 +0000 @@ -99,6 +99,7 @@ CSVFormatDialog::TimingType timingType = dialog->getTimingType(); CSVFormatDialog::TimeUnits timeUnits = dialog->getTimeUnits(); QString separator = dialog->getSeparator(); + QString::SplitBehavior behaviour = dialog->getSplitBehaviour(); size_t sampleRate = dialog->getSampleRate(); size_t windowSize = dialog->getWindowSize(); @@ -148,7 +149,7 @@ if (line.startsWith("#")) continue; - QStringList list = line.split(separator, QString::KeepEmptyParts); + QStringList list = line.split(separator, behaviour); if (!model) { @@ -174,7 +175,7 @@ } QStringList tidyList; - QRegExp nonNumericRx("[^0-9.,+-]"); + QRegExp nonNumericRx("[^0-9eE.,+-]"); for (int i = 0; i < list.size(); ++i) { @@ -257,18 +258,20 @@ if (!ok) { if (warnings < warnLimit) { std::cerr << "WARNING: CSVFileReader::load: " - << "Non-numeric value in data line " << lineno + << "Non-numeric value \"" + << list[i].toStdString() + << "\" in data line " << lineno << ":" << std::endl; std::cerr << line.toStdString() << std::endl; ++warnings; } else if (warnings == warnLimit) { - std::cerr << "WARNING: Too many warnings" << std::endl; +// std::cerr << "WARNING: Too many warnings" << std::endl; } } } - std::cerr << "Setting bin values for count " << lineno << ", frame " - << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl; +// std::cerr << "Setting bin values for count " << lineno << ", frame " +// << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl; model3->setColumn(frameNo / model3->getResolution(), values); } @@ -296,7 +299,8 @@ m_modelType(OneDimensionalModel), m_timingType(ExplicitTiming), m_timeUnits(TimeAudioFrames), - m_separator("") + m_separator(""), + m_behaviour(QString::KeepEmptyParts) { setModal(true); setWindowTitle(tr("Select Data Format")); @@ -543,6 +547,8 @@ if (line.startsWith("#")) continue; + m_behaviour = QString::KeepEmptyParts; + if (m_separator == "") { //!!! to do: ask the user if (line.split(",").size() >= 2) m_separator = ","; @@ -550,10 +556,13 @@ else if (line.split("|").size() >= 2) m_separator = "|"; else if (line.split("/").size() >= 2) m_separator = "/"; else if (line.split(":").size() >= 2) m_separator = ":"; - else m_separator = " "; + else { + m_separator = " "; + m_behaviour = QString::SkipEmptyParts; + } } - QStringList list = line.split(m_separator); + QStringList list = line.split(m_separator, m_behaviour); QStringList tidyList; for (int i = 0; i < list.size(); ++i) {