src/cx/string.h

changeset 1332
02946dc73e6a
parent 1318
12fa1d37fe48
--- a/src/cx/string.h	Tue May 27 22:23:06 2025 +0200
+++ b/src/cx/string.h	Tue May 27 22:23:33 2025 +0200
@@ -263,6 +263,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 +291,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 +315,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