# HG changeset patch # User Mike Becker # Date 1765626896 -3600 # Node ID 32b82c4242525908db929b9163393d5a73b5ec26 # Parent 814049fb62eec58887680943de77ed6206d04fe2 removes the CX_STR() macro and instead makes the cx_str() inlinable resolves #782 diff -r 814049fb62ee -r 32b82c424252 CHANGELOG --- a/CHANGELOG Sat Dec 13 12:50:37 2025 +0100 +++ b/CHANGELOG Sat Dec 13 12:54:56 2025 +0100 @@ -23,6 +23,7 @@ * fixes that overwriting items with cxMapPut() in a kv-list did not work * fixes that cxReallocate(), cxReallocateArray(), cx_reallocate(), and cx_reallocatearray() were not returning zero after freeing the memory when passed a size of zero + * removes the CX_STR() macro and instead makes the cx_str() inlinable * removes the sort_members feature from CxJsonWriter * removes the source and sink API from properties.h * removes the flush feature from CxBuffer diff -r 814049fb62ee -r 32b82c424252 docs/Writerside/topics/about.md --- a/docs/Writerside/topics/about.md Sat Dec 13 12:50:37 2025 +0100 +++ b/docs/Writerside/topics/about.md Sat Dec 13 12:54:56 2025 +0100 @@ -50,6 +50,7 @@ * fixes that overwriting items with cxMapPut() in a kv-list did not work * fixes that cxReallocate(), cxReallocateArray(), cx_reallocate(), and cx_reallocatearray() were not returning zero after freeing the memory when passed a size of zero +* removes the CX_STR() macro and instead makes the cx_str() inlinable * removes the sort_members feature from CxJsonWriter * removes the source and sink API from properties.h * removes the flush feature from CxBuffer diff -r 814049fb62ee -r 32b82c424252 docs/Writerside/topics/string.h.md --- a/docs/Writerside/topics/string.h.md Sat Dec 13 12:50:37 2025 +0100 +++ b/docs/Writerside/topics/string.h.md Sat Dec 13 12:54:56 2025 +0100 @@ -74,10 +74,9 @@ When you want to use a UCX string in a `printf`-like function, you can use the macro `CX_PRIstr` for the format specifier, and the `CX_SFMT(s)` macro to expand the arguments. -> When you want to convert a string _literal_ into a UCX string, you can also use the `CX_STR(lit)` macro. -> This macro uses the fact that `sizeof(lit)` for a string literal `lit` is always the string length plus one, -> effectively saving an invocation of `strlen()`. -> However, this only works for literals - in all other cases you must use `cx_str()` or `cx_strn`. +> When you want to convert a string _literal_ into a UCX string, you can also use the `cx_str()` function. +> With optimizations turned on, this function gets inlined and optimizes the call to `strlen()` out, giving +> you a `cxstring` structure at zero cost with the length calculated at compile-time. ## Comparison @@ -294,10 +293,10 @@ cxstring str = cx_str("an,arbitrarily;||separated;string"); // create the context -CxStrtokCtx ctx = cx_strtok(str, CX_STR(","), 10); +CxStrtokCtx ctx = cx_strtok(str, ",", 10); // add two more delimters -cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; +cxstring delim_more[2] = {cx_str("||"), cx_str(";")}; cx_strtok_delim(&ctx, delim_more, 2); // iterate over the tokens diff -r 814049fb62ee -r 32b82c424252 src/cx/json.h --- a/src/cx/json.h Sat Dec 13 12:50:37 2025 +0100 +++ b/src/cx/json.h Sat Dec 13 12:54:56 2025 +0100 @@ -1366,6 +1366,18 @@ */ #define cxJsonObjRemove(value, name) cx_json_obj_remove(value, cx_strcast(name)) +/** + * Performs a deep comparison of two JSON values. + * + * The order of object members is ignored during comparison. + * + * @param json the JSON value + * @param other the other JSON value that the JSON value is compared to + * @retval zero the values are equal (except for ordering of object members) + * @retval non-zero the values differ + */ +CX_EXPORT int cxJsonCompare(const CxJsonValue *json, const CxJsonValue *other); + #ifdef __cplusplus } #endif diff -r 814049fb62ee -r 32b82c424252 src/cx/string.h --- a/src/cx/string.h Sat Dec 13 12:50:37 2025 +0100 +++ b/src/cx/string.h Sat Dec 13 12:54:56 2025 +0100 @@ -39,6 +39,8 @@ #include "common.h" #include "allocator.h" +#include + /** 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); diff -r 814049fb62ee -r 32b82c424252 src/json.c --- a/src/json.c Sat Dec 13 12:50:37 2025 +0100 +++ b/src/json.c Sat Dec 13 12:54:56 2025 +0100 @@ -111,8 +111,8 @@ ttype = CX_JSON_TOKEN_STRING; } else { cxstring s = cx_strcast(str); - if (!cx_strcmp(s, CX_STR("true")) || !cx_strcmp(s, CX_STR("false")) - || !cx_strcmp(s, CX_STR("null"))) { + if (!cx_strcmp(s, "true") || !cx_strcmp(s, "false") + || !cx_strcmp(s, "null")) { ttype = CX_JSON_TOKEN_LITERAL; } else { ttype = token_numbertype(str.ptr, str.length); @@ -678,9 +678,9 @@ if ((vbuf = json_create_value(json, CX_JSON_LITERAL)) == NULL) { return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE } - if (0 == cx_strcmp(cx_strcast(token.content), cx_str("true"))) { + if (0 == cx_strcmp(token.content, "true")) { vbuf->literal = CX_JSON_TRUE; - } else if (0 == cx_strcmp(cx_strcast(token.content), cx_str("false"))) { + } else if (0 == cx_strcmp(token.content, "false")) { vbuf->literal = CX_JSON_FALSE; } else { vbuf->literal = CX_JSON_NULL; diff -r 814049fb62ee -r 32b82c424252 src/string.c --- a/src/string.c Sat Dec 13 12:50:37 2025 +0100 +++ b/src/string.c Sat Dec 13 12:54:56 2025 +0100 @@ -46,28 +46,6 @@ #define cx_strcasecmp_impl strncasecmp #endif -cxmutstr cx_mutstr(char *cstring) { - return (cxmutstr) {cstring, cstring == NULL ? 0 : strlen(cstring)}; -} - -cxmutstr cx_mutstrn( - char *cstring, - size_t length -) { - return (cxmutstr) {cstring, length}; -} - -cxstring cx_str(const char *cstring) { - return (cxstring) {cstring, cstring == NULL ? 0 : strlen(cstring)}; -} - -cxstring cx_strn( - const char *cstring, - size_t length -) { - return (cxstring) {cstring, length}; -} - void cx_strfree(cxmutstr *str) { if (str == NULL) return; cxFreeDefault(str->ptr); diff -r 814049fb62ee -r 32b82c424252 tests/test_hash_map.c --- a/tests/test_hash_map.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_hash_map.c Sat Dec 13 12:54:56 2025 +0100 @@ -246,11 +246,11 @@ CxMap *map = cxHashMapCreate(allocator, sizeof(cxstring), 8); // define some strings - cxstring s1 = CX_STR("this"); - cxstring s2 = CX_STR("is"); - cxstring s3 = CX_STR("a"); - cxstring s4 = CX_STR("test"); - cxstring s5 = CX_STR("setup"); + cxstring s1 = cx_str("this"); + cxstring s2 = cx_str("is"); + cxstring s3 = cx_str("a"); + cxstring s4 = cx_str("test"); + cxstring s5 = cx_str("setup"); // put them into the map cxMapPut(map, "s1", &s1); @@ -292,8 +292,8 @@ CX_TEST(test_hash_map_integer_keys) { CxMap *map = cxHashMapCreateSimple(sizeof(cxstring)); CX_TEST_DO { - cxstring s1 = CX_STR("hello"); - cxstring s2 = CX_STR("world"); + cxstring s1 = cx_str("hello"); + cxstring s2 = cx_str("world"); cxMapPut(map, UINT32_C(70875), &s1); cxMapPut(map, UINT64_C(5785133750), &s2); diff -r 814049fb62ee -r 32b82c424252 tests/test_json.c --- a/tests/test_json.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_json.c Sat Dec 13 12:54:56 2025 +0100 @@ -1254,7 +1254,7 @@ cxJsonObjPutLiteral(obj, "bool", CX_JSON_FALSE); cxJsonObjPutNumber(obj, "int", 47); // purposely use PutNumber to put an int CxJsonValue *strings = cxJsonObjPutArr(obj, "strings"); - cxJsonArrAddCxStrings(strings, (cxstring[]) {CX_STR("hello"), CX_STR("world")}, 2); + cxJsonArrAddCxStrings(strings, (cxstring[]) {cx_str("hello"), cx_str("world")}, 2); CxJsonValue *nested = cxJsonObjPutObj(obj, "nested"); CxJsonValue *objects = cxJsonObjPutArr(nested, "objects"); CxJsonValue *obj_in_arr[2] = {cxJsonCreateObj(allocator), cxJsonCreateObj(allocator)}; diff -r 814049fb62ee -r 32b82c424252 tests/test_kv_list.c --- a/tests/test_kv_list.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_kv_list.c Sat Dec 13 12:54:56 2025 +0100 @@ -594,7 +594,7 @@ // removing the element CX_TEST_ASSERT(0 == cxMapRemove(map, cx_strn(key->data, key->len))); key = cxKvListGetKey(list, 1); - CX_TEST_ASSERT(0 == cx_strcmp(CX_STR("efg"), cx_strn(key->data, key->len))); + CX_TEST_ASSERT(0 == cx_strcmp("efg", cx_strn(key->data, key->len))); // remove the key of element CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); diff -r 814049fb62ee -r 32b82c424252 tests/test_properties.c --- a/tests/test_properties.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_properties.c Sat Dec 13 12:54:56 2025 +0100 @@ -671,8 +671,8 @@ CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); CX_TEST_ASSERT(cxMapSize(map) == 2); - cxstring v1 = CX_STR("value"); - cxstring v2 = CX_STR("value2"); + cxstring v1 = cx_str("value"); + cxstring v2 = cx_str("value2"); CX_TEST_ASSERT(cx_strcmp_p(cxMapGet(map, "test"), &v1) == 0); CX_TEST_ASSERT(cx_strcmp_p(cxMapGet(map, "test2"), &v2) == 0); diff -r 814049fb62ee -r 32b82c424252 tests/test_string.c --- a/tests/test_string.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_string.c Sat Dec 13 12:54:56 2025 +0100 @@ -39,7 +39,7 @@ #str " is not zero terminated") CX_TEST(test_string_construct) { - cxstring s1 = CX_STR("1234"); + cxstring s1 = cx_str("1234"); cxstring s2 = cx_strn("abcd", 2); cxmutstr s3 = cx_mutstr((char *) "1234"); cxmutstr s4 = cx_mutstrn((char *) "abcd", 2); @@ -105,7 +105,7 @@ } CX_TEST(test_strdup) { - cxstring str = CX_STR("test"); + cxstring str = cx_str("test"); cxmutstr dup = cx_strdup(str); CX_TEST_DO { CX_TEST_ASSERT(dup.length == str.length); @@ -116,7 +116,7 @@ } CX_TEST(test_strdup_shortened) { - cxstring str = CX_STR("test"); + cxstring str = cx_str("test"); str.length = 2; cxmutstr dup = cx_strdup(str); CX_TEST_DO { @@ -131,35 +131,35 @@ CxTestingAllocator talloc; cx_testing_allocator_init(&talloc); const CxAllocator *alloc = &talloc.base; - cxstring str = CX_STR("test string"); + cxstring str = cx_str("test string"); str.length = 8; // test with a non-zero-terminated source cxmutstr dup; CX_TEST_DO { // copy into a smaller string - dup = cx_strdup_a(alloc, CX_STR("hello")); + dup = cx_strdup_a(alloc, "hello"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into a larger string - dup = cx_strdup_a(alloc, CX_STR("hello, world!")); + dup = cx_strdup_a(alloc, "hello, world!"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into an equal-length string - dup = cx_strdup_a(alloc, CX_STR("testing!")); + dup = cx_strdup_a(alloc, "testing!"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into a NULL-string dup.ptr = NULL; CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); } @@ -167,9 +167,9 @@ } CX_TEST(test_strlen) { - cxstring s1 = CX_STR("1234"); - cxstring s2 = CX_STR(".:.:."); - cxstring s3 = CX_STR("X"); + cxstring s1 = cx_str("1234"); + cxstring s2 = cx_str(".:.:."); + cxstring s3 = cx_str("X"); CX_TEST_DO { size_t len0 = cx_strlen(0); size_t len1 = cx_strlen(1, s1); @@ -184,7 +184,7 @@ } CX_TEST(test_strsubs) { - cxstring str = CX_STR("A test string"); + cxstring str = cx_str("A test string"); CX_TEST_DO { cxstring sub = cx_strsubs(str, 0); @@ -210,12 +210,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strsubs_m(cx_mutstrn(NULL, 0), 0); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strchr) { - cxstring str = CX_STR("I will find you - and I will kill you"); + cxstring str = cx_str("I will find you - and I will kill you"); CX_TEST_DO { cxstring notfound = cx_strchr(str, 'x'); @@ -227,12 +227,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strchr_m(cx_mutstrn(NULL, 0), 'a'); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strrchr) { - cxstring str = CX_STR("X will find you - and I will kill you"); + cxstring str = cx_str("X will find you - and I will kill you"); CX_TEST_DO { cxstring notfound = cx_strrchr(str, 'x'); @@ -251,12 +251,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strrchr_m(cx_mutstrn(NULL, 0), 'a'); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strstr) { - cxstring str = CX_STR("find the match in this string"); + cxstring str = cx_str("find the match in this string"); const size_t longstrpatternlen = 64 + cx_strstr_sbo_size; const size_t longstrlen = 320 + longstrpatternlen + 14; @@ -314,7 +314,7 @@ } CX_TEST(test_strcmp) { - cxstring str = CX_STR("compare this"); + cxstring str = cx_str("compare this"); CX_TEST_DO { CX_TEST_ASSERT(0 == cx_strcmp(cx_str(""), cx_str(""))); CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str(""))); @@ -329,15 +329,15 @@ CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str("Lex"))); CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str("Another lex test"))); - cxstring str2 = CX_STR("Compare This"); + cxstring str2 = cx_str("Compare This"); CX_TEST_ASSERT(0 != cx_strcmp_p(&str, &str2)); - str2 = CX_STR("compare this"); + str2 = cx_str("compare this"); CX_TEST_ASSERT(0 == cx_strcmp_p(&str, &str2)); } } CX_TEST(test_strcasecmp) { - cxstring str = CX_STR("compare this"); + cxstring str = cx_str("compare this"); CX_TEST_DO { CX_TEST_ASSERT(0 == cx_strcasecmp(cx_str(""), cx_str(""))); CX_TEST_ASSERT(0 < cx_strcasecmp(str, cx_str(""))); @@ -352,17 +352,17 @@ CX_TEST_ASSERT(0 > cx_strcasecmp(str, cx_str("Lex"))); CX_TEST_ASSERT(0 < cx_strcasecmp(str, cx_str("Another lex test"))); - cxstring str2 = CX_STR("Compare This"); + cxstring str2 = cx_str("Compare This"); CX_TEST_ASSERT(0 == cx_strcasecmp_p(&str, &str2)); - str2 = CX_STR("Compare Tool"); + str2 = cx_str("Compare Tool"); CX_TEST_ASSERT(0 > cx_strcasecmp_p(&str, &str2)); } } CX_TEST(test_strcat) { - cxstring s1 = CX_STR("12"); - cxstring s2 = CX_STR("34"); - cxstring s3 = CX_STR("56"); + cxstring s1 = cx_str("12"); + cxstring s2 = cx_str("34"); + cxstring s3 = cx_str("56"); cxstring sn = {NULL, 0}; CxTestingAllocator talloc; @@ -371,22 +371,22 @@ CX_TEST_DO { cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t1), cx_str("1234"))); + CX_TEST_ASSERT(0 == cx_strcmp(t1, "1234")); ASSERT_ZERO_TERMINATED(t1); cx_strfree_a(alloc, &t1); cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t2), cx_str("123456"))); + CX_TEST_ASSERT(0 == cx_strcmp(t2, "123456")); ASSERT_ZERO_TERMINATED(t2); cx_strfree_a(alloc, &t2); cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t3), cx_str("123456"))); + CX_TEST_ASSERT(0 == cx_strcmp(t3, "123456")); ASSERT_ZERO_TERMINATED(t3); cx_strfree_a(alloc, &t3); cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t4), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(t4, "")); ASSERT_ZERO_TERMINATED(t4); cx_strfree_a(alloc, &t4); @@ -394,14 +394,14 @@ // use the macro cxmutstr t5 = cx_strcat(3, s3, s1, s2); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t5), cx_str("561234"))); + CX_TEST_ASSERT(0 == cx_strcmp(t5, "561234")); ASSERT_ZERO_TERMINATED(t5); cx_strfree(&t5); // use an initial string cxmutstr t6 = cx_strdup(cx_str("Hello")); t6 = cx_strcat_m(t6, 2, cx_str(", "), cx_str("World!")); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t6), cx_str("Hello, World!"))); + CX_TEST_ASSERT(0 == cx_strcmp(t6, "Hello, World!")); ASSERT_ZERO_TERMINATED(t6); cx_strfree(&t6); @@ -420,26 +420,26 @@ } CX_TEST(test_strcat_more_than_eight) { - cxstring s1 = CX_STR("12"); - cxstring s2 = CX_STR("34"); - cxstring s3 = CX_STR("56"); - cxstring s4 = CX_STR("78"); - cxstring s5 = CX_STR("9a"); - cxstring s6 = CX_STR("bc"); - cxstring s7 = CX_STR("de"); - cxstring s8 = CX_STR("f0"); - cxstring s9 = CX_STR("xy"); + cxstring s1 = cx_str("12"); + cxstring s2 = cx_str("34"); + cxstring s3 = cx_str("56"); + cxstring s4 = cx_str("78"); + cxstring s5 = cx_str("9a"); + cxstring s6 = cx_str("bc"); + cxstring s7 = cx_str("de"); + cxstring s8 = cx_str("f0"); + cxstring s9 = cx_str("xy"); CX_TEST_DO { cxmutstr r = cx_strcat(9, s1, s2, s3, s4, s5, s6, s7, s8, s9); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(r), cx_str("123456789abcdef0xy"))); + CX_TEST_ASSERT(0 == cx_strcmp(r, "123456789abcdef0xy")); ASSERT_ZERO_TERMINATED(r); cx_strfree(&r); } } CX_TEST(test_strsplit) { - cxstring test = CX_STR("this,is,a,csv,string"); + cxstring test = cx_str("this,is,a,csv,string"); size_t capa = 8; cxstring list[8]; size_t n; @@ -531,9 +531,9 @@ cxmutstr mlist[4]; n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist); CX_TEST_ASSERT(n == 3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], "")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[2], "a,csv,string")); cx_strfree(&mtest); } } @@ -543,7 +543,7 @@ cx_testing_allocator_init(&talloc); CxAllocator *alloc = &talloc.base; - cxstring test = CX_STR("this,is,a,csv,string"); + cxstring test = cx_str("this,is,a,csv,string"); size_t capa = 8; cxstring *list; size_t n; @@ -647,9 +647,9 @@ cxmutstr *mlist; n = cx_strsplit_ma(alloc, mtest, cx_str("is,"), 4, &mlist); CX_TEST_ASSERT(n == 3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], "")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[2], "a,csv,string")); cxFree(alloc, mlist); cx_strfree(&mtest); @@ -676,13 +676,13 @@ // call the _m variant just for coverage cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t ")); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m1), cx_str("ein test"))); + CX_TEST_ASSERT(0 == cx_strcmp(m1, "ein test")); } } CX_TEST(test_strprefix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strprefix(empty, cx_str("pref"))); CX_TEST_ASSERT(cx_strprefix(str, empty)); @@ -693,8 +693,8 @@ } CX_TEST(test_strsuffix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strsuffix(empty, cx_str("suf"))); CX_TEST_ASSERT(cx_strsuffix(str, empty)); @@ -705,8 +705,8 @@ } CX_TEST(test_strcaseprefix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strcaseprefix(empty, cx_str("pREf"))); CX_TEST_ASSERT(cx_strcaseprefix(str, empty)); @@ -717,8 +717,8 @@ } CX_TEST(test_strcasesuffix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strcasesuffix(empty, cx_str("sUf"))); CX_TEST_ASSERT(cx_strcasesuffix(str, empty)); @@ -733,13 +733,13 @@ cx_testing_allocator_init(&talloc); CxAllocator *alloc = &talloc.base; - cxstring str = CX_STR("test ababab string aba"); - cxstring longstr = CX_STR( + cxstring str = cx_str("test ababab string aba"); + cxstring longstr = cx_str( "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd"); - cxstring notrail = CX_STR("test abab"); - cxstring empty = CX_STR(""); - cxstring astr = CX_STR("aaaaaaaaaa"); - cxstring csstr = CX_STR("test AB ab TEST xyz"); + cxstring notrail = cx_str("test abab"); + cxstring empty = cx_str(""); + cxstring astr = cx_str("aaaaaaaaaa"); + cxstring csstr = cx_str("test AB ab TEST xyz"); cxmutstr repl = cx_strreplace(str, cx_str("abab"), cx_str("muchlonger")); const char *expected = "test muchlongerab string aba"; @@ -839,8 +839,8 @@ } CX_TEST(test_strtok) { - cxstring str = CX_STR("a,comma,separated,string"); - cxstring delim = CX_STR(","); + cxstring str = cx_str("a,comma,separated,string"); + cxstring delim = cx_str(","); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); CX_TEST_ASSERT(ctx.str.ptr == str.ptr); @@ -857,9 +857,9 @@ } CX_TEST(test_strtok_delim) { - cxstring str = CX_STR("an,arbitrarily|separated;string"); - cxstring delim = CX_STR(","); - cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")}; + cxstring str = cx_str("an,arbitrarily|separated;string"); + cxstring delim = cx_str(","); + cxstring delim_more[2] = {cx_str("|"), cx_str(";")}; CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); cx_strtok_delim(&ctx, delim_more, 2); @@ -877,8 +877,8 @@ } CX_TEST(test_strtok_next_easy) { - cxstring str = CX_STR("a,comma,separated,string"); - cxstring delim = CX_STR(","); + cxstring str = cx_str("a,comma,separated,string"); + cxstring delim = cx_str(","); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); bool ret; @@ -918,8 +918,8 @@ } CX_TEST(test_strtok_next_unlimited) { - cxstring str = CX_STR("some;-;otherwise;-;separated;-;string;-;"); - cxstring delim = CX_STR(";-;"); + cxstring str = cx_str("some;-;otherwise;-;separated;-;string;-;"); + cxstring delim = cx_str(";-;"); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, SIZE_MAX); bool ret; @@ -983,8 +983,8 @@ CX_TEST(test_strtok_next_advanced) { cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); - cxstring delim = CX_STR(","); - cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; + cxstring delim = cx_str(","); + cxstring delim_more[2] = {cx_str("||"), cx_str(";")}; CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 10); cx_strtok_delim(&ctx, delim_more, 2); @@ -993,7 +993,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("an"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "an")); CX_TEST_ASSERT(ctx.pos == 0); CX_TEST_ASSERT(ctx.next_pos == 3); CX_TEST_ASSERT(ctx.delim_pos == 2); @@ -1002,7 +1002,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("arbitrarily"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "arbitrarily")); CX_TEST_ASSERT(ctx.pos == 3); CX_TEST_ASSERT(ctx.next_pos == 15); CX_TEST_ASSERT(ctx.delim_pos == 14); @@ -1011,7 +1011,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "")); CX_TEST_ASSERT(ctx.pos == 15); CX_TEST_ASSERT(ctx.next_pos == 17); CX_TEST_ASSERT(ctx.delim_pos == 15); @@ -1020,7 +1020,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("separated"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "separated")); CX_TEST_ASSERT(ctx.pos == 17); CX_TEST_ASSERT(ctx.next_pos == 27); CX_TEST_ASSERT(ctx.delim_pos == 26); @@ -1029,7 +1029,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("string"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "string")); CX_TEST_ASSERT(ctx.pos == 27); CX_TEST_ASSERT(ctx.next_pos == 33); CX_TEST_ASSERT(ctx.delim_pos == 33); @@ -1043,7 +1043,7 @@ CX_TEST_ASSERT(ctx.delim_pos == 33); CX_TEST_ASSERT(ctx.found == 5); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(str), cx_str("AN,ARBITRARILY;||SEPARATED;STRING"))); + CX_TEST_ASSERT(0 == cx_strcmp(str, "AN,ARBITRARILY;||SEPARATED;STRING")); } cx_strfree(&str); } @@ -1483,7 +1483,7 @@ } CX_TEST(test_strformat) { - cxstring str = CX_STR("Hello, World!"); + cxstring str = cx_str("Hello, World!"); CX_TEST_DO { char actual[64]; snprintf(actual, 64, "Test %"CX_PRIstr " Success.", CX_SFMT(str));