15 while (start < sv.size() && ws_flags[sv[start] +
CHAR_OFFSET]) {
19 size_t end = sv.size();
20 while (end > start && ws_flags[sv[end - 1] +
CHAR_OFFSET]) {
24 return sv.substr(start, end - start);
49 auto & col_names = this->data->col_names;
50 auto col_pos = col_names->index_of(col_name);
55 throw std::runtime_error(
"Can't find a column named " + std::string(col_name));
58 CSV_INLINE CSVRow::operator std::vector<std::string>()
const {
59 std::vector<std::string> ret;
60 for (
size_t i = 0; i < size(); i++)
61 ret.push_back(std::string(this->get_field(i)));
70 const size_t end = full.find(
'\n', data_start);
71 const size_t len = (
end == csv::string_view::npos)
72 ? (full.size() - data_start)
74 return full.substr(data_start, len);
79 std::unordered_map<std::string, std::string> row_map;
80 row_map.reserve(this->
size());
82 for (
size_t i = 0; i < this->
size(); i++) {
83 auto col_name = (*this->data->col_names)[i];
92 const std::vector<std::string>& subset
94 std::unordered_map<std::string, std::string> row_map;
95 row_map.reserve(subset.size());
97 for (
const auto& col_name : subset)
98 row_map[col_name] = this->
operator[](col_name).get<std::string>();
105 return this->get_field_impl(index, this->data);
110 return this->get_field_impl(index, _data);
120 this->_type = internals::data_type(this->sv, &this->value, decimalSymbol);
135#pragma region CSVRow Iterator
152 return std::reverse_iterator<CSVRow::iterator>(this->
end());
156 return std::reverse_iterator<CSVRow::iterator>(this->
begin());
160 CSVRow::iterator::iterator(const CSVRow* _reader,
int _i)
161 : daddy(_reader), data(_reader->data), i(_i) {
162 if (_i < (
int)this->daddy->size())
163 this->field = std::make_shared<CSVField>(
164 CSVField(this->daddy->get_field_safe(_i, this->data)));
166 this->field =
nullptr;
169 CSV_INLINE CSVRow::iterator::reference CSVRow::iterator::operator*()
const {
170 return *(this->field.get());
173 CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->()
const {
177 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
180 if (this->i < (
int)this->daddy->size())
181 this->field = std::make_shared<CSVField>(
182 CSVField(this->daddy->get_field_safe(i, this->data)));
184 this->field =
nullptr;
188 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator++(
int) {
195 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator--() {
198 this->field = std::make_shared<CSVField>(
199 CSVField(this->daddy->get_field_safe(this->i, this->data)));
203 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator--(
int) {
210 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator+(difference_type n)
const {
212 return CSVRow::iterator(this->daddy, i + (
int)n);
215 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator-(difference_type n)
const {
217 return CSVRow::iterator::operator+(-n);
220#pragma endregion CSVRow Iterator
Data type representing individual CSV values.
bool try_parse_decimal(long double &dVal, const char decimalSymbol='.')
Attempts to parse a decimal (or integer) value using the given symbol, returning true if the value is...
T get()
Returns the value casted to the requested type, performing type checking before.
A random access iterator over the contents of a CSV row.
iterator end() const noexcept
Return an iterator pointing to just after the end of the CSVRow.
std::reverse_iterator< iterator > reverse_iterator
A reverse iterator over the contents of a CSVRow.
csv::string_view raw_str() const noexcept
Return a string_view of the raw bytes of this row as they appear in the underlying parse buffer,...
std::unordered_map< std::string, std::string > to_unordered_map() const
Convert this CSVRow into an unordered map.
CONSTEXPR size_t size() const noexcept
Return the number of fields in this row.
CSVField operator[](size_t n) const
Return a CSVField object corrsponding to the nth value in the row.
iterator begin() const
Return an iterator pointing to the first field.
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Defines the data type used for storing information about a CSV row.
The all encompassing namespace.
@ CSV_DOUBLE
Floating point value.
@ CSV_STRING
Non-numeric string.
constexpr unsigned CHAR_OFFSET
Offset to convert char into array index.
nonstd::string_view string_view
The string_view class used by this library.