Skip to content

Commit

Permalink
CSVRow::current_row_start(): track row start position of input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
longqimin committed Sep 14, 2024
1 parent 9f8a721 commit bb63f72
Show file tree
Hide file tree
Showing 7 changed files with 1,108 additions and 1,026 deletions.
1 change: 1 addition & 0 deletions include/internal/basic_csv_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ namespace csv {
this->field_start = UNINITIALIZED_FIELD;
this->field_length = 0;
this->reset_data_ptr();
this->data_ptr->_stream_pos = this->mmap_pos;

// Create memory map
size_t length = std::min(this->source_size - this->mmap_pos, bytes);
Expand Down
1 change: 1 addition & 0 deletions include/internal/basic_csv_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ namespace csv {
if (this->eof()) return;

this->reset_data_ptr();
this->data_ptr->_stream_pos = this->stream_pos;
this->data_ptr->_data = std::make_shared<std::string>();

if (source_size == 0) {
Expand Down
6 changes: 6 additions & 0 deletions include/internal/csv_row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ namespace csv {
internals::ColNamesPtr col_names = nullptr;
internals::ParseFlagMap parse_flags;
internals::WhitespaceMap ws_flags;

/** where in Stream we start */
uint64_t _stream_pos = {};
};

using RawCSVDataPtr = std::shared_ptr<RawCSVData>;
Expand Down Expand Up @@ -324,6 +327,9 @@ namespace csv {
/** Return the number of fields in this row */
CONSTEXPR size_t size() const noexcept { return row_length; }

/** Where in the Stream we start */
size_t current_row_start() const { return data->_stream_pos + data_start; }

/** @name Value Retrieval */
///@{
CSVField operator[](size_t n) const;
Expand Down
Loading

0 comments on commit bb63f72

Please sign in to comment.