Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ class CsvParser {
// If we're out of tokens to read return whatever's left in the
// field and row buffers. If there's nothing left, return null.
if (maybe_token == nullptr) {
m_state = State::EMPTY;
return !m_fieldbuf.empty() ? Field(std::move(m_fieldbuf))
: Field(FieldType::CSV_END);
if(m_state == State::END_OF_ROW || m_scanposition == 0) {
return Field(FieldType::CSV_END);
}
m_state = State::END_OF_ROW;
return Field(std::move(m_fieldbuf));
}

// Parsing the CSV is done using a finite state machine
Expand Down
2 changes: 1 addition & 1 deletion test/data/empty.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
a,b,c
1,"",""
2,3,4
2,3,""
2 changes: 1 addition & 1 deletion test/data/emptyUnquoted.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
a,b,c
1,,
2,3,4
2,3,
4 changes: 2 additions & 2 deletions test/parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ TEST(CsvParserTest, CommaInQuotes) {
TEST(CsvParserTest, Empty) {
std::ifstream f(TEST_DATA_DIR "/empty.csv");
CsvParser parser(f);
CSV expected = {{"a", "b", "c"}, {"1", "", ""}, {"2", "3", "4"}};
CSV expected = {{"a", "b", "c"}, {"1", "", ""}, {"2", "3", ""}};
EXPECT_EQ(read_all(parser), expected);
}

TEST(CsvParserTest, EmptyUnquoted) {
std::ifstream f(TEST_DATA_DIR "/emptyUnquoted.csv");
CsvParser parser(f);
CSV expected = {{"a", "b", "c"}, {"1", "", ""}, {"2", "3", "4"}};
CSV expected = {{"a", "b", "c"}, {"1", "", ""}, {"2", "3", ""}};
EXPECT_EQ(read_all(parser), expected);
}

Expand Down