Mercurial > hg > svcore
comparison data/fileio/CSVFormat.cpp @ 1854:bde22957545e
Add support for doubling escapes for quotes in quoted texts in CSV-like formats on import (similar to how we, and the relevant RFC, do escaping on export now)
author | Chris Cannam |
---|---|
date | Mon, 11 May 2020 14:43:58 +0100 |
parents | 9570ef94eaa3 |
children | 1b8c4ee06f6d |
comparison
equal
deleted
inserted
replaced
1853:f36fef97ac81 | 1854:bde22957545e |
---|---|
133 ColumnQualities defaultQualities = | 133 ColumnQualities defaultQualities = |
134 ColumnNumeric | ColumnIntegral | ColumnSmall | | 134 ColumnNumeric | ColumnIntegral | ColumnSmall | |
135 ColumnIncreasing | ColumnNearEmpty; | 135 ColumnIncreasing | ColumnNearEmpty; |
136 | 136 |
137 for (int i = 0; i < cols; ++i) { | 137 for (int i = 0; i < cols; ++i) { |
138 | 138 |
139 SVDEBUG << "line no " << lineno << ": column " << i << " contains: \"" << list[i] << "\"" << endl; | |
140 | |
139 while (m_columnQualities.size() <= i) { | 141 while (m_columnQualities.size() <= i) { |
140 m_columnQualities.push_back(defaultQualities); | 142 m_columnQualities.push_back(defaultQualities); |
141 m_prevValues.push_back(0.f); | 143 m_prevValues.push_back(0.f); |
142 } | 144 } |
143 | 145 |
155 bool small = (qualities & ColumnSmall); | 157 bool small = (qualities & ColumnSmall); |
156 bool large = (qualities & ColumnLarge); // this one defaults to off | 158 bool large = (qualities & ColumnLarge); // this one defaults to off |
157 bool signd = (qualities & ColumnSigned); // also defaults to off | 159 bool signd = (qualities & ColumnSigned); // also defaults to off |
158 bool emptyish = (qualities & ColumnNearEmpty); | 160 bool emptyish = (qualities & ColumnNearEmpty); |
159 | 161 |
160 if (lineno > 1 && s.trimmed() != "") { | 162 if (s.trimmed() != "") { |
161 emptyish = false; | 163 |
162 } | 164 if (lineno > 1) { |
163 | 165 emptyish = false; |
164 float value = 0.f; | 166 } |
165 | 167 |
166 //!!! how to take into account headers? | 168 float value = 0.f; |
167 | 169 |
168 if (numeric) { | 170 //!!! how to take into account headers? |
169 value = s.toFloat(&ok); | 171 |
170 if (!ok) { | 172 if (numeric) { |
171 value = (float)StringBits::stringToDoubleLocaleFree(s, &ok); | 173 value = s.toFloat(&ok); |
172 } | 174 if (!ok) { |
173 if (ok) { | 175 value = (float)StringBits::stringToDoubleLocaleFree(s, &ok); |
174 if (lineno < 2 && value > 1000.f) { | 176 } |
175 large = true; | 177 if (ok) { |
176 } | 178 if (lineno < 2 && value > 1000.f) { |
177 if (value < 0.f) { | 179 large = true; |
178 signd = true; | 180 } |
179 } | 181 if (value < 0.f) { |
180 if (value < -1.f || value > 1.f) { | 182 signd = true; |
183 } | |
184 if (value < -1.f || value > 1.f) { | |
185 small = false; | |
186 } | |
187 } else { | |
188 numeric = false; | |
189 | |
190 // If the column is not numeric, it can't be any of | |
191 // these things either | |
192 integral = false; | |
193 increasing = false; | |
181 small = false; | 194 small = false; |
182 } | 195 large = false; |
183 } else { | 196 signd = false; |
184 numeric = false; | 197 } |
185 | 198 } |
186 // If the column is not numeric, it can't be any of | 199 |
187 // these things either | 200 if (numeric) { |
188 integral = false; | 201 |
189 increasing = false; | 202 if (integral) { |
190 small = false; | 203 if (s.contains('.') || s.contains(',')) { |
191 large = false; | 204 integral = false; |
192 signd = false; | 205 } |
193 } | 206 } |
194 } | 207 |
195 | 208 if (increasing) { |
196 if (numeric) { | 209 if (lineno > 0 && value <= m_prevValues[i]) { |
197 | 210 increasing = false; |
198 if (integral) { | 211 } |
199 if (s.contains('.') || s.contains(',')) { | 212 } |
200 integral = false; | 213 |
201 } | 214 m_prevValues[i] = value; |
202 } | 215 } |
203 | |
204 if (increasing) { | |
205 if (lineno > 0 && value <= m_prevValues[i]) { | |
206 increasing = false; | |
207 } | |
208 } | |
209 | |
210 m_prevValues[i] = value; | |
211 } | 216 } |
212 | 217 |
213 m_columnQualities[i] = | 218 m_columnQualities[i] = |
214 (numeric ? ColumnNumeric : 0) | | 219 (numeric ? ColumnNumeric : 0) | |
215 (integral ? ColumnIntegral : 0) | | 220 (integral ? ColumnIntegral : 0) | |