diff options
| author | Tadas Vilkeliskis <vilkeliskis.t@gmail.com> | 2026-06-11 10:00:42 -0400 |
|---|---|---|
| committer | Tadas Vilkeliskis <vilkeliskis.t@gmail.com> | 2026-06-11 10:00:42 -0400 |
| commit | 12007e197832263b9113554bdfea1a8258f179bc (patch) | |
| tree | 2fddfacf735aca531604921eacf9612c17dead2e /src/csv_parser.h | |
| parent | 01cf97e60f970490a94a56d8c82fca320e17fac5 (diff) | |
Fix multiple parsing bugs and add RFC 4180 quote support
- Change nread to size_t to prevent overflow.
- Fix state machine to handle consecutive newlines appropriately.
- Add csv_parser_finish to emit pending trailing fields at EOF.
- Fix nread boundary count on callback errors.
- Add support for quoted fields, including escaped quotes.
- Update and expand test suite to cover new cases and quote parsing.
Diffstat (limited to 'src/csv_parser.h')
| -rw-r--r-- | src/csv_parser.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/csv_parser.h b/src/csv_parser.h index 8c78e8b..267c768 100644 --- a/src/csv_parser.h +++ b/src/csv_parser.h @@ -35,6 +35,8 @@ typedef enum csv_parser_state_t { csvps_line_start = 0, csvps_field_start, csvps_field_value, + csvps_field_quoted_value, + csvps_field_quoted_quote, csvps_field_end, csvps_line_end_begin, csvps_line_end, @@ -48,7 +50,7 @@ typedef struct csv_parser_t { int row; /* csv column */ int col; - uint32_t nread; + size_t nread; /* user data */ void *data; } csv_parser_t; @@ -88,6 +90,12 @@ size_t csv_parser_execute(csv_parser_t *parser, const char *data, size_t data_len); +/** + * Flush any pending state. This is useful when the file ends + * without a trailing newline, to flush the final empty field. + * Returns 0 on success, anything else on error. + */ +int csv_parser_finish(csv_parser_t *parser, const csv_parser_settings_t *settings); #ifdef __cplusplus } |
