Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSVRow::current_row_start(): track row start position of input stream #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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