kraken: csv: expose 'read_csv_line'

This commit is contained in:
Bruno BELANYI 2022-03-24 17:17:09 +01:00
parent 6fc5502b99
commit 8474ed0c69
2 changed files with 5 additions and 7 deletions

View file

@ -4,10 +4,7 @@
namespace kraken::csv {
namespace {
// for convenience, use a stringstream which does not accept string_view inputs
csv_line_type parse_line(std::string const& line) {
csv_line_type read_csv_line(std::string const& line) {
auto parsed = csv_line_type{};
auto input = std::istringstream(line);
@ -18,8 +15,6 @@ csv_line_type parse_line(std::string const& line) {
return parsed;
}
} // namespace
csv_type read_csv(std::istream& input, CsvHeader header) {
auto parsed = std::vector<csv_line_type>{};
@ -30,7 +25,7 @@ csv_type read_csv(std::istream& input, CsvHeader header) {
continue;
}
parsed.emplace_back(parse_line(std::move(line)));
parsed.emplace_back(read_csv_line(std::move(line)));
}
return parsed;

View file

@ -14,6 +14,9 @@ enum class CsvHeader {
KEEP,
};
/// Parse a single CSV line, no error checking.
csv_line_type read_csv_line(std::string const& input);
/// Parse a CSV file from an input-stream, return a vector of parsed lines.
csv_type read_csv(std::istream& input, CsvHeader header = CsvHeader::SKIP);