add support for any string as a delimiter in all cx_strsplit() variants

Mon, 22 Dec 2025 15:47:59 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 22 Dec 2025 15:47:59 +0100
changeset 1652
db8299984bfe
parent 1651
38b051dea6b1
child 1653
6a842bd49fea

add support for any string as a delimiter in all cx_strsplit() variants

relates to #789

docs/Writerside/topics/mempool.h.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
tests/test_string.c file | annotate | diff | comparison | revisions
--- a/docs/Writerside/topics/mempool.h.md	Mon Dec 22 15:28:07 2025 +0100
+++ b/docs/Writerside/topics/mempool.h.md	Mon Dec 22 15:47:59 2025 +0100
@@ -190,7 +190,7 @@
     for (size_t i = 1 ; i < lc ; i++) {
         if (lines[i].length == 0) continue;
         cxstring fields[3];
-        size_t fc = cx_strsplit(lines[i], cx_str(";"), 3, fields);
+        size_t fc = cx_strsplit(lines[i], ";", 3, fields);
         if (fc != 3) {
             fprintf(stderr, "Syntax error in line %zu.\n", i);
             cxMempoolFree(pool);
--- a/docs/Writerside/topics/string.h.md	Mon Dec 22 15:28:07 2025 +0100
+++ b/docs/Writerside/topics/string.h.md	Mon Dec 22 15:47:59 2025 +0100
@@ -223,18 +223,18 @@
 ```C
 #include <cx/string.h>
 
-size_t cx_strsplit(cxstring string, cxstring delim,
+size_t cx_strsplit(cxstring string, AnyStr delim,
         size_t limit, cxstring *output);
 
 size_t cx_strsplit_a(const CxAllocator *allocator,
-        cxstring string, cxstring delim,
+        cxstring string, AnyStr delim,
         size_t limit, cxstring **output);
 
-size_t cx_strsplit_m(cxmutstr string, cxstring delim,
+size_t cx_strsplit_m(cxmutstr string, AnyStr delim,
         size_t limit, cxmutstr *output);
 
 size_t cx_strsplit_ma(const CxAllocator *allocator,
-        cxmutstr string, cxstring delim,
+        cxmutstr string, AnyStr delim,
         size_t limit, cxmutstr **output);
 ```
 
--- a/src/cx/string.h	Mon Dec 22 15:28:07 2025 +0100
+++ b/src/cx/string.h	Mon Dec 22 15:47:59 2025 +0100
@@ -703,18 +703,86 @@
 /**
  * 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.
+ * Internal function - do not use.
+ *
+ * @param string the string to split
+ * @param delim  the delimiter
+ * @param limit the maximum number of split items
+ * @param output the output array
+ * @return the actual number of split items
+ * @see cx_strsplit()
+ */
+cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
+CX_EXPORT size_t cx_strsplit_(cxstring string, cxstring delim,
+        size_t limit, cxstring *output);
+
+/**
+ * Splits a given string using a delimiter string.
+ *
+ * Internal function - do not use.
+ *
+ * @param allocator the allocator to use for allocating the resulting array
+ * @param string the string to split
+ * @param delim  the delimiter
+ * @param limit the maximum number of split items
+ * @param output the output array
+ * @return the actual number of split items
+ * @see cx_strsplit_a()
+ */
+cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
+CX_EXPORT size_t cx_strsplit_a_(const CxAllocator *allocator,
+        cxstring string, cxstring delim,
+        size_t limit, cxstring **output);
+
+
+/**
+ * Splits a given string using a delimiter string.
+ *
+ * Internal function - do not use.
  *
  * @param string the string to split
  * @param delim  the delimiter
  * @param limit the maximum number of split items
- * @param output a preallocated array of at least @p limit length
+ * @param output the output array
+ * @return the actual number of split items
+ * @see cx_strsplit_m()
+ */
+cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
+CX_EXPORT size_t cx_strsplit_m_(cxmutstr string, cxstring delim,
+        size_t limit, cxmutstr *output);
+
+/**
+ * Splits a given string using a delimiter string.
+ *
+ * Internal function - do not use.
+ *
+ * @param allocator the allocator to use for allocating the resulting array
+ * @param string the string to split
+ * @param delim  the delimiter
+ * @param limit the maximum number of split items
+ * @param output the output array
+ * @return the actual number of split items
+ * @see cx_strsplit_ma()
+ */
+cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
+CX_EXPORT size_t cx_strsplit_ma_(const CxAllocator *allocator,
+        cxmutstr string, cxstring delim, size_t limit,
+        cxmutstr **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 cxstring) 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
  * @return the actual number of split items
  */
-cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
-CX_EXPORT size_t cx_strsplit(cxstring string, cxstring delim,
-        size_t limit, cxstring *output);
+#define cx_strsplit(string, delim, limit, output) \
+        cx_strsplit_(string, cx_strcast(delim), limit, output)
 
 /**
  * Splits a given string using a delimiter string.
@@ -727,18 +795,16 @@
  * @attention If allocation fails, the @c NULL pointer will be written to
  * @p output and the number returned will be zero.
  *
- * @param allocator the allocator to use for allocating the resulting array
- * @param string the string to split
+ * @param allocator (@c CxAllocator*) the allocator to use for allocating the resulting array
+ * @param string (@c cxstring) the string to split
  * @param delim  the delimiter
- * @param limit the maximum number of split items
- * @param output a pointer where the address of the allocated array shall be
- * written to
+ * @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
  * @return the actual number of split items
  */
-cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
-CX_EXPORT size_t cx_strsplit_a(const CxAllocator *allocator,
-        cxstring string, cxstring delim,
-        size_t limit, cxstring **output);
+#define cx_strsplit_a(allocator, string, delim, limit, output) \
+        cx_strsplit_a_(allocator, string, cx_strcast(delim), limit, output)
 
 
 /**
@@ -747,15 +813,14 @@
  * @note The resulting array contains strings that point to the source
  * @p string. Use cx_strdup() to get copies.
  *
- * @param string the string to split
+ * @param string (@c cxmutstr) the string to split
  * @param delim  the delimiter
- * @param limit the maximum number of split items
- * @param output a preallocated array of at least @p limit length
+ * @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
  */
-cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
-CX_EXPORT size_t cx_strsplit_m(cxmutstr string, cxstring delim,
-        size_t limit, cxmutstr *output);
+#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.
@@ -768,18 +833,16 @@
  * @attention If allocation fails, the @c NULL pointer will be written to
  * @p output and the number returned will be zero.
  *
- * @param allocator the allocator to use for allocating the resulting array
- * @param string the string to split
+ * @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 the maximum number of split items
- * @param output a pointer where the address of the allocated array shall be
- * written to
+ * @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
  */
-cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
-CX_EXPORT size_t cx_strsplit_ma(const CxAllocator *allocator,
-        cxmutstr string, cxstring delim, size_t limit,
-        cxmutstr **output);
+#define cx_strsplit_ma(allocator, string, delim, limit, output) \
+        cx_strsplit_ma_(allocator, string, cx_strcast(delim), limit, output)
 
 /**
  * Compares two strings.
--- a/src/string.c	Mon Dec 22 15:28:07 2025 +0100
+++ b/src/string.c	Mon Dec 22 15:47:59 2025 +0100
@@ -326,7 +326,7 @@
     return (cxmutstr) {(char *) result.ptr, result.length};
 }
 
-size_t cx_strsplit(
+size_t cx_strsplit_(
         cxstring string,
         cxstring delim,
         size_t limit,
@@ -384,7 +384,7 @@
     return n;
 }
 
-size_t cx_strsplit_a(
+size_t cx_strsplit_a_(
         const CxAllocator *allocator,
         cxstring string,
         cxstring delim,
@@ -413,27 +413,27 @@
         }
     }
     *output = cxCalloc(allocator, n, sizeof(cxstring));
-    return cx_strsplit(string, delim, n, *output);
+    return cx_strsplit_(string, delim, n, *output);
 }
 
-size_t cx_strsplit_m(
+size_t cx_strsplit_m_(
         cxmutstr string,
         cxstring delim,
         size_t limit,
         cxmutstr *output
 ) {
-    return cx_strsplit(cx_strcast(string),
+    return cx_strsplit_(cx_strcast(string),
                        delim, limit, (cxstring *) output);
 }
 
-size_t cx_strsplit_ma(
+size_t cx_strsplit_ma_(
         const CxAllocator *allocator,
         cxmutstr string,
         cxstring delim,
         size_t limit,
         cxmutstr **output
 ) {
-    return cx_strsplit_a(allocator, cx_strcast(string),
+    return cx_strsplit_a_(allocator, cx_strcast(string),
                          delim, limit, (cxstring **) output);
 }
 
--- a/tests/test_string.c	Mon Dec 22 15:28:07 2025 +0100
+++ b/tests/test_string.c	Mon Dec 22 15:47:59 2025 +0100
@@ -451,91 +451,91 @@
     size_t n;
     CX_TEST_DO {
         // special case: empty string
-        n = cx_strsplit(test, cx_str(""), capa, list);
+        n = cx_strsplit(test, "", capa, list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
 
         // no delimiter occurrence
-        n = cx_strsplit(test, cx_str("z"), capa, list);
+        n = cx_strsplit(test, "z", capa, list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
 
         // partially matching delimiter
-        n = cx_strsplit(test, cx_str("is,not"), capa, list);
+        n = cx_strsplit(test, "is,not", capa, list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
 
         // matching single-char delimiter
-        n = cx_strsplit(test, cx_str(","), capa, list);
+        n = cx_strsplit(test, ",", capa, list);
         CX_TEST_ASSERT(n == 5);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[3], cx_str("csv")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[4], cx_str("string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "is"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[3], "csv"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[4], "string"));
 
         // matching multi-char delimiter
-        n = cx_strsplit(test, cx_str("is"), capa, list);
+        n = cx_strsplit(test, "is", capa, list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str(",a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ","));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], ",a,csv,string"));
 
         // bounded list using single-char delimiter
-        n = cx_strsplit(test, cx_str(","), 3, list);
+        n = cx_strsplit(test, ",", 3, list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "is"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a,csv,string"));
 
         // bounded list using multi-char delimiter
-        n = cx_strsplit(test, cx_str("is"), 2, list);
+        n = cx_strsplit(test, "is", 2, list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ",is,a,csv,string"));
 
         // start with delimiter
-        n = cx_strsplit(test, cx_str("this"), capa, list);
+        n = cx_strsplit(test, "this", capa, list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ",is,a,csv,string"));
 
         // end with delimiter
-        n = cx_strsplit(test, cx_str("string"), capa, list);
+        n = cx_strsplit(test, "string", capa, list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this,is,a,csv,")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this,is,a,csv,"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
 
 
         // end with delimiter exceed bound
-        n = cx_strsplit(cx_str("a,b,c,"), cx_str(","), 3, list);
+        n = cx_strsplit(cx_str("a,b,c,"), ",", 3, list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("a")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("b")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("c,")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "a"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "b"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "c,"));
 
         // exact match
-        n = cx_strsplit(test, cx_str("this,is,a,csv,string"), capa, list);
+        n = cx_strsplit(test, "this,is,a,csv,string", capa, list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
 
         // string to be split is only substring
-        n = cx_strsplit(test, cx_str("this,is,a,csv,string,with,extension"), capa, list);
+        n = cx_strsplit(test, "this,is,a,csv,string,with,extension", capa, list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
 
         // subsequent encounter of delimiter (the string between is empty)
-        n = cx_strsplit(test, cx_str("is,"), capa, list);
+        n = cx_strsplit(test, "is,", capa, list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a,csv,string"));
 
         // call the _m variant just for coverage
         cxmutstr mtest = cx_strdup(test);
         cxmutstr mlist[4];
-        n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist);
+        n = cx_strsplit_m(mtest, "is,", 4, mlist);
         CX_TEST_ASSERT(n == 3);
         CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th"));
         CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], ""));
@@ -555,103 +555,103 @@
     size_t n;
     CX_TEST_DO {
         // special case: empty string
-        n = cx_strsplit_a(alloc, test, cx_str(""), capa, &list);
+        n = cx_strsplit_a(alloc, test, "", capa, &list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
         cxFree(alloc, list);
 
         // no delimiter occurrence
-        n = cx_strsplit_a(alloc, test, cx_str("z"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "z", capa, &list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
         cxFree(alloc, list);
 
         // partially matching delimiter
-        n = cx_strsplit_a(alloc, test, cx_str("is,not"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "is,not", capa, &list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
         cxFree(alloc, list);
 
         // matching single-char delimiter
-        n = cx_strsplit_a(alloc, test, cx_str(","), capa, &list);
+        n = cx_strsplit_a(alloc, test, ",", capa, &list);
         CX_TEST_ASSERT(n == 5);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[3], cx_str("csv")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[4], cx_str("string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "is"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[3], "csv"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[4], "string"));
         cxFree(alloc, list);
 
         // matching multi-char delimiter
-        n = cx_strsplit_a(alloc, test, cx_str("is"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "is", capa, &list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str(",a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ","));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], ",a,csv,string"));
         cxFree(alloc, list);
 
         // bounded list using single-char delimiter
-        n = cx_strsplit_a(alloc, test, cx_str(","), 3, &list);
+        n = cx_strsplit_a(alloc, test, ",", 3, &list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("is")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "is"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a,csv,string"));
         cxFree(alloc, list);
 
         // bounded list using multi-char delimiter
-        n = cx_strsplit_a(alloc, test, cx_str("is"), 2, &list);
+        n = cx_strsplit_a(alloc, test, "is", 2, &list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ",is,a,csv,string"));
         cxFree(alloc, list);
 
         // start with delimiter
-        n = cx_strsplit_a(alloc, test, cx_str("this"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "this", capa, &list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str(",is,a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ",is,a,csv,string"));
         cxFree(alloc, list);
 
         // end with delimiter
-        n = cx_strsplit_a(alloc, test, cx_str("string"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "string", capa, &list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("this,is,a,csv,")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "this,is,a,csv,"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
         cxFree(alloc, list);
 
         // end with delimiter exceed bound
-        n = cx_strsplit_a(alloc, cx_str("a,b,c,"), cx_str(","), 3, &list);
+        n = cx_strsplit_a(alloc, cx_str("a,b,c,"), ",", 3, &list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("a")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("b")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("c,")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "a"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], "b"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "c,"));
         cxFree(alloc, list);
 
         // exact match
-        n = cx_strsplit_a(alloc, test, cx_str("this,is,a,csv,string"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "this,is,a,csv,string", capa, &list);
         CX_TEST_ASSERT(n == 2);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
         cxFree(alloc, list);
 
         // string to be split is only substring
-        n = cx_strsplit_a(alloc, test, cx_str("this,is,a,csv,string,with,extension"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "this,is,a,csv,string,with,extension", capa, &list);
         CX_TEST_ASSERT(n == 1);
         CX_TEST_ASSERT(0 == cx_strcmp(list[0], test));
         cxFree(alloc, list);
 
         // subsequent encounter of delimiter (the string between is empty)
-        n = cx_strsplit_a(alloc, test, cx_str("is,"), capa, &list);
+        n = cx_strsplit_a(alloc, test, "is,", capa, &list);
         CX_TEST_ASSERT(n == 3);
-        CX_TEST_ASSERT(0 == cx_strcmp(list[0], cx_str("th")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[1], cx_str("")));
-        CX_TEST_ASSERT(0 == cx_strcmp(list[2], cx_str("a,csv,string")));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[0], "th"));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[1], ""));
+        CX_TEST_ASSERT(0 == cx_strcmp(list[2], "a,csv,string"));
         cxFree(alloc, list);
 
         // call the _m variant just for coverage
         cxmutstr mtest = cx_strdup(test);
         cxmutstr *mlist;
-        n = cx_strsplit_ma(alloc, mtest, cx_str("is,"), 4, &mlist);
+        n = cx_strsplit_ma(alloc, mtest, "is,", 4, &mlist);
         CX_TEST_ASSERT(n == 3);
         CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th"));
         CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], ""));

mercurial