void rename_string(const char* src, char* dst)
{
- uint16_t dst_count = 0;
- size_t length = strlen(src);
- for (size_t i = 0; i < length; i++) {
- switch (wide_char_length(src[i])) {
- case 2:
- dst_count += _replace_two_byte_wide_char(&src[i], &dst[dst_count]);
- i++;
- break;
- default:
- dst_count += _replace_char(src[i], &dst[dst_count]);
- break;
- }
- }
+ size_t len = strlen(src) + 1;
+ char* out = malloc(len);
+ if (out == NULL)
+ return;
+
+ memcpy(out, src, len);
+
+ out = replace(&out, " ", "_");
+ out = replace(&out, "ä", "ae");
+ out = replace(&out, "Ä", "Ae");
+ out = replace(&out, "ö", "oe");
+ out = replace(&out, "Ö", "Oe");
+ out = replace(&out, "ü", "ue");
+ out = replace(&out, "Ü", "Ue");
+ out = replace(&out, "ß", "ss");
+
+ memcpy(dst, out, strlen(out) + 1);
+ free(out);
+ out = NULL;
}
void rename_revert(const char* src, char* dst)
}
}
-char* replace(const char* src, const char* pattern, const char* replace_str)
+char* replace(char** src, const char* pattern, const char* replace_str)
{
- const size_t len = strlen(src);
+ const size_t len = strlen(*src);
const size_t plen = strlen(pattern);
uint32_t count = 0;
for (uint32_t i = 0; i < len; i++) {
- if (strncmp(&src[i], pattern, plen) == 0)
+ if (strncmp(*src + i, pattern, plen) == 0)
count++;
}
uint32_t outi = 0;
for (uint32_t i = 0; i < len; i++) {
- if (strncmp(&src[i], pattern, plen) == 0) {
+ if (strncmp(*src + i, pattern, plen) == 0) {
memcpy(&output[outi], replace_str, rlen);
i += plen - 1;
outi += rlen;
} else {
- output[outi++] = src[i];
+ output[outi++] = (*src)[i];
}
}
+ free(*src);
+ *src = NULL;
return output;
}
\ No newline at end of file