csvpp 1.2.0
CSV parsing / writing libraries
|
Parses CSV data. More...
#include <csv.hpp>
Classes | |
struct | input_string_t |
Disambiguation tag type. More... | |
class | Iterator |
Iterates over Rows in CSV data. More... | |
class | Row |
Represents a single row of CSV data. More... | |
Public Member Functions | |
Reader (std::istream &input_stream, const char delimiter=',', const char quote='"', const bool lenient = false) | |
Use a std::istream for CSV parsing. | |
Reader (const std::string &filename, const char delimiter=',', const char quote='"', const bool lenient = false) | |
Open a file for CSV parsing. | |
Reader (input_string_t, const std::string &input_data, const char delimiter=',', const char quote='"', const bool lenient = false) | |
Parse CSV from memory. | |
Reader (const Reader &)=delete | |
Reader & | operator= (const Reader &)=delete |
Reader (Reader &&)=default | |
Reader & | operator= (Reader &&)=default |
bool | end_of_row () const |
Check for end of input. | |
bool | eof () const |
Check for end of row. | |
operator bool () | |
void | set_delimiter (const char delimiter) |
Change the delimiter character. | |
void | set_quote (const char quote) |
Change the quote character. | |
void | set_lenient (const bool lenient) |
Enable / disable lenient parsing. | |
Iterator | begin () |
auto | end () |
template<typename T = std::string> | |
T | read_field () |
Read a single field. | |
template<typename T > | |
Reader & | operator>> (T &data) |
Read a single field. | |
template<typename ... Data> | |
void | read_v (Data &... data) |
Reads fields into variadic arguments. | |
Row | get_row () |
Get the current Row. | |
template<typename T = std::string, typename OutputIter > | |
bool | read_row (OutputIter it) |
Reads current row into an output iterator. | |
template<typename T = std::string> | |
std::optional< std::vector< T > > | read_row_vec () |
Reads current row into a std::vector. | |
template<typename ... Args> | |
std::optional< std::tuple< Args... > > | read_row_tuple () |
Reads current row into a tuple. | |
template<typename T = std::string> | |
std::vector< std::vector< T > > | read_all () |
Read entire CSV data into a vector of vectors. | |
Static Public Attributes | |
static constexpr input_string_t | input_string {} |
Disambiguation tag. | |
Parses CSV data.
By default, parses according to RFC 4180 rules, and throws a Parse_error when given non-conformant input. The field delimiter and quote characters may be changed, and there is a lenient parsing option to ignore violations.
Blank rows are ignored and skipped over.
Most methods operate on rows, but some read field-by-field. Mixing row-wise and field-wise methods is not recommended, but is possible. Row-wise methods will act as if the current position is the start of a row, regardless of any fields that have been read from the current row so far.
|
inlineexplicit |
Use a std::istream for CSV parsing.
input_stream | std::istream to read from |
delimiter | Delimiter character |
quote | Quote character |
lenient | Enable lenient parsing (will attempt to read past syntax errors) |
input_stream
must not be destroyed or read from during the lifetime of this Reader
|
inlineexplicit |
Open a file for CSV parsing.
filename | Path to a file to parse |
delimiter | Delimiter character |
quote | Quote character |
lenient | Enable lenient parsing (will attempt to read past syntax errors) |
IO_error | if there is an error opening the file |
|
inline |
Parse CSV from memory.
Use Reader::input_string to distinguish this constructor from the constructor accepting a filename
input_data | std::string containing CSV to parse |
delimiter | Delimiter character |
quote | Quote character |
lenient | Enable lenient parsing (will attempt to read past syntax errors) |
|
inline |
Check for end of input.
true
if the last field in the row has been read
|
inline |
Check for end of row.
true
if no fields remain in the current row
|
inline |
true
if there is more data to be read
|
inline |
Read a single field.
Check end_of_row() to see if this is the last field in the current row
[out] | data | Variable to to write field to |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to type T. Caller may call this again with a different type to try again |
Read entire CSV data into a vector of vectors.
T | Type to convert fields to. Defaults to std::string |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to type T |
|
inline |
Read a single field.
Check end_of_row() to see if this is the last field in the current row
T | Type to convert fields to. Defaults to std::string |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to type T. Caller may call this again with a different type to try again |
|
inline |
Reads current row into an output iterator.
T | Type to convert fields to. Defaults to std::string |
it | An output iterator to receive the row data |
false
if this is the last row Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to type T |
|
inline |
Reads current row into a tuple.
Args | types to convert fields to |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to specified types |
|
inline |
Reads current row into a std::vector.
T | Type to convert fields to. Defaults to std::string |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to type T |
Reads fields into variadic arguments.
[out] | data | Variables to read into. If more parameters are passed than there are fields remaining, the remaining parameters will be default initialized |
Parse_error | if error parsing field (only when not parsing in lenient mode) |
IO_error | if error reading CSV data |
Type_conversion_error | if error converting to specified types |
Change the delimiter character.
delimiter | New delimiter character |
Enable / disable lenient parsing.
Lenient parsing will attempt to ignore syntax errors in CSV input.
lenient | true for lenient parsing |
Change the quote character.
quote | New quote character |
|
inlinestaticconstexpr |