From: Bastian Dehn Date: Tue, 3 Mar 2026 19:48:10 +0000 (+0100) Subject: change escape with replace X-Git-Tag: 1.1.6^2~1^2~3 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=eecfc8ce6b47ff72421366388bc377b5171639b7;p=mv_none_space.git change escape with replace --- diff --git a/src/rename.c b/src/rename.c index 12060ef..4c12247 100644 --- a/src/rename.c +++ b/src/rename.c @@ -41,25 +41,24 @@ char* replace(char** src, const char* pattern, const char* replace_str) void escape(const char* src, char* dst) { - uint16_t dst_count = 0; - size_t length = strlen(src); - for (size_t i = 0; i < length; i++) { - switch(src[i]) { - case SPACE: - case ROUND_BRACKET_OPEN: - case ROUND_BRACKET_CLOSE: - case BRACKET_OPEN: - case BRACKET_CLOSE: - case BRACE_OPEN: - case BRACE_CLOSE: - dst[dst_count++] = '\\'; - dst[dst_count++] = src[i]; - break; - default: - dst[dst_count++] = src[i]; - 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, "(", "\\("); + out = replace(&out, ")", "\\)"); + out = replace(&out, "{", "\\{"); + out = replace(&out, "}", "\\}"); + out = replace(&out, "[", "\\["); + out = replace(&out, "]", "\\]"); + + memcpy(dst, out, strlen(out) + 1); + free(out); + out = NULL; } void rename_point(const char* src, char* dst) diff --git a/src/rename.h b/src/rename.h index db3e99b..16be401 100644 --- a/src/rename.h +++ b/src/rename.h @@ -5,31 +5,9 @@ #define STR_MAX_LENGTH 1024 #define SPACE (char) 0x20 -#define ROUND_BRACKET_OPEN (char) 0x28 -#define ROUND_BRACKET_CLOSE (char) 0x29 -#define BRACKET_OPEN (char) 0x5b -#define BRACKET_CLOSE (char) 0x5d -#define BRACE_OPEN (char) 0x7b -#define BRACE_CLOSE (char) 0x7d #define POINT (char) 0x2e #define A (char) 0x41 #define Z (char) 0x5a -#define WIDE_CHAR_PREFIX (char) 0xc3 -#define WIDE_CHAR_a (char) 0xa4 -#define WIDE_CHAR_A (char) 0x84 -#define WIDE_CHAR_o (char) 0xb6 -#define WIDE_CHAR_O (char) 0x96 -#define WIDE_CHAR_u (char) 0xbc -#define WIDE_CHAR_U (char) 0x9c -#define WIDE_CHAR_SS (char) 0x9f -#define WIDE_CHAR_SHORT_PREFIX (char) 0xc3 -#define WIDE_CHAR_SHORT_a (char) 0xa4 -#define WIDE_CHAR_SHORT_A (char) 0x84 -#define WIDE_CHAR_SHORT_o (char) 0xb6 -#define WIDE_CHAR_SHORT_O (char) 0x96 -#define WIDE_CHAR_SHORT_u (char) 0xbc -#define WIDE_CHAR_SHORT_U (char) 0x9c -#define WIDE_CHAR_SHORT_SS (char) 0x9f typedef void (*rename_ptr)(const char* src, char* dst);