Fix bug where header reading corrupted the current line buffer

This commit is contained in:
ado 2023-07-16 18:25:15 +02:00
parent 03f5b839fc
commit 5ab41c0315
2 changed files with 11 additions and 8 deletions

View File

@ -44,7 +44,8 @@ public:
if constexpr (ignore_header) { if constexpr (ignore_header) {
ignore_next(); ignore_next();
} else { } else {
header_ = reader_.get_next_row(); // TODO read header after use_fields is called
header_ = reader_.get_header();
} }
} else { } else {
set_error_file_not_open(); set_error_file_not_open();
@ -769,14 +770,15 @@ private:
return true; return true;
} }
std::vector<std::string> get_next_row() { std::vector<std::string> get_header() {
std::vector<std::string> next_row; std::vector<std::string> header;
next_line_converter_.split(next_line_buffer_, delim_); std::string header_buffer = next_line_buffer_;
auto& next_row_raw = next_line_converter_.splitter_.split_data_; converter_.split(header_buffer.data(), delim_);
for (const auto& [begin, end] : next_row_raw) { auto& header_row_raw = converter_.splitter_.split_data_;
next_row.emplace_back(begin, end); for (const auto& [begin, end] : header_row_raw) {
header.emplace_back(begin, end);
} }
return next_row; return header;
} }
//////////////// ////////////////

View File

@ -689,6 +689,7 @@ std::string no_quote(const std::string& s) {
} }
TEST_CASE("parser test csv on multiple lines with quotes") { TEST_CASE("parser test csv on multiple lines with quotes") {
// TODO test with "_""_""_",...
unique_file_name f; unique_file_name f;
std::vector<X> data = {{1, 2, "\"x\r\nx\nx\""}, std::vector<X> data = {{1, 2, "\"x\r\nx\nx\""},
{3, 4, "\"y\ny\r\ny\""}, {3, 4, "\"y\ny\r\ny\""},