src/ucx/cx/string.h

changeset 613
b649d66c433e
parent 582
82b60a8dd55c
child 621
956c03c25edd
--- a/src/ucx/cx/string.h	Wed Jun 25 21:00:29 2025 +0200
+++ b/src/ucx/cx/string.h	Mon Jul 21 22:22:46 2025 +0200
@@ -167,6 +167,8 @@
  *
  * The length is implicitly inferred by using a call to @c strlen().
  *
+ * When @c NULL is passed, the length will be set to zero.
+ *
  * @note the wrapped string will share the specified pointer to the string.
  * If you do want a copy, use cx_strdup() on the return value of this function.
  *
@@ -177,7 +179,6 @@
  *
  * @see cx_mutstrn()
  */
-cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
 cx_attr_export
@@ -212,6 +213,8 @@
  *
  * The length is implicitly inferred by using a call to @c strlen().
  *
+ * When @c NULL is passed, the length will be set to zero.
+ *
  * @note the wrapped string will share the specified pointer to the string.
  * If you do want a copy, use cx_strdup() on the return value of this function.
  *
@@ -222,7 +225,6 @@
  *
  * @see cx_strn()
  */
-cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
 cx_attr_export
@@ -263,6 +265,10 @@
 static inline cxstring cx_strcast(cxstring str) {
     return str;
 }
+cx_attr_nodiscard
+static inline cxstring cx_strcast(const char *str) {
+    return cx_str(str);
+}
 extern "C" {
 #else
 /**
@@ -287,6 +293,17 @@
 }
 
 /**
+ * Internal function, do not use.
+ * @param str
+ * @return
+ * @see cx_strcast()
+ */
+cx_attr_nodiscard
+static inline cxstring cx_strcast_z(const char *str) {
+    return cx_str(str);
+}
+
+/**
 * Casts a mutable string to an immutable string.
 *
 * Does nothing for already immutable strings.
@@ -300,8 +317,9 @@
 */
 #define cx_strcast(str) _Generic((str), \
         cxmutstr: cx_strcast_m, \
-        cxstring: cx_strcast_c) \
-        (str)
+        cxstring: cx_strcast_c, \
+        const char*: cx_strcast_z, \
+        char *: cx_strcast_z) (str)
 #endif
 
 /**

mercurial