mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
add ignore_header setup option, add unit tests for parsing by header, add string_view to possible conversion values
This commit is contained in:
@@ -25,15 +25,19 @@ class parser {
|
||||
constexpr static bool quoted_multiline_enabled =
|
||||
multiline::enabled && setup<Matchers...>::quote::enabled;
|
||||
|
||||
constexpr static bool ignore_header = setup<Matchers...>::ignore_header;
|
||||
|
||||
public:
|
||||
parser(const std::string& file_name,
|
||||
const std::string& delim = ss::default_delimiter)
|
||||
: file_name_{file_name}, reader_{file_name_, delim} {
|
||||
if (reader_.file_) {
|
||||
read_line();
|
||||
// TODO if header reading enabled
|
||||
header_ = reader_.get_next_row();
|
||||
// TODO if ignore_header defined ignore first line
|
||||
if constexpr (ignore_header) {
|
||||
ignore_next();
|
||||
} else {
|
||||
header_ = reader_.get_next_row();
|
||||
}
|
||||
} else {
|
||||
set_error_file_not_open();
|
||||
eof_ = true;
|
||||
@@ -102,6 +106,11 @@ public:
|
||||
|
||||
template <typename... Ts>
|
||||
void use_fields(const Ts&... fields_args) {
|
||||
if constexpr (ignore_header) {
|
||||
set_error_header_ignored();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!valid()) {
|
||||
return;
|
||||
}
|
||||
@@ -449,6 +458,18 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_header_ignored() {
|
||||
if constexpr (string_error) {
|
||||
error_.append(file_name_)
|
||||
.append(": \"")
|
||||
.append("the header row is ignored within the setup, it cannot "
|
||||
"be used")
|
||||
.append("\"");
|
||||
} else {
|
||||
error_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_invalid_field(const std::string& field) {
|
||||
if constexpr (string_error) {
|
||||
error_.append(file_name_)
|
||||
|
||||
Reference in New Issue
Block a user