r/C_Programming • • Oct 21 '26

A string library

Some time ago I was inspired by the string view library to focus on simpler things and do some recreational programming of my own. I had written very little C before, but spent a lot of time reading it, mostly the miniaudio source code, which I think still helped a lot.

cvr_string.h

This is a relatively small one, mostly practice for the next library in this repo. But I would really appreciate some feedback or review on my code.

There are more functions available compared to sv, plus a string type that owns it and can modify it (for now just appending), plus iterators over words, lines, or a delimiter. I tried to make everything as ergonomic as I could.

At the core of the library is also the two way string matching (Crochemore-Perrin) algorithm taken from the rust std library. I did include an explanation into how it works, but mine just follows a practical example. I found theoretical explanations to be too confusing (at least for my brain).

I don't think I am done with the algorithms. I think it may be useful to use different ones depending on the size of the haystack or needle. Plus, it seems like a good place to mess around with SIMD. However, I have no clue how to benchmark in C.

The library is C89 compatible for no other reason that I find it fun and challenging.

14 Upvotes

6 comments sorted by

View all comments

Show parent comment

5

u/Hoxitron Oct 21 '26 edited Oct 21 '26

This project is 100% hand written. AI wasn't used at all in creating it.

3

u/mikeblas Oct 22 '26

Thank you for your disclosure. I have approved your post.