csvpp 1.2.0
CSV parsing / writing libraries
|
CSV Reader / parser. More...
Typedefs | |
typedef struct CSV_reader | CSV_reader |
Functions | |
CSV_reader * | CSV_reader_init_from_filename (const char *filename) |
Create a new CSV_reader object parsing from a file. | |
CSV_reader * | CSV_reader_init_from_file (FILE *file) |
Create a new CSV_reader object parsing from a FILE *. | |
CSV_reader * | CSV_reader_init_from_str (const char *input) |
Create a new CSV_reader object parsing from an in-memory string. | |
void | CSV_reader_free (CSV_reader *reader) |
Free a CSV_reader object. | |
void | CSV_reader_set_delimiter (CSV_reader *reader, const char delimiter) |
Change delimiter character. | |
void | CSV_reader_set_quote (CSV_reader *reader, const char quote) |
Change the quote character. | |
void | CSV_reader_set_lenient (CSV_reader *reader, const bool lenient) |
Enable / disable lenient parsing. | |
char * | CSV_reader_read_field (CSV_reader *reader) |
Read a single field. | |
CSV_status | CSV_reader_read_v (CSV_reader *reader,...) |
Reads fields into variadic arguments. | |
CSV_row * | CSV_reader_read_row (CSV_reader *reader) |
Read the current row from the CSV file and advance to the next. | |
CSV_status | CSV_reader_read_row_ptr (CSV_reader *reader, char ***fields, size_t *num_fields) |
Read a row into an array of strings. | |
bool | CSV_reader_eof (const CSV_reader *reader) |
Check for end of input. | |
bool | CSV_reader_end_of_row (const CSV_reader *reader) |
Check for end of current row. | |
const char * | CSV_reader_get_error_msg (const CSV_reader *reader) |
Get message for last error. | |
CSV_status | CSV_reader_get_error (const CSV_reader *reader) |
Get error code for last error. | |
CSV Reader / parser.
By default, parses according to RFC 4180 rules, and will stop with an 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.
Contains both row-wise and field-wise methods. Mixing these 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.
bool CSV_reader_end_of_row | ( | const CSV_reader * | reader | ) |
Check for end of current row.
true
if no fields remain in the current row bool CSV_reader_eof | ( | const CSV_reader * | reader | ) |
Check for end of input.
true
if no data remains to be read void CSV_reader_free | ( | CSV_reader * | reader | ) |
Free a CSV_reader object.
Closes the file if created with CSV_reader_init_from_filename
CSV_status CSV_reader_get_error | ( | const CSV_reader * | reader | ) |
Get error code for last error.
const char * CSV_reader_get_error_msg | ( | const CSV_reader * | reader | ) |
Get message for last error.
CSV_reader * CSV_reader_init_from_file | ( | FILE * | file | ) |
Create a new CSV_reader object parsing from a FILE *.
file | FILE * opened in read mode. Caller remains responsible to call fclose on the file use |
CSV_reader * CSV_reader_init_from_filename | ( | const char * | filename | ) |
Create a new CSV_reader object parsing from a file.
filename | Path to file |
CSV_reader * CSV_reader_init_from_str | ( | const char * | input | ) |
Create a new CSV_reader object parsing from an in-memory string.
input | String to read from. Caller remains responsible to free the string after use |
char * CSV_reader_read_field | ( | CSV_reader * | reader | ) |
Read a single field.
Check CSV_reader_end_of_row() to see if this is the last field in the current row
free()
CSV_row * CSV_reader_read_row | ( | CSV_reader * | reader | ) |
Read the current row from the CSV file and advance to the next.
CSV_status CSV_reader_read_row_ptr | ( | CSV_reader * | reader, |
char *** | fields, | ||
size_t * | num_fields ) |
Read a row into an array of strings.
If fields
is null, this will allocate a new array (and pass ownership to the caller), and return the final size into num_fields
.
Otherwise, it overwrites fields
contents with strings (owned by caller) up to the limit specified in num_fields, discarding any fields remaining until the end of the row
[in,out] | fields | Pointer to string array to write fields into. Caller must free all strings returned in the array. If NULL is passed, a new array will be allocated and returned by this call. Caller should free this array as well as the strings within |
[in,out] | num_fields | Pointer to size of fields .If NULL is passed to fields , the size of the new array returned into fields will be returned into num_fields |
CSV_status CSV_reader_read_v | ( | CSV_reader * | reader, |
... ) |
Reads fields into variadic arguments.
[out] | ... | char** variables to read into. Last argument must be NULL If more parameters are passed than there are fields remaining, the remaining parameters will be set to NULL |
void CSV_reader_set_delimiter | ( | CSV_reader * | reader, |
const char | delimiter ) |
Change delimiter character.
delimiter | New delimiter character |
void CSV_reader_set_lenient | ( | CSV_reader * | reader, |
const bool | lenient ) |
Enable / disable lenient parsing.
Lenient parsing will attempt to ignore syntax errors in CSV input.
void CSV_reader_set_quote | ( | CSV_reader * | reader, |
const char | quote ) |
Change the quote character.
quote | New quote character |