3#include "col_names.hpp"
7 CSV_INLINE std::vector<std::string> ColNames::get_col_names()
const {
8 return this->col_names;
11 CSV_INLINE void ColNames::set_col_names(
const std::vector<std::string>& cnames) {
12 this->col_names = cnames;
13 this->col_pos.clear();
15 for (
size_t i = 0; i < cnames.size(); i++) {
19 std::string lower(cnames[i]);
20 std::transform(lower.begin(), lower.end(), lower.begin(),
21 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
22 this->col_pos[lower] = i;
24 this->col_pos[cnames[i]] = i;
31 std::string lower(col_name);
32 std::transform(lower.begin(), lower.end(), lower.begin(),
33 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
34 auto pos = this->col_pos.find(lower);
35 if (pos != this->col_pos.end())
36 return (
int)pos->second;
40 auto pos = this->col_pos.find(col_name.data());
41 if (pos != this->col_pos.end())
42 return (
int)pos->second;
48 this->_policy = policy;
51 CSV_INLINE size_t ColNames::size() const noexcept {
52 return this->col_names.size();
56 if (i >= this->col_names.size())
57 throw std::out_of_range(
"Column index out of bounds.");
59 return this->col_names[i];
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
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.
nonstd::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.