Mercurial > hg > svcore
comparison data/fileio/CSVStreamWriter.h @ 1833:21c792334c2e sensible-delimited-data-strings
Rewrite all the DelimitedDataString stuff so as to return vectors of individual cell strings rather than having the classes add the delimiters themselves. Rename accordingly to names based on StringExport. Take advantage of this in the CSV writer code so as to properly quote cells that contain delimiter characters.
author | Chris Cannam |
---|---|
date | Fri, 03 Apr 2020 17:11:05 +0100 |
parents | 0d89abd631ac |
children |
comparison
equal
deleted
inserted
replaced
1832:7c92c644db20 | 1833:21c792334c2e |
---|---|
18 | 18 |
19 #include "base/BaseTypes.h" | 19 #include "base/BaseTypes.h" |
20 #include "base/Selection.h" | 20 #include "base/Selection.h" |
21 #include "base/ProgressReporter.h" | 21 #include "base/ProgressReporter.h" |
22 #include "base/DataExportOptions.h" | 22 #include "base/DataExportOptions.h" |
23 #include "base/StringBits.h" | |
23 #include "data/model/Model.h" | 24 #include "data/model/Model.h" |
25 | |
24 #include <QString> | 26 #include <QString> |
25 #include <algorithm> | 27 #include <algorithm> |
26 #include <numeric> | 28 #include <numeric> |
27 | 29 |
28 namespace CSVStreamWriter | 30 namespace CSVStreamWriter |
66 while (readPtr < endFrame) { | 68 while (readPtr < endFrame) { |
67 if (wasCancelled()) return false; | 69 if (wasCancelled()) return false; |
68 | 70 |
69 const auto start = readPtr; | 71 const auto start = readPtr; |
70 const auto end = std::min(start + blockSize, endFrame); | 72 const auto end = std::min(start + blockSize, endFrame); |
71 const auto data = model.toDelimitedDataString( | 73 const auto data = model.toStringExportRows( |
72 delimiter, | |
73 options, | 74 options, |
74 start, | 75 start, |
75 end - start | 76 end - start |
76 ).trimmed(); | 77 ); |
77 | 78 |
78 if ( data != "" ) { | 79 if (!data.empty()) { |
79 if (started) { | 80 for (const auto &row: data) { |
80 oss << "\n"; | 81 if (started) { |
81 } else { | 82 oss << "\n"; |
82 started = true; | 83 } else { |
84 started = true; | |
85 } | |
86 oss << StringBits::joinDelimited(row, delimiter); | |
83 } | 87 } |
84 oss << data; | |
85 } | 88 } |
86 | 89 |
87 nFramesWritten += end - start; | 90 nFramesWritten += end - start; |
88 const int currentProgress = | 91 const int currentProgress = |
89 int(100 * nFramesWritten / nFramesToWrite); | 92 int(100 * nFramesWritten / nFramesToWrite); |
118 startFrame, | 121 startFrame, |
119 endFrame | 122 endFrame |
120 }; | 123 }; |
121 MultiSelection regions; | 124 MultiSelection regions; |
122 regions.addSelection(all); | 125 regions.addSelection(all); |
123 return CSVStreamWriter::writeInChunks( | 126 return writeInChunks( |
124 oss, | 127 oss, |
125 model, | 128 model, |
126 regions, | 129 regions, |
127 reporter, | 130 reporter, |
128 delimiter, | 131 delimiter, |
139 QString delimiter = ",", | 142 QString delimiter = ",", |
140 DataExportOptions options = DataExportDefaults, | 143 DataExportOptions options = DataExportDefaults, |
141 const sv_frame_t blockSize = 16384) | 144 const sv_frame_t blockSize = 16384) |
142 { | 145 { |
143 const Selection empty; | 146 const Selection empty; |
144 return CSVStreamWriter::writeInChunks( | 147 return writeInChunks( |
145 oss, | 148 oss, |
146 model, | 149 model, |
147 empty, | 150 empty, |
148 reporter, | 151 reporter, |
149 delimiter, | 152 delimiter, |