#ifndef CSV_PARSER_H #define CSV_PARSER_H #include #include #include /* Include collection library headers */ #include #include /* Forward declarations */ typedef struct csv_parser csv_parser_t; typedef struct csv_record csv_record_t; /* Error codes */ typedef enum { CSV_SUCCESS = 0, CSV_ERROR_MEMORY = -1, CSV_ERROR_PARSE = -2, CSV_ERROR_INVALID_PARAMETER = -3, CSV_ERROR_IO = -4 } csv_error_t; /* Error information structure */ typedef struct { const char *message; /* Error message (valid until next parse operation) */ int line; /* Line number where error occurred (1-based, 0 if unknown) */ int column; /* Column number where error occurred (1-based, 0 if unknown) */ bool has_location; /* Whether line/column information is available */ } csv_error_info_t; /* CSV record structure - represents a single row in the CSV */ struct csv_record { vector *fields; /* Vector of char* field values */ }; /* Parser (opaque, stateful - maintains error state between operations) */ struct csv_parser; /** * Create a new CSV parser * @note Parser maintains error state; create separate parsers for concurrent use */ csv_parser_t *csv_parser_create(void); /** * Free a CSV parser and all associated memory */ void csv_parser_destroy(csv_parser_t *parser); /** * Parse CSV data from a string * @note Sets *records to NULL on failure * @return Vector of csv_record_t* on success, NULL on failure */ csv_error_t csv_parser_parse_string(csv_parser_t *parser, const char *input, vector **records); /** * Parse CSV data from a file * @note Sets *records to NULL on failure * @note Advances file position to end of parsed content * @return Vector of csv_record_t* on success, NULL on failure */ csv_error_t csv_parser_parse_file(csv_parser_t *parser, FILE *file, vector **records); /** * Get detailed error information from the parser * @note Message pointer is valid until the next parse operation */ csv_error_info_t csv_parser_get_error_info(csv_parser_t *parser); /** * Convert error code to human-readable string */ const char *csv_error_string(csv_error_t error); #endif /* CSV_PARSER_H */