7#include <rapidcsv/rapidcsv.h>
11 m_stream( aStream ), m_delimiter( wxT(
"," ) ),
12 m_quote( wxT(
"\"" ) ), m_lineTerminator( wxT(
"\n" ) ),
13 m_escape( wxEmptyString )
20 for(
const auto& row : aRows )
31 for(
size_t i = 0; i < cols.size(); ++i )
33 wxString colVal = cols[i];
39 const bool useEscape =
m_escape.size();
61 std::string utf8str( line.utf8_string() );
62 m_stream.Write( utf8str.data(), utf8str.length() );
66bool AutoDecodeCSV(
const wxString& aInput, std::vector<std::vector<wxString>>& aData )
69 bool trimCells =
true;
70 bool skipCommentLines =
true;
71 bool skipEmptyLines =
true;
72 char commentPrefix =
'#';
76 if( aInput.find(
'\t' ) != std::string::npos )
81 std::istringstream inputStream( aInput.ToStdString() );
83 rapidcsv::Document doc( inputStream, rapidcsv::LabelParams( -1, -1 ),
84 rapidcsv::SeparatorParams( delimiter, trimCells ), rapidcsv::ConverterParams(),
85 rapidcsv::LineReaderParams( skipCommentLines, commentPrefix, skipEmptyLines ) );
90 for(
size_t i = 0; i < doc.GetRowCount(); ++i )
92 std::vector<wxString>& row = aData.emplace_back();
93 for(
size_t j = 0; j < doc.GetColumnCount(); ++j )
95 std::string cell = doc.GetCell<std::string>( j, i );
96 row.emplace_back( cell );
101 return aData[0].size() > 0;
void WriteLines(const std::vector< std::vector< wxString > > &aRows)
Write a vector of rows to the stream.
void WriteLine(const std::vector< wxString > &aCols)
Write a single row to the stream.
wxOutputStream & m_stream
CSV_WRITER(wxOutputStream &aStream)
wxString m_lineTerminator
bool AutoDecodeCSV(const wxString &aInput, std::vector< std::vector< wxString > > &aData)
Try to guess the format of a T/CSV file and decode it into aData.