3#include "col_names.hpp"
8 CSV_INLINE const std::vector<std::string>& ColNames::get_col_names() const noexcept {
9 return this->col_names;
12 CSV_INLINE void ColNames::set_col_names(
const std::vector<std::string>& cnames) {
13 this->col_names = cnames;
14 this->col_pos.clear();
16 for (
size_t i = 0; i < cnames.size(); i++) {
20 std::string lower(cnames[i]);
21 std::transform(lower.begin(), lower.end(), lower.begin(),
22 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
23 this->col_pos[lower] = i;
25 this->col_pos[cnames[i]] = i;
32 std::string lower(col_name);
33 std::transform(lower.begin(), lower.end(), lower.begin(),
34 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
35 auto pos = this->col_pos.find(lower);
36 return (pos != this->col_pos.end()) ? (int)pos->second :
CSV_NOT_FOUND;
39 auto pos = this->col_pos.find(std::string(col_name));
40 return (pos != this->col_pos.end()) ? (int)pos->second :
CSV_NOT_FOUND;
44 this->_policy = policy;
47 CSV_INLINE size_t ColNames::size() const noexcept {
48 return this->col_names.size();
52 if (i >= this->col_names.size())
53 throw_column_index_out_of_bounds();
55 return this->col_names[i];
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Shared exception message templates and throw helpers.
The all encompassing namespace.
ColumnNamePolicy
Determines how column name lookups are performed.
@ CASE_INSENSITIVE
Case-insensitive match.
constexpr int CSV_NOT_FOUND
Integer indicating a requested column wasn't found.
std::string_view string_view
The string_view class used by this library.
const std::string & operator[](size_t i) const
Retrieve column name by index.
void set_policy(csv::ColumnNamePolicy policy)
Sets the column name lookup policy.