kraken: csv: add writing functionality

Once again, pretty naive, but it will do.
This commit is contained in:
Bruno BELANYI 2022-03-12 00:31:20 +01:00
parent 0dee0e12dc
commit 23b71018ac
3 changed files with 32 additions and 0 deletions

View file

@ -2,5 +2,7 @@ add_library(csv STATIC
csv.hh csv.hh
read-csv.cc read-csv.cc
read-csv.hh read-csv.hh
write-csv.cc
write-csv.hh
) )
target_link_libraries(csv PRIVATE common_options) target_link_libraries(csv PRIVATE common_options)

16
src/csv/write-csv.cc Normal file
View file

@ -0,0 +1,16 @@
#include "write-csv.hh"
#include <algorithm>
#include <iostream>
#include <iterator>
namespace kraken::csv {
void write_csv(std::ostream& output, csv_type const& csv) {
for (const auto& line : csv) {
std::ranges::copy(line,
std::ostream_iterator<std::string>{output, ","});
}
}
} // namespace kraken::csv

14
src/csv/write-csv.hh Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include <iosfwd>
#include <string>
#include <vector>
#include "csv/csv.hh"
namespace kraken::csv {
/// Write raw CSV data to an output-stream.
void write_csv(std::ostream& output, csv_type const& csv);
} // namespace kraken::csv