#include <reader.hpp>
Public Member Functions | |
| Reader (std::istream &input, const anch::csv::Options &options=anch::csv::Options()) | |
| Reader (const Reader &)=delete | |
| bool | next () |
| std::optional< std::size_t > | column (std::string_view name) const noexcept |
| std::span< const std::string_view > | fields () const noexcept |
| std::size_t | size () const noexcept |
| std::string_view | operator[] (std::size_t index) const |
| bool | quoted (std::size_t index) const |
| std::size_t | line () const noexcept |
| const std::vector< std::string > & | header () const noexcept |
| const anch::csv::Options & | options () const noexcept |
CSV records reader (RFC 4180): records are read one by one from a stream, without loading the whole input.
Fields are std::string_view valid until the next call to next (the record buffer is reused: no allocation per field). Quoted fields can contain the separator, doubled quotes and line endings. CRLF and LF line endings are read (CR alone is refused), the last record can have no line ending and an UTF-8 BOM is skipped. An empty field and an empty quoted field ( "" ) are distinguished with quoted .
Errors raise CsvError with the line and the column of the error.
| anch::csv::Reader::Reader | ( | std::istream & | input, |
| const anch::csv::Options & | options = anch::csv::Options() ) |
Reader constructor: the header is read when Options::header is set
| input | the input stream |
| options | the options |
| std::invalid_argument | when separator and quote are equal, or one of them is CR or LF |
| CsvError | on invalid header |
|
delete |
|
noexcept |
Get column index of a header name
| name | the column name |
|
noexcept |
Current record fields
|
noexcept |
Header (empty without Options::header )
|
noexcept |
Physical line where the current record begins (records can have line endings in quoted fields)
1 | bool anch::csv::Reader::next | ( | ) |
| std::string_view anch::csv::Reader::operator[] | ( | std::size_t | index | ) | const |
Current record field
| index | the field index |
|
noexcept |
| bool anch::csv::Reader::quoted | ( | std::size_t | index | ) | const |
Check if a field is quoted: an empty field is an absent value, an empty quoted field ( "" ) an empty string
| index | the field index |
true when field is quoted
|
noexcept |
Current record number of fields