ucx/cx/string.h

branch
dav-2
changeset 891
4d58cbcc9efa
parent 889
42cdbf9bbd49
--- a/ucx/cx/string.h	Sun Dec 07 20:16:59 2025 +0100
+++ b/ucx/cx/string.h	Fri Dec 19 17:53:18 2025 +0100
@@ -39,6 +39,8 @@
 #include "common.h"
 #include "allocator.h"
 
+#include <string.h>
+
 /** Expands a UCX string as printf arguments. */
 #define CX_SFMT(s) (int) (s).length, (s).ptr
 
@@ -137,30 +139,6 @@
  */
 typedef struct cx_strtok_ctx_s CxStrtokCtx;
 
-#ifdef __cplusplus
-extern "C" {
-
-/**
- * A literal initializer for an UCX string structure.
- *
- * @param literal the string literal
- */
-#define CX_STR(literal) cxstring{literal, sizeof(literal) - 1}
-
-#else // __cplusplus
-
-/**
- * A literal initializer for an UCX string structure.
- *
- * The argument MUST be a string (const char*) @em literal.
- *
- * @param literal the string literal
- */
-#define CX_STR(literal) ((cxstring){literal, sizeof(literal) - 1})
-
-#endif
-
-
 /**
  * Wraps a mutable string that must be zero-terminated.
  *
@@ -179,7 +157,12 @@
  * @see cx_mutstrn()
  */
 cx_attr_nodiscard cx_attr_cstr_arg(1)
-CX_EXPORT cxmutstr cx_mutstr(char *cstring);
+CX_INLINE cxmutstr cx_mutstr(char *cstring) {
+    cxmutstr str;
+    str.ptr = cstring;
+    str.length = cstring == NULL ? 0 : strlen(cstring);
+    return str;
+}
 
 /**
  * Wraps a string that does not need to be zero-terminated.
@@ -198,7 +181,12 @@
  * @see cx_mutstr()
  */
 cx_attr_nodiscard cx_attr_access_rw(1, 2)
-CX_EXPORT cxmutstr cx_mutstrn(char *cstring, size_t length);
+CX_INLINE cxmutstr cx_mutstrn(char *cstring, size_t length) {
+    cxmutstr str;
+    str.ptr = cstring;
+    str.length = length;
+    return str;
+}
 
 /**
  * Wraps a string that must be zero-terminated.
@@ -218,7 +206,12 @@
  * @see cx_strn()
  */
 cx_attr_nodiscard cx_attr_cstr_arg(1)
-CX_EXPORT cxstring cx_str(const char *cstring);
+CX_INLINE cxstring cx_str(const char *cstring) {
+    cxstring str;
+    str.ptr = cstring;
+    str.length = cstring == NULL ? 0 : strlen(cstring);
+    return str;
+}
 
 
 /**
@@ -238,10 +231,14 @@
  * @see cx_str()
  */
 cx_attr_nodiscard cx_attr_access_r(1, 2)
-CX_EXPORT cxstring cx_strn(const char *cstring, size_t length);
+CX_INLINE cxstring cx_strn(const char *cstring, size_t length) {
+    cxstring str;
+    str.ptr = cstring;
+    str.length = length;
+    return str;
+}
 
 #ifdef __cplusplus
-} // extern "C"
 cx_attr_nodiscard
 CX_CPPDECL cxstring cx_strcast(cxmutstr str) {
     return cx_strn(str.ptr, str.length);
@@ -256,7 +253,7 @@
 }
 cx_attr_nodiscard
 CX_CPPDECL cxstring cx_strcast(const unsigned char *str) {
-    return cx_str(static_cast<const char*>(str));
+    return cx_str(reinterpret_cast<const char*>(str));
 }
 extern "C" {
 #else

mercurial