# HG changeset patch # User Mike Becker # Date 1766311786 -3600 # Node ID bbe3199e37fcd15cd26a4b65b325c1af316a99bc # Parent 045894204ca5167aae6649ad2212ab47de6a2d34 changes cx_strcpy() and cx_strcpy_a() to accept any string relates to #789 diff -r 045894204ca5 -r bbe3199e37fc CHANGELOG --- a/CHANGELOG Sat Dec 20 11:11:58 2025 +0100 +++ b/CHANGELOG Sun Dec 21 11:09:46 2025 +0100 @@ -18,6 +18,7 @@ * changes cxBufferTerminate() to automatically shrink the buffer * changes cxBufferTerminate() so that position and size are equal after a successful operation * changes cxBufferPutString() to accept any kind of string that cx_strcast() supports + * changes multiple string.h functions automatically apply cx_strcast() where possible * changes the names of cxDefineDestructor() and cxDefineAdvancedDestructor() to cxSetDestructor() and cxSetdvancedDestructor() * changes the name of cxCollectionCompareFunc() to cxSetCompareFunc() diff -r 045894204ca5 -r bbe3199e37fc docs/Writerside/topics/about.md --- a/docs/Writerside/topics/about.md Sat Dec 20 11:11:58 2025 +0100 +++ b/docs/Writerside/topics/about.md Sun Dec 21 11:09:46 2025 +0100 @@ -45,6 +45,7 @@ * changes cxBufferTerminate() to automatically shrink the buffer * changes cxBufferTerminate() so that position and size are equal after a successful operation * changes cxBufferPutString() to accept any kind of string that cx_strcast() supports +* changes multiple string.h functions automatically apply cx_strcast() where possible * changes the names of cxDefineDestructor() and cxDefineAdvancedDestructor() to cxSetDestructor() and cxSetdvancedDestructor() * changes the name of cxCollectionCompareFunc() to cxSetCompareFunc() diff -r 045894204ca5 -r bbe3199e37fc docs/Writerside/topics/string.h.md --- a/docs/Writerside/topics/string.h.md Sat Dec 20 11:11:58 2025 +0100 +++ b/docs/Writerside/topics/string.h.md Sun Dec 21 11:09:46 2025 +0100 @@ -39,10 +39,10 @@ cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); -int cx_strcpy(cxmutstr *dest, cxstring source); +int cx_strcpy(cxmutstr *dest, AnyStr source); int cx_strcpy_a(const CxAllocator *allocator, - cxmutstr *dest, cxstring source); + cxmutstr *dest, AnyStr source); void cx_strfree(cxmutstr *str); @@ -131,7 +131,7 @@ size_t cx_strlen(size_t count, ...); ``` -The `cx_strcat_a()` function takes `count` UCX strings, +The `cx_strcat_a()` function takes `count` UCX strings (`cxstring` or `cxmutstr`), allocates memory for a concatenation of those strings _with a single allocation_, and copies the contents of the strings to the new memory. `cx_strcat()` is equivalent, except that it uses the [default allocator](allocator.h.md#default-allocator). diff -r 045894204ca5 -r bbe3199e37fc src/cx/string.h --- a/src/cx/string.h Sat Dec 20 11:11:58 2025 +0100 +++ b/src/cx/string.h Sun Dec 21 11:09:46 2025 +0100 @@ -348,10 +348,7 @@ /** * Copies a string. * - * The memory in the @p dest structure is either allocated or re-allocated to fit the entire - * source string, including a zero-terminator. - * - * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. + * Internal function - do not use. * * @param alloc the allocator * @param dest a pointer to the structure where to copy the contents to @@ -359,10 +356,26 @@ * * @retval zero success * @retval non-zero if re-allocation failed + * @see cx_strcpy_a() */ cx_attr_nonnull_arg(1) -CX_EXPORT int cx_strcpy_a(const CxAllocator *alloc, cxmutstr *dest, cxstring src); +CX_EXPORT int cx_strcpy_a_(const CxAllocator *alloc, cxmutstr *dest, cxstring src); +/** + * Copies a string. + * + * The memory in the @p dest structure is either allocated or re-allocated to fit the entire + * source string, including a zero-terminator. + * + * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. + * + * @param alloc (@c CxAllocator*) the allocator + * @param dest (@c cxmutstr*) a pointer to the structure where to copy the contents to + * @param src the source string + * @retval zero success + * @retval non-zero if re-allocation failed + */ +#define cx_strcpy_a(alloc, dest, src) cx_strcpy_a_(alloc, dest, cx_strcast(src)) /** * Copies a string. @@ -373,8 +386,7 @@ * The string in @p dest is guaranteed to be zero-terminated, regardless of whether @p src is. * * @param dest (@c cxmutstr*) a pointer to the structure where to copy the contents to - * @param src (@c cxstring) the source string - * + * @param src the source string * @retval zero success * @retval non-zero if re-allocation failed */ diff -r 045894204ca5 -r bbe3199e37fc src/string.c --- a/src/string.c Sat Dec 20 11:11:58 2025 +0100 +++ b/src/string.c Sun Dec 21 11:09:46 2025 +0100 @@ -64,7 +64,7 @@ str->length = 0; } -int cx_strcpy_a( +int cx_strcpy_a_( const CxAllocator *alloc, cxmutstr *dest, cxstring src