8 /* Include collection library headers */
9 #include <derp/common.h>
10 #include <derp/vector.h>
12 /* Forward declarations */
13 typedef struct csv_parser csv_parser_t;
14 typedef struct csv_record csv_record_t;
19 CSV_ERROR_MEMORY = -1,
21 CSV_ERROR_INVALID_PARAMETER = -3,
25 /* Error information structure */
27 const char *message; /* Error message (valid until next parse operation) */
28 int line; /* Line number where error occurred (1-based, 0 if unknown) */
29 int column; /* Column number where error occurred (1-based, 0 if unknown) */
30 bool has_location; /* Whether line/column information is available */
33 /* CSV record structure - represents a single row in the CSV */
35 vector *fields; /* Vector of char* field values */
38 /* Parser (opaque, stateful - maintains error state between operations) */
42 * Create a new CSV parser
43 * @note Parser maintains error state; create separate parsers for concurrent use
45 csv_parser_t *csv_parser_create(void);
48 * Free a CSV parser and all associated memory
50 void csv_parser_destroy(csv_parser_t *parser);
53 * Parse CSV data from a string
54 * @note Sets *records to NULL on failure
55 * @return Vector of csv_record_t* on success, NULL on failure
57 csv_error_t csv_parser_parse_string(csv_parser_t *parser, const char *input, vector **records);
60 * Parse CSV data from a file
61 * @note Sets *records to NULL on failure
62 * @note Advances file position to end of parsed content
63 * @return Vector of csv_record_t* on success, NULL on failure
65 csv_error_t csv_parser_parse_file(csv_parser_t *parser, FILE *file, vector **records);
68 * Get detailed error information from the parser
69 * @note Message pointer is valid until the next parse operation
71 csv_error_info_t csv_parser_get_error_info(csv_parser_t *parser);
74 * Convert error code to human-readable string
76 const char *csv_error_string(csv_error_t error);
78 #endif /* CSV_PARSER_H */