16 while (start < sv.size() && ws_flags[sv[start] +
CHAR_OFFSET]) {
20 size_t end = sv.size();
21 while (end > start && ws_flags[sv[end - 1] +
CHAR_OFFSET]) {
25 return sv.substr(start, end - start);
30 return this->make_field(n, this->data);
34 auto & col_names = this->data->col_names;
35 auto col_pos = col_names->index_of(col_name);
40 internals::throw_column_not_found(col_name);
42 CSV_INLINE CSVRow::operator std::vector<std::string>()
const {
43 std::vector<std::string> ret;
44 for (
size_t i = 0; i < size(); i++)
45 ret.push_back(std::string(this->get_field(i)));
55 if (data_end != (std::numeric_limits<size_t>::max)()
56 && data_end >= data_start
57 && data_end <= full.size()) {
58 return full.substr(data_start, data_end - data_start);
61 const size_t end = full.find(
'\n', data_start);
62 const size_t len = (
end == csv::string_view::npos)
63 ? (full.size() - data_start)
65 return full.substr(data_start, len);
70 std::unordered_map<std::string, std::string> row_map;
71 row_map.reserve(this->
size());
73 for (
size_t i = 0; i < this->
size(); i++) {
74 auto col_name = (*this->data->col_names)[i];
83 const std::vector<std::string>& subset
85 std::unordered_map<std::string, std::string> row_map;
86 row_map.reserve(subset.size());
88 for (
const auto& col_name : subset)
89 row_map[col_name] = this->
operator[](col_name).get<std::string>();
96 return this->get_field_impl(index, this->data);
101 return this->get_field_impl(index, _data);
104 CSV_INLINE CSVField CSVRow::make_field(
size_t index,
const internals::RawCSVDataPtr& _data)
const
107 const size_t field_index = this->fields_start + index;
108 if (_data->has_field_scalars() && field_index < _data->field_scalars.size()) {
109 return CSVField(field, _data->field_scalars[field_index]);
112 return CSVField(field);
120 if (this->type_ == DataType::UNKNOWN)
127 double parsed_value = 0;
128 if (!classify_scalar::parse_float(this->sv.data(), this->sv.data() + this->sv.size(), parsed_value, decimalSymbol)) {
141 dVal = this->numeric_value_as_long_double();
150 if (this->type_ == DataType::UNKNOWN)
154 out = this->value_.timestamp;
158 if (this->stores_integral() && this->value_.integer >= 0) {
159 out =
static_cast<std::uint64_t
>(this->value_.integer);
167#pragma region CSVRow Iterator
184 return std::reverse_iterator<CSVRow::iterator>(this->
end());
188 return std::reverse_iterator<CSVRow::iterator>(this->
begin());
192 CSVRow::iterator::iterator(const CSVRow* _reader,
int _i)
193 : daddy(_reader), data(_reader->data), i(_i) {
194 if (_i < (
int)this->daddy->size())
195 this->field = std::make_shared<CSVField>(
196 this->daddy->make_field(_i, this->data));
198 this->field =
nullptr;
201 CSV_INLINE CSVRow::iterator::reference CSVRow::iterator::operator*()
const {
202 return *(this->field.get());
205 CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->()
const {
209 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
212 if (this->i < (
int)this->daddy->size())
213 this->field = std::make_shared<CSVField>(
214 this->daddy->make_field(i, this->data));
216 this->field =
nullptr;
220 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator++(
int) {
227 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator--() {
230 this->field = std::make_shared<CSVField>(
231 this->daddy->make_field(this->i, this->data));
235 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator--(
int) {
242 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator+(difference_type n)
const {
244 return CSVRow::iterator(this->daddy, i + (
int)n);
247 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator-(difference_type n)
const {
249 return CSVRow::iterator::operator+(-n);
252 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator+=(difference_type n) {
257 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator-=(difference_type n) {
262 CSV_INLINE CSVRow::iterator::difference_type CSVRow::iterator::operator-(
const iterator& other)
const noexcept {
263 return this->i - other.i;
266#pragma endregion CSVRow Iterator
Data type representing individual CSV values.
bool try_parse_timestamp(std::uint64_t &out) noexcept
Parse this field as Unix milliseconds.
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 the field at n.
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.
Shared exception message templates and throw helpers.
Defines the data type used for storing information about a CSV row.
The all encompassing namespace.
@ CSV_TIMESTAMP
Timestamp value.
@ CSV_DOUBLE
Floating point value.
@ CSV_STRING
Non-scalar string.
constexpr unsigned CHAR_OFFSET
Offset to convert char into array index.
std::string_view string_view
The string_view class used by this library.