Simple Dynamic Strings library for C, compatible with null-terminated strings
1–10 of 85 posts
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#2Is this a complete drop-in replacement?? If so it could occasionally make my life much easier!
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#3I rarely work with C but when I do I am always reminded at how painful it is to use strings. Is this a complete drop-in replacement?? If so it could occasionally make my life much easier!
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#4I rarely work with C but when I do I am always reminded at how painful it is to use strings. Is this a complete drop-in replacement?? If so it could occasionally make my life much easier!
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#5I rarely work with C but when I do I am always reminded at how painful it is to use strings. Is this a complete drop-in replacement?? If so it could occasionally make my life much easier!
SDS works by allocating a chunk of memory that can fit a header + your string data. The APIs all consume pointers and internally it mutates it's copy of the pointer so it can get at the metadata. So it can be used to generate strings that are passed to other things. I don't think it's easy to use sds operations on other strings in a zero-copy way.
[0]: https://www.fefe.de/libowfat/ [1]: https://www.fefe.de/gatling/
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#6I rarely work with C but when I do I am always reminded at how painful it is to use strings. Is this a complete drop-in replacement?? If so it could occasionally make my life much easier!
aStr("string"); then aMap aFold aConcat, etc, but aAppend(&array,'\0') needs to be done manually if passing to standard str functions. This is so long* or whatever arrays can have the same interface
Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#7Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#8Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#9I tend to use libdjb[0] if I need to use strings in C. Is this library significantly easier? [0] http://www.fefe.de/djb/
(Note: This has not been touched since 2000, use [2] instead)
[1] https://www.fefe.de/libowfat/Re: Simple Dynamic Strings library for C, compatible with null-terminated strings
#10Considering 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 avoiding a couple of .str's is really worth the risk. You definitely have to always keep in mind to never accidentally mix a char* with an sds, for the advantage of slightly cleaner looking code.