3 ms·
I want C strings that are compatible with string.h. I want some struct that is a pointer to the char array `s’ with size_t `n’. To meaningfully do this, it me
by andrewmcwatters 4y ago
I want C strings that are compatible with string.h.
I want some struct that is a pointer to the char array `s’ with size_t `n’.
To meaningfully do this, it means you need auxiliary functions that you execute after calling string.h functions, or you write wrappers that do this for you after calling the relevant string.h functions.
I’m OK with that.
SDS doesn’t do this. Most other C string libraries like this one basically do what I’m asking for, but not quite.
I don’t want separate structs for reading and writing strings. I just want authors to keep it as simple as possible without diverging too hard from how C strings already work today.
- kevin_thibedeau 4y agoI have a personal lib that works like this. It maintains a simple struct with a start pointer and a one-past-the-end pointer. You can use it to construct a view or point into unused space at the end of a string for building ops. NUL termination is preserved so interop with stdlib is always available. This allows for nicer string handling while always allowing interop with anything expecting a char *. Libraries with their own string implementation always exact a penalty to get a cstr out.