changes cx_strcpy() and cx_strcpy_a() to accept any string

Sun, 21 Dec 2025 11:09:46 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 21 Dec 2025 11:09:46 +0100
changeset 1644
bbe3199e37fc
parent 1643
045894204ca5
child 1645
27037c1b14e0

changes cx_strcpy() and cx_strcpy_a() to accept any string

relates to #789

CHANGELOG file | annotate | diff | comparison | revisions
docs/Writerside/topics/about.md file | annotate | diff | comparison | revisions
docs/Writerside/topics/string.h.md file | annotate | diff | comparison | revisions
src/cx/string.h file | annotate | diff | comparison | revisions
src/string.c file | annotate | diff | comparison | revisions
--- 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()
--- 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()
--- 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).
--- 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
  */
--- 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

mercurial