comparison data/fileio/CSVFormat.cpp @ 1585:9570ef94eaa3

Add mechanism to retrieve the set of plausible separators found in CSV-like file when guessing its format
author Chris Cannam
date Wed, 09 Jan 2019 14:39:50 +0000
parents a92e94215863
children bde22957545e
comparison
equal deleted inserted replaced
1578:07f23b90701a 1585:9570ef94eaa3
37 } 37 }
38 38
39 bool 39 bool
40 CSVFormat::guessFormatFor(QString path) 40 CSVFormat::guessFormatFor(QString path)
41 { 41 {
42 m_separator = ""; // to prompt guessing for it
43
44 m_modelType = TwoDimensionalModel; 42 m_modelType = TwoDimensionalModel;
45 m_timingType = ExplicitTiming; 43 m_timingType = ExplicitTiming;
46 m_timeUnits = TimeSeconds; 44 m_timeUnits = TimeSeconds;
47 45
48 m_maxExampleCols = 0; 46 m_maxExampleCols = 0;
106 QString candidates = "\t|,/: "; 104 QString candidates = "\t|,/: ";
107 105
108 for (int i = 0; i < candidates.length(); ++i) { 106 for (int i = 0; i < candidates.length(); ++i) {
109 auto bits = StringBits::split(line, candidates[i], m_allowQuoting); 107 auto bits = StringBits::split(line, candidates[i], m_allowQuoting);
110 if (bits.size() >= 2) { 108 if (bits.size() >= 2) {
111 SVDEBUG << "Successfully split the line into:" << endl; 109 m_plausibleSeparators.insert(candidates[i]);
112 for (auto b: bits) { 110 if (m_separator == "") {
113 SVDEBUG << b << endl; 111 m_separator = candidates[i];
114 } 112 SVDEBUG << "Estimated column separator: '" << m_separator
115 m_separator = candidates[i]; 113 << "'" << endl;
116 SVDEBUG << "Estimated column separator: '" << m_separator 114 }
117 << "'" << endl;
118 return;
119 } 115 }
120 } 116 }
121 } 117 }
122 118
123 void 119 void
124 CSVFormat::guessQualities(QString line, int lineno) 120 CSVFormat::guessQualities(QString line, int lineno)
125 { 121 {
126 if (m_separator == "") { 122 guessSeparator(line);
127 guessSeparator(line);
128 }
129 123
130 QStringList list = StringBits::split(line, getSeparator(), m_allowQuoting); 124 QStringList list = StringBits::split(line, getSeparator(), m_allowQuoting);
131 125
132 int cols = list.size(); 126 int cols = list.size();
133 if (lineno == 0 || (cols > m_columnCount)) m_columnCount = cols; 127 if (lineno == 0 || (cols > m_columnCount)) m_columnCount = cols;