Skip to content

Suggestion: Add a "CSV_ABORT" option flag which would cause csv_parse() to stop parsing (set this in the callback) #27

@bobhairgrove

Description

@bobhairgrove

It looks like there isn't any way to stop csv_parse() from running all the way to the end of the data. I am doing input validation in my "notify field" callback function.

If certain errors occur (not errors which would cause csv_parse() to stop anyway, but data validation errors -- such as regular expression matching fails), it would be nice to set some kind of "abort" flag in the csv_parser->options struct member which would be checked within the main parsing loop and return from the function if set (after cleaning up memory allocations, etc.). Since I still have access to the parser struct during processing, I could simply set the additional (to be determined) "CSV_ABORT" flag in the options. Anything else done to the parser struct would probably not work, or end up being very messy, I think.

This would be very useful if the calling code throws a C++ exception, for example -- throwing an exception would not prevent csv_parse() from doing its thing until it runs out of data.

Another use case would be for parsing 1st line field headers. Since the headers are only meaningful to the application using libcsv, and can be missing, any field could theoretically contain embedded newline characters (although they probably shouldn't). libcsv would be able to parse these, and when the first real end-of-line is reached, one might want to stop parsing. Otherwise, using fgets, etc. to look for a new line is bound to fail if any of the headers have such embedded new lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions