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++);
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 * (int)pow(16, (
double)base16_exponent);
163 parsedValue = value_;
189 #pragma region CSVRow Iterator
206 return std::reverse_iterator<CSVRow::iterator>(this->
end());
210 return std::reverse_iterator<CSVRow::iterator>(this->
begin());
214 CSVRow::iterator::iterator(const CSVRow* _reader,
int _i)
215 : daddy(_reader), i(_i) {
216 if (_i < (
int)this->daddy->size())
217 this->field = std::make_shared<CSVField>(
218 this->daddy->operator[](_i));
220 this->field =
nullptr;
223 CSV_INLINE CSVRow::iterator::reference CSVRow::iterator::operator*()
const {
224 return *(this->field.get());
227 CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->()
const {
231 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
234 if (this->i < (
int)this->daddy->size())
235 this->field = std::make_shared<CSVField>(
236 this->daddy->operator[](i));
238 this->field =
nullptr;
242 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator++(
int) {
249 CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator--() {
252 this->field = std::make_shared<CSVField>(
253 this->daddy->operator[](this->i));
257 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator--(
int) {
264 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator+(difference_type n)
const {
266 return CSVRow::iterator(this->daddy, i + (
int)n);
269 CSV_INLINE CSVRow::iterator CSVRow::iterator::operator-(difference_type n)
const {
271 return CSVRow::iterator::operator+(-n);
274 #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...
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.
CONSTEXPR_14 DataType data_type(csv::string_view in, long double *const out, const char decimalSymbol)
Distinguishes numeric from other text values.
ParseFlags
An enum used for describing the significance of each character with respect to CSV parsing.
The all encompassing namespace.
@ CSV_DOUBLE
Floating point value.
@ CSV_STRING
Non-numeric string.
nonstd::string_view string_view
The string_view class used by this library.