|
Vince's CSV Parser
|
Data structure for representing CSV rows. More...
#include <csv_row.hpp>
Classes | |
| class | iterator |
| A random access iterator over the contents of a CSV row. More... | |
Public Types | |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| A reverse iterator over the contents of a CSVRow. | |
Public Member Functions | |
| CSVRow (internals::RawCSVDataPtr _data) | |
| Construct a CSVRow view over parsed row storage. | |
| CSVRow (internals::RawCSVDataPtr _data, size_t _data_start, size_t _field_bounds) | |
| CSVRow (internals::RawCSVDataPtr _data, size_t _data_start, size_t _field_bounds, size_t _row_length) | |
| CONSTEXPR bool | empty () const noexcept |
| Indicates whether row is empty or not. | |
| CONSTEXPR size_t | size () const noexcept |
| Return the number of fields in this row. | |
Value Retrieval | |
| CSVField | operator[] (size_t n) const |
| Return a CSVField object corrsponding to the nth value in the row. | |
| CSVField | operator[] (csv::string_view) const |
| Retrieve a value by its associated column name. | |
| std::string | to_json (const std::vector< std::string > &subset={}) const |
| Convert a CSV row to a JSON object, i.e. | |
| std::string | to_json_array (const std::vector< std::string > &subset={}) const |
| Convert a CSV row to a JSON array, i.e. | |
| std::vector< std::string > | get_col_names () const |
| Retrieve this row's associated column names. | |
| std::unordered_map< std::string, std::string > | to_unordered_map () const |
| Convert this CSVRow into an unordered map. | |
| std::unordered_map< std::string, std::string > | to_unordered_map (const std::vector< std::string > &subset) const |
| Convert a selected subset of columns into an unordered map. | |
| auto | to_sv_range () const |
| Convert this CSVRow into a std::ranges::input_range of string_views. | |
| operator std::vector< std::string > () const | |
Convert this row into a std::vector<std::string>. | |
| 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, up to (but not including) the trailing newline character. | |
Iterators | |
Each iterator points to a CSVField object. | |
| iterator | begin () const |
| Return an iterator pointing to the first field. | |
| iterator | end () const noexcept |
| Return an iterator pointing to just after the end of the CSVRow. | |
| reverse_iterator | rbegin () const noexcept |
| reverse_iterator | rend () const |
Data structure for representing CSV rows.
Definition at line 264 of file csv_row.hpp.
| using csv::CSVRow::reverse_iterator = std::reverse_iterator<iterator> |
A reverse iterator over the contents of a CSVRow.
Definition at line 376 of file csv_row.hpp.
|
inline |
Construct a CSVRow view over parsed row storage.
Definition at line 271 of file csv_row.hpp.
|
inline |
Definition at line 272 of file csv_row.hpp.
|
inline |
Definition at line 274 of file csv_row.hpp.
| CSVRow::iterator csv::CSVRow::begin | ( | ) | const |
Return an iterator pointing to the first field.
Definition at line 138 of file csv_row.cpp.
|
inlinenoexcept |
Indicates whether row is empty or not.
Definition at line 278 of file csv_row.hpp.
|
noexcept |
Return an iterator pointing to just after the end of the CSVRow.
Definition at line 147 of file csv_row.cpp.
|
inline |
Retrieve this row's associated column names.
Definition at line 291 of file csv_row.hpp.
| csv::CSVRow::operator std::vector< std::string > | ( | ) | const |
Convert this row into a std::vector<std::string>.
This conversion is primarily intended for write-side workflows, such as reordering or selecting columns before forwarding the row to CSVWriter.
operator[] because it materializes all fields as owning strings. | CSVField csv::CSVRow::operator[] | ( | csv::string_view | col_name | ) | const |
Retrieve a value by its associated column name.
If the column specified can't be round, a runtime error is thrown.
Definition at line 48 of file csv_row.cpp.
| CSVField csv::CSVRow::operator[] | ( | size_t | n | ) | const |
Return a CSVField object corrsponding to the nth value in the row.
std::runtime_error if n is invalid.Definition at line 37 of file csv_row.cpp.
|
noexcept |
Return a string_view of the raw bytes of this row as they appear in the underlying parse buffer, up to (but not including) the trailing newline character.
Definition at line 66 of file csv_row.cpp.
|
noexcept |
Definition at line 151 of file csv_row.cpp.
| CSVRow::reverse_iterator csv::CSVRow::rend | ( | ) | const |
Definition at line 155 of file csv_row.cpp.
|
inlinenoexcept |
Return the number of fields in this row.
Definition at line 281 of file csv_row.hpp.
| std::string csv::CSVRow::to_json | ( | const std::vector< std::string > & | subset = {} | ) | const |
Convert a CSV row to a JSON object, i.e.
{"col1":"value1","col2":"value2"}
subset empty to include the row's original columns. Definition at line 195 of file csv_row_json.cpp.
| std::string csv::CSVRow::to_json_array | ( | const std::vector< std::string > & | subset = {} | ) | const |
Convert a CSV row to a JSON array, i.e.
["value1","value2",...]
subset empty to include all columns. Definition at line 232 of file csv_row_json.cpp.
|
inline |
Convert this CSVRow into a std::ranges::input_range of string_views.
Definition at line 307 of file csv_row.hpp.
| std::unordered_map< std::string, std::string > csv::CSVRow::to_unordered_map | ( | ) | const |
Convert this CSVRow into an unordered map.
Build a map from column names to values for a given row.
The keys are the column names and the values are the corresponding field values.
Definition at line 78 of file csv_row.cpp.
| std::unordered_map< std::string, std::string > csv::CSVRow::to_unordered_map | ( | const std::vector< std::string > & | subset | ) | const |
Convert a selected subset of columns into an unordered map.
Build a map from a subset of column names to values for a given row.
Definition at line 91 of file csv_row.cpp.