From 5ff10462082267f4f9ae2934fa9f72e14b8d807d Mon Sep 17 00:00:00 2001 From: hirohira Date: Tue, 8 Oct 2024 07:36:44 +0900 Subject: [PATCH] fix: reset parser state in StreamParser::next StreamParser::next was missing parsing state reset. It caused incorrectly parsing the first element of the second and later chunks. This commit addresses the issue. --- include/internal/basic_csv_parser.hpp | 3 +++ single_include/csv.hpp | 3 +++ single_include_test/csv.hpp | 3 +++ 3 files changed, 9 insertions(+) diff --git a/include/internal/basic_csv_parser.hpp b/include/internal/basic_csv_parser.hpp index d76b2d9e..1a584d87 100644 --- a/include/internal/basic_csv_parser.hpp +++ b/include/internal/basic_csv_parser.hpp @@ -320,6 +320,9 @@ namespace csv { void next(size_t bytes = ITERATION_CHUNK_SIZE) override { if (this->eof()) return; + // Reset parser state + this->field_start = UNINITIALIZED_FIELD; + this->field_length = 0; this->reset_data_ptr(); this->data_ptr->_data = std::make_shared(); diff --git a/single_include/csv.hpp b/single_include/csv.hpp index 811c8e14..82d76720 100644 --- a/single_include/csv.hpp +++ b/single_include/csv.hpp @@ -6159,6 +6159,9 @@ namespace csv { void next(size_t bytes = ITERATION_CHUNK_SIZE) override { if (this->eof()) return; + // Reset parser state + this->field_start = UNINITIALIZED_FIELD; + this->field_length = 0; this->reset_data_ptr(); this->data_ptr->_data = std::make_shared(); diff --git a/single_include_test/csv.hpp b/single_include_test/csv.hpp index 811c8e14..82d76720 100644 --- a/single_include_test/csv.hpp +++ b/single_include_test/csv.hpp @@ -6159,6 +6159,9 @@ namespace csv { void next(size_t bytes = ITERATION_CHUNK_SIZE) override { if (this->eof()) return; + // Reset parser state + this->field_start = UNINITIALIZED_FIELD; + this->field_length = 0; this->reset_data_ptr(); this->data_ptr->_data = std::make_shared();