A CSV parser is one of those things that looks trivial until the first file with a comma
inside a quoted field arrives. This one exists because strtok() and
strsep() kept producing awkward behaviour: they are stateful, they do not
know about quoting, and once a separator appears inside quotes the parse is already wrong.
So instead of splitting strings with a library tokeniser, the parser walks the input itself and tracks CSV quoting state as it goes. That single decision is what makes quoted separators, multi-line cells and ragged rows fall out naturally rather than needing special cases.
Data structure
Parsing produces a linked list of rows, each holding a linked list of cells, and then a lookup array of row pointers is built on top. The array gives fast row access; the linked cells allow every row to hold a different number of columns.
Row 0 -> Cell 0 -> Cell 1 -> Cell 2
|
Row 1 -> Cell 0 -> Cell 1 -> Cell 2 -> Cell 3
|
Row 2 -> Cell 0 -> Cell 1
Access is then getCell(row, column), with cell status available for the
three cases that actually bite in practice: an empty cell, a row that does not exist,
and a column that does not exist in a row that does.
What it handles
- Custom separators, not just commas.
- Quoted fields containing the separator.
- Multi-line quoted cells.
- Ragged files, where rows have different numbers of columns.
- Files produced by Excel, which are RFC 4180-ish rather than strictly RFC 4180.
Scope, honestly
It reads the whole file into memory, so the maximum file size is bounded by available RAM. That is a deliberate trade: it keeps the structure simple and the access direct, and it is the wrong choice for a multi-gigabyte export. It also is not trying to replace a large feature-rich CSV library — if you need strict RFC 4180 conformance in every edge case, use one of those.
The repository runs super-linter, a C/C++ build workflow and CodeQL on every push, which matters more than usual for a parser: most of the interesting bugs in C are in the boundary handling.
Using it
There is no GUI and no package to install. Clone the repository, build it with the included C/C++ workflow, and link the source into your project — there is nothing else to pull in.
The source, the issues and the history are in the repository.
View on GitHub →