--- a/src/cx/string.h Mon Dec 29 11:21:16 2025 +0100 +++ b/src/cx/string.h Tue Dec 30 13:50:55 2025 +0100 @@ -882,20 +882,46 @@ cxmutstr string, cxstring delim, size_t limit, cxmutstr **output); +#ifdef __cplusplus +CX_CPPDECL size_t cx_strsplit_cpp_(cxstring string, cxstring delim, + size_t limit, cxstring *output) { + return cx_strsplit_(string, delim, limit, output); +} +CX_CPPDECL size_t cx_strsplit_cpp_(cxmutstr string, cxstring delim, + size_t limit, cxmutstr *output) { + return cx_strsplit_m_(string, delim, limit, output); +} +CX_CPPDECL size_t cx_strsplit_a_cpp_(const CxAllocator *allocator, + cxstring string, cxstring delim, size_t limit, cxstring **output) { + return cx_strsplit_a_(allocator, string, delim, limit, output); +} +CX_CPPDECL size_t cx_strsplit_a_cpp_(const CxAllocator *allocator, + cxmutstr string, cxstring delim, size_t limit, cxmutstr **output) { + return cx_strsplit_ma_(allocator, string, delim, limit, output); +} +#define cx_strsplit(string, delim, limit, output) \ + cx_strsplit_cpp_(cx_strcast_m(string), cx_strcast(delim), limit, output) +#define cx_strsplit_a(allocator, string, delim, limit, output) \ + cx_strsplit_a_cpp_(allocator, cx_strcast_m(string), cx_strcast(delim), limit, output) +#else /** * Splits a given string using a delimiter string. * * @note The resulting array contains strings that point to the source * @p string. Use cx_strdup() to get copies. * - * @param string (@c cxstring) the string to split + * @param string the string to split * @param delim the delimiter * @param limit (@c size_t) the maximum number of split items - * @param output (@c cxstring*) a preallocated array of at least @p limit length + * @param output (@c cxstring* or @c cxmutstr*) a preallocated array of at + * least @p limit length * @return the actual number of split items */ #define cx_strsplit(string, delim, limit, output) \ - cx_strsplit_(string, cx_strcast(delim), limit, output) + _Generic(cx_strcast_m(string), \ + cxstring: cx_strsplit_, \ + cxmutstr: cx_strsplit_m_)\ + (cx_strcast_m(string), cx_strcast(delim), limit, output) /** * Splits a given string using a delimiter string. @@ -909,53 +935,19 @@ * @p output and the number returned will be zero. * * @param allocator (@c CxAllocator*) the allocator to use for allocating the resulting array - * @param string (@c cxstring) the string to split + * @param string the string to split * @param delim the delimiter * @param limit (@c size_t) the maximum number of split items - * @param output (@c cxstring**) a pointer where the address of the allocated - * array shall be written to + * @param output (@c cxstring** or @c cxmutstr**) a pointer where the address + * of the allocated array shall be written to * @return the actual number of split items */ #define cx_strsplit_a(allocator, string, delim, limit, output) \ - cx_strsplit_a_(allocator, string, cx_strcast(delim), limit, output) - - -/** - * Splits a given string using a delimiter string. - * - * @note The resulting array contains strings that point to the source - * @p string. Use cx_strdup() to get copies. - * - * @param string (@c cxmutstr) the string to split - * @param delim the delimiter - * @param limit (@c size_t) the maximum number of split items - * @param output (@c cxmutstr*) a preallocated array of at least @p limit length - * @return the actual number of split items - */ -#define cx_strsplit_m(string, delim, limit, output) \ - cx_strsplit_m_(string, cx_strcast(delim), limit, output) - -/** - * Splits a given string using a delimiter string. - * - * The array pointed to by @p output will be allocated by @p allocator. - * - * @note The resulting array contains strings that point to the source - * @p string. Use cx_strdup() to get copies. - * - * @attention If allocation fails, the @c NULL pointer will be written to - * @p output and the number returned will be zero. - * - * @param allocator (@c CxAllocator*) the allocator to use for allocating the resulting array - * @param string (@c cxmutstr) the string to split - * @param delim the delimiter - * @param limit (@c size_t) the maximum number of split items - * @param output (@c cxmutstr**) a pointer where the address of the allocated - * array shall be written to - * @return the actual number of split items - */ -#define cx_strsplit_ma(allocator, string, delim, limit, output) \ - cx_strsplit_ma_(allocator, string, cx_strcast(delim), limit, output) + _Generic(cx_strcast_m(string), \ + cxstring: cx_strsplit_a_, \ + cxmutstr: cx_strsplit_ma_)\ + (allocator, cx_strcast_m(string), cx_strcast(delim), limit, output) +#endif /** * Compares two strings.