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

Allow to skip lines from beginning #176

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 16 additions & 1 deletion src/rapidcsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,12 @@ namespace rapidcsv
*/
explicit LineReaderParams(const bool pSkipCommentLines = false,
const char pCommentPrefix = '#',
const bool pSkipEmptyLines = false)
const bool pSkipEmptyLines = false,
const int pSkippedLinesCount = 0)
: mSkipCommentLines(pSkipCommentLines)
, mCommentPrefix(pCommentPrefix)
, mSkipEmptyLines(pSkipEmptyLines)
, mSkippedLinesCount(pSkippedLinesCount)
{
}

Expand All @@ -449,6 +451,11 @@ namespace rapidcsv
* @brief specifies whether to skip empty lines.
*/
bool mSkipEmptyLines;

/**
* @brief specifies the number of lines skipped from the start.
*/
int mSkippedLinesCount;
};

/**
Expand Down Expand Up @@ -1567,6 +1574,14 @@ namespace rapidcsv
int cr = 0;
int lf = 0;

// skip lines from the beginning
std::string line;
for (int i = 0; i < mLineReaderParams.mSkippedLinesCount; ++ i)
{
std::getline(pStream, line);
p_FileLength -= line.size() +1;
}

while (p_FileLength > 0)
{
const std::streamsize toReadLength = std::min<std::streamsize>(p_FileLength, bufLength);
Expand Down
Loading