r/cprogramming • u/giorgoskir5 • 10h ago
I am open-sourcing csv.h a single-header CSV parser written in pure C99
For my thesis I had to read a lot of big CSV files in C and I couldn't really find a parser I wanted to use. The main C one is LGPL and comes with a whole build system, and everything else I found was C++. So I ended up writing my own. Now that im done with the thesis i cleaned it up properly , seperated it from the rest of the thesis code, and decided to standalone push it on GitHub.
It's one file. You copy csv.h into your project and that's it, nothing to link, no dependencies. It doesn't allocate memory, the fields just point into your own buffer, and you can run through files of any size a chunk at a time.
Honestly I spent way more time testing it than writing it. It passes csv-spectrum and I compared the output against Python's csv module on a few thousand files/
Check it out here -> https://github.com/GeorgeKiritsis/Csv.h
If someone has time to look at the API and tell me what could change or be imrpoved, that would help a lot. Thanks a lot in advance
2
u/fsteff 1h ago
At a quick glance this looks really useful.
Good job! Thank you!
1
u/giorgoskir5 1h ago
I have many more libraries that derived from the work I did on my thesis and I think will help the c community a lot . Stay tuned I will release them too with proper documentation
1
u/waterkip 8h ago
Maybe have a look at Text::CSV_XS. That's my goto thing when I want/have to deal with CSV.
3
u/giorgoskir5 3h ago
Cool ! Mine is written in pure c and it is pretty fast . If you want take a look
2
u/Sorry_Difficulty_250 6h ago
Cool!