I tend to use libdjb[0] if I need to use strings in C. Is this library significantly easier? [0] http://www.fefe.de/djb/
from the top of that page: (Note: This has not been touched since 2000, use [2] instead) [1] https://www.fefe.de/libowfat/
Simple Dynamic Strings library for C, compatible with null-terminated strings
11–20 of 85 posts
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#12Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#13Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#14Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#15This is a bit on the unsafe side since it blindly trusts user input. At minimum, there needs to be some kind of magic number in the struct header to validate its looking at the right memory. Best case, some kind of pointer accounting. Unfortunately, magic doesn't come for free.
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#16Joking aside, I assume this is char set agnostic?
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#17Just looking at the API "sds" seems to just be a typedef for char* - unfortunately, that means that accidentally passing a char* as an sds into any of the functions will be instant UB and not even a compiler warning. Considering this is C, there is no way to prevent this easily since you can't express a type that is one-way convertible (i.e. sds -> char* ok, char* -> sds not ok). I do have to wonder though if avoidin…
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#18Just looking at the API "sds" seems to just be a typedef for char* - unfortunately, that means that accidentally passing a char* as an sds into any of the functions will be instant UB and not even a compiler warning. Considering this is C, there is no way to prevent this easily since you can't express a type that is one-way convertible (i.e. sds -> char* ok, char* -> sds not ok). I do have to wonder though if avoidin…
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#19UTF support?
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#20UTF support?
I'm also missing stack allocation support, needed for fast short strings. It should be even included in sdsnew, for len < 128.