11 CSV_INLINE RawCSVField& CSVFieldList::operator[](
size_t n)
const {
12 const size_t page_no = n / _single_buffer_capacity;
13 const size_t buffer_idx = (page_no < 1) ? n : n % _single_buffer_capacity;
14 return this->buffers[page_no][buffer_idx];
18 RawCSVField * buffer =
new RawCSVField[_single_buffer_capacity];
19 buffers.push_back(buffer);
20 _current_buffer_size = 0;
21 _back = &(buffers.back()[0]);
48 auto & col_names = this->data->col_names;
49 auto col_pos = col_names->index_of(col_name);
54 throw std::runtime_error(
"Can't find a column named " + col_name);
57 CSV_INLINE CSVRow::operator std::vector<std::string>()
const {
58 std::vector<std::string> ret;
59 for (
size_t i = 0; i < size(); i++)
60 ret.push_back(std::string(this->get_field(i)));
69 if (index >= this->
size())
70 throw std::runtime_error(
"Index out of bounds.");
72 const size_t field_index = this->fields_start + index;
73 auto& field = this->data->fields[field_index];
74 auto field_str =
csv::string_view(this->data->data).substr(this->data_start + field.start);
76 if (field.has_double_quote) {
77 auto& value = this->data->double_quote_fields[field_index];
79 bool prev_ch_quote =
false;
80 for (
size_t i = 0; i < field.length; i++) {
81 if (this->data->parse_flags[field_str[i] + 128] == ParseFlags::QUOTE) {
83 prev_ch_quote =
false;
91 value += field_str[i];
98 return field_str.substr(0, field.length);
102 size_t start = 0, end = 0;
105 for (; start < this->sv.size() && this->sv[start] ==
' '; start++);
106 for (end = start; end < this->sv.size() && this->sv[end] !=
' '; end++);
108 unsigned long long int value = 0;
110 size_t digits = (end - start);
111 size_t base16_exponent = digits - 1;
113 if (digits == 0)
return false;
115 for (
const auto& ch : this->sv.substr(start, digits)) {
129 digit =
static_cast<int>(ch -
'0');
159 value += digit * pow(16, base16_exponent);
168 #pragma region CSVRow Iterator
185 return std::reverse_iterator<CSVRow::iterator>(this->
end());
189 return std::reverse_iterator<CSVRow::iterator>(this->
begin());
193 CSVRow::iterator::iterator(const CSVRow* _reader,
int _i)
194 : daddy(_reader), i(_i) {
195 if (_i < (
int)this->daddy->size())
196 this->field = std::make_shared<CSVField>(
197 this->daddy->operator[](_i));
199 this->field =
nullptr;
202 CSV_INLINE CSVRow::iterator::reference CSVRow::iterator::operator*()
const {
203 return *(this->field.get());
206 CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->()
const {
211 return this->field.get();
215 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
218 if (this->i < (
int)this->daddy->size())
219 this->field = std::make_shared<CSVField>(
220 this->daddy->operator[](i));
222 this->field =
nullptr;
226 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator++(
int) {
233 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator--() {
236 this->field = std::make_shared<CSVField>(
237 this->daddy->operator[](this->i));
241 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator--(
int) {
248 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator+(difference_type n)
const {
250 return CSVRow::iterator(this->daddy, i + (
int)n);
253 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator-(difference_type n)
const {
255 return CSVRow::iterator::operator+(-n);
258 #pragma endregion CSVRow Iterator
Data type representing individual CSV values.
bool try_parse_hex(int &parsedValue)
Parse a hexadecimal value, returning false if the value is not hex.
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.
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.
ParseFlags
An enum used for describing the significance of each character with respect to CSV parsing.
The all encompassing namespace.
nonstd::string_view string_view
The string_view class used by this library.