Skip to content

Commit 78b048b

Browse files
committed
Don't push empty rows
The current NEWLINE behavior of reading as much CR/LF as possible basically means empty rows are/should be ignored. This fixes the issue of pushing an empty row that can occur when the data chunk ends in the middle of such a CR/LF stream (either because of a block of empty lines or if you are unlucky because the chunk ended right in the middle of a Windows CRLF endline)
1 parent 23ac626 commit 78b048b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/internal/basic_csv_parser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ namespace csv {
143143
while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
144144
this->data_pos++;
145145

146-
// End of record -> Write record
147-
this->push_field();
148-
this->push_row();
146+
// End of record -> Write non-empty record
147+
if (this->field_length > 0 || !this->current_row.empty()) {
148+
this->push_field();
149+
this->push_row();
150+
}
149151

150152
// Reset
151153
this->current_row = CSVRow(data_ptr, this->data_pos, fields->size());

single_include/csv.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7084,9 +7084,11 @@ namespace csv {
70847084
while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
70857085
this->data_pos++;
70867086

7087-
// End of record -> Write record
7088-
this->push_field();
7089-
this->push_row();
7087+
// End of record -> Write non-empty record
7088+
if (this->field_length > 0 || !this->current_row.empty()) {
7089+
this->push_field();
7090+
this->push_row();
7091+
}
70907092

70917093
// Reset
70927094
this->current_row = CSVRow(data_ptr, this->data_pos, fields->size());

single_include_test/csv.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7084,9 +7084,11 @@ namespace csv {
70847084
while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
70857085
this->data_pos++;
70867086

7087-
// End of record -> Write record
7088-
this->push_field();
7089-
this->push_row();
7087+
// End of record -> Write non-empty record
7088+
if (this->field_length > 0 || !this->current_row.empty()) {
7089+
this->push_field();
7090+
this->push_row();
7091+
}
70907092

70917093
// Reset
70927094
this->current_row = CSVRow(data_ptr, this->data_pos, fields->size());

0 commit comments

Comments
 (0)