Mon, 10 Feb 2025 18:25:16 +0100
remove cx_strupper() and cx_strlower() - fixes #591
CHANGELOG | 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/CHANGELOG Tue Jan 28 18:27:46 2025 +0100 +++ b/CHANGELOG Mon Feb 10 18:25:16 2025 +0100 @@ -31,6 +31,7 @@ * moves cx_compare_func typedef to compare.h * moves cx_szmul() to common.h * moves stream copy functions to new streams.h + * removes cx_strupper() and cx_strlower() because they only do the right thing in special cases * removes several *_m variants of functions in string.h in favor of automatic conversion * removes utils.h * removes flag_removal function from iterator
--- a/src/cx/string.h Tue Jan 28 18:27:46 2025 +0100 +++ b/src/cx/string.h Mon Feb 10 18:25:16 2025 +0100 @@ -951,26 +951,6 @@ ); /** - * Converts the string to lower case. - * - * The change is made in-place. If you want a copy, use cx_strdup(), first. - * - * @param string the string to modify - * @see cx_strdup() - */ -void cx_strlower(cxmutstr string); - -/** - * Converts the string to upper case. - * - * The change is made in-place. If you want a copy, use cx_strdup(), first. - * - * @param string the string to modify - * @see cx_strdup() - */ -void cx_strupper(cxmutstr string); - -/** * Replaces a pattern in a string with another string. * * The pattern is taken literally and is no regular expression.
--- a/src/string.c Tue Jan 28 18:27:46 2025 +0100 +++ b/src/string.c Mon Feb 10 18:25:16 2025 +0100 @@ -588,22 +588,6 @@ #endif } -void cx_strlower(cxmutstr string) { - for (size_t i = 0; i < string.length; i++) { - if ((unsigned int) (string.ptr[i] - 'A') < 26u) { - string.ptr[i] += 'a' - 'A'; - } - } -} - -void cx_strupper(cxmutstr string) { - for (size_t i = 0; i < string.length; i++) { - if ((unsigned int) (string.ptr[i] - 'a') < 26u) { - string.ptr[i] += 'A' - 'a'; - } - } -} - #ifndef CX_STRREPLACE_INDEX_BUFFER_SIZE #define CX_STRREPLACE_INDEX_BUFFER_SIZE 64 #endif
--- a/tests/test_string.c Tue Jan 28 18:27:46 2025 +0100 +++ b/tests/test_string.c Mon Feb 10 18:25:16 2025 +0100 @@ -743,24 +743,6 @@ cx_testing_allocator_destroy(&talloc); } -CX_TEST(test_strupper) { - cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t")); - CX_TEST_DO { - cx_strupper(str); - CX_TEST_ASSERT(0 == strcmp(str.ptr, "THIS 1S @ TE$T")); - } - cx_strfree(&str); -} - -CX_TEST(test_strlower) { - cxmutstr str = cx_strdup(cx_str("thIs 1s @ Te$t")); - CX_TEST_DO { - cx_strlower(str); - CX_TEST_ASSERT(0 == strcmp(str.ptr, "this 1s @ te$t")); - } - cx_strfree(&str); -} - CX_TEST(test_strtok) { cxstring str = CX_STR("a,comma,separated,string"); cxstring delim = CX_STR(","); @@ -896,6 +878,14 @@ } } +static void test_toupper(cxmutstr string) { + for (size_t i = 0; i < string.length; i++) { + if ((unsigned int)(string.ptr[i] - 'a') < 26u) { + string.ptr[i] += 'A' - 'a'; + } + } +} + CX_TEST(test_strtok_next_advanced) { cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); cxstring delim = CX_STR(","); @@ -913,7 +903,7 @@ CX_TEST_ASSERT(ctx.next_pos == 3); CX_TEST_ASSERT(ctx.delim_pos == 2); CX_TEST_ASSERT(ctx.found == 1); - cx_strupper(tok); + test_toupper(tok); ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); @@ -922,7 +912,7 @@ CX_TEST_ASSERT(ctx.next_pos == 15); CX_TEST_ASSERT(ctx.delim_pos == 14); CX_TEST_ASSERT(ctx.found == 2); - cx_strupper(tok); + test_toupper(tok); ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); @@ -931,7 +921,7 @@ CX_TEST_ASSERT(ctx.next_pos == 17); CX_TEST_ASSERT(ctx.delim_pos == 15); CX_TEST_ASSERT(ctx.found == 3); - cx_strupper(tok); + test_toupper(tok); ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); @@ -940,7 +930,7 @@ CX_TEST_ASSERT(ctx.next_pos == 27); CX_TEST_ASSERT(ctx.delim_pos == 26); CX_TEST_ASSERT(ctx.found == 4); - cx_strupper(tok); + test_toupper(tok); ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); @@ -949,7 +939,7 @@ CX_TEST_ASSERT(ctx.next_pos == 33); CX_TEST_ASSERT(ctx.delim_pos == 33); CX_TEST_ASSERT(ctx.found == 5); - cx_strupper(tok); + test_toupper(tok); ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(!ret); @@ -1276,8 +1266,6 @@ cx_test_register(suite, test_strcaseprefix); cx_test_register(suite, test_strcasesuffix); cx_test_register(suite, test_strreplace); - cx_test_register(suite, test_strupper); - cx_test_register(suite, test_strlower); cx_test_register(suite, test_strtok); cx_test_register(suite, test_strtok_delim); cx_test_register(suite, test_strtok_next_easy);