13 CSV_DEBUG_ASSERT(format.possible_delimiters.size() == 1);
14 return format.possible_delimiters.front();
18#if CSV_EXCEPTIONS_ENABLED
22 internals::throw_error(error);
29 internals::throw_error(error);
35 this->try_quote(
quote, error);
36 internals::throw_error(error);
42 this->try_trim(whitespace, error);
43 internals::throw_error(error);
48#if CSV_EXCEPTIONS_ENABLED
49 char CSVFormat::get_delim()
const {
53 internals::throw_error(error);
63 if (!validate_characters(delims, this->trim_chars, this->quote_char, error))
return false;
64 this->possible_delimiters = delims;
68 bool CSVFormat::try_quote(
char quote, CSVError& error) {
69 if (!validate_characters(this->possible_delimiters, this->trim_chars,
quote, error))
return false;
70 this->no_quote =
false;
71 this->quote_char =
quote;
75 bool CSVFormat::try_trim(
const std::vector<char>& whitespace, CSVError& error) {
76 if (!validate_characters(this->possible_delimiters, whitespace, this->quote_char, error))
return false;
77 this->trim_chars = whitespace;
83 if (this->possible_delimiters.size() != 1) {
85 this->possible_delimiters.empty() ?
"At least one delimiter is required."
86 : internals::ERROR_MULTIPLE_DELIMITERS);
88 out = this->possible_delimiters.front();
93 this->col_names = names;
95 this->col_names_explicitly_set_ =
true;
100 if (row < 0) this->variable_column_policy = VariableColumnPolicy::KEEP;
103 this->header_explicitly_set_ =
true;
104 this->col_names = {};
105 this->col_names_explicitly_set_ =
false;
109#if CSV_EXCEPTIONS_ENABLED
113 internals::throw_error(error);
120 if (size < internals::CSV_CHUNK_SIZE_FLOOR) {
122 internals::make_chunk_size_error(internals::CSV_CHUNK_SIZE_FLOOR, size));
124 const size_t max_chunk_size = internals::CSV_CHUNK_SIZE_MAX;
125 if (size > max_chunk_size) {
127 internals::make_chunk_size_ceiling_error(max_chunk_size, size));
129 this->_chunk_size = size;
133 bool CSVFormat::validate_characters(
134 const std::vector<char>& candidates,
const std::vector<char>& whitespace,
138 if (candidates.empty()) {
141 const std::set<char> delims(candidates.begin(), candidates.end());
142 const std::set<char> trims(whitespace.begin(), whitespace.end());
143 std::set<char> offenders;
145 for (std::set<char>::const_iterator it = delims.begin(); it != delims.end(); ++it) {
146 if (trims.find(*it) != trims.end()) offenders.insert(*it);
151 if (delims.find(
quote) != delims.end() || trims.find(
quote) != trims.end()) {
152 offenders.insert(
quote);
154 if (!offenders.empty()) {
161 format.possible_delimiters = {
',',
'|',
'\t',
';',
'^' };
The all encompassing namespace.
@ InvalidFormat
Conflicting parsing characters or an unresolved delimiter query.
@ InvalidChunkSize
Configured read-window size is outside the supported byte limits.
A diagnostic whose text remains valid for the lifetime of the error.