From: Bastian Dehn Date: Thu, 2 Oct 2025 15:56:49 +0000 (+0200) Subject: change rename string with space test X-Git-Tag: 1.1.2^2~1^2~8 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=57ce4fb920343e467686b28b00746e1a391a8b9e;p=mv_none_space.git change rename string with space test --- diff --git a/src/rename.c b/src/rename.c index 92a0da7..0218fd8 100644 --- a/src/rename.c +++ b/src/rename.c @@ -132,6 +132,55 @@ void rename_str(const char* src, char* dst) } } +char* rename_string(const char* src) +{ + size_t length = strlen(src); + int dest_count = 0; + char* dest = malloc(sizeof(char) * STR_MAX_LENGTH); + + for (int i = 0; i < length; i++) { + if (src[i] == SPACE) { + dest[dest_count++] = '_'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_a) { + i++; + dest[dest_count++] = 'a'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_A) { + i++; + dest[dest_count++] = 'A'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_o) { + i++; + dest[dest_count++] = 'o'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_O) { + i++; + dest[dest_count++] = 'O'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_u) { + i++; + dest[dest_count++] = 'u'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_U) { + i++; + dest[dest_count++] = 'U'; + dest[dest_count++] = 'e'; + } else if (src[i] == WIDE_CHAR_PREFIX && src[i + 1] == WIDE_CHAR_SS) { + i++; + dest[dest_count++] = 's'; + dest[dest_count++] = 's'; + } else { + dest[dest_count++] = src[i]; + } + } + + dest[dest_count] = '\0'; + length = strlen(dest) + 1; + dest = realloc(dest, sizeof(char) * length); + + return dest; +} + void rename_revert_str(const char* src, char* dst) { int len = strlen(src); diff --git a/src/rename.h b/src/rename.h index d49648f..87f1c3b 100644 --- a/src/rename.h +++ b/src/rename.h @@ -38,6 +38,7 @@ char* escape(const char* src); __attribute_deprecated__ void rename_point_str(const char* src, char* dst); __attribute_deprecated__ void rename_lower_str(const char* src, char* dst); __attribute_deprecated__ void rename_str(const char* src, char* dst); +char* rename_string(const char* src); __attribute_deprecated__ void rename_revert_str(const char* src, char* dst); #endif \ No newline at end of file diff --git a/tests/rename_tests.c b/tests/rename_tests.c index 663b0eb..a1556a6 100644 --- a/tests/rename_tests.c +++ b/tests/rename_tests.c @@ -27,14 +27,16 @@ int teardown(void **state) return 0; } -void rename_spaces(void **state) +void rename_spaces() { - char* output = (char*) *state; char* input = "Dies ist ein Test Satz"; - rename_str(input, output); + char* output = rename_string(input); assert_string_equal(output, "Dies_ist_ein_Test_Satz"); + + free(output); + output = NULL; } void rename_ae(void **state)