--- a/docs/Writerside/topics/string.h.md Sat Apr 19 11:36:53 2025 +0200 +++ b/docs/Writerside/topics/string.h.md Sat Apr 19 14:43:16 2025 +0200 @@ -39,6 +39,11 @@ cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); +int cx_strcpy(cxmutstr *dest, cxstring source); + +int cx_strcpy_a(const CxAllocator *allocator, + cxmutstr *dest, cxstring source); + void cx_strfree(cxmutstr *str); void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); @@ -56,6 +61,10 @@ and guarantees that the result string is zero-terminated. The function `cx_strdup()` is equivalent to `cx_strdup_a()`, except that it uses the default stdlib allocator. +The functions `cx_strcpy_a()` and `cx_strcpy()` copy the contents of the `source` string to the `dest` string, +and also guarantee zero-termination of the resulting string. +The memory in `dest` is either freshly allocated or re-allocated to fit the size of the string plus the terminator. + Allocated strings are always of type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`. The caller must make sure to use the correct allocator for deallocating a string. It is safe to call these functions multiple times on a given string, as the pointer will be nulled and the length set to zero.