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

Add ability to parse headers easier #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add ability to parse headers easier #108

wants to merge 3 commits into from

Conversation

ribtoks
Copy link

@ribtoks ribtoks commented Jul 7, 2020

What is this PR trying to accomplish?

When you don't know the header names in advance, you cannot use this great library. This PR introduces a helper that allows to use a workaround for setting column names after the header was read.

How is this PR trying to accomplish said thing?

I added an internal array of column names that gets filled when we read the header. After this we can use a trick to reuse this column names for actual reading using set_header_from_self().

How is this PR tested?

Manually and as part of a test suite in a different project.

Additional context

Illustration of how it is used:

io::CSVReader<COLUMNS_COUNT,
            io::trim_chars<' ', '\t'>,
            io::double_quote_escape<',', '\"'>,
            io::ignore_overflow,
            io::single_and_empty_line_comment<'%'>> csvReader(filepath);
// CsvCallHelper is just a C++ templates expander, it does not matter for this PR
CsvCallHelper<decltype(csvReader)> callHelper(csvReader);
std::vector<std::string> fakeColumns(COLUMNS_COUNT);
csvReader.next_line();
callHelper.ReadHeader<io::ignore_column, COLUMNS_COUNT>(io::ignore_missing_column | io::ignore_extra_column, fakeColumns);

csvReader.set_header_from_self();
std::vector<std::string> columns(COLUMNS_COUNT);
while (callHelper.ReadRow<COLUMNS_COUNT>(columns)) {
   // ...
}

@ben-strasser
Copy link
Owner

I do not understand what you are trying to accomplish. Have you tried calling next_line, parsing that and then using set_header?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants