]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
change escape with replace
authorBastian Dehn <hhaalo@arcor.de>
Tue, 3 Mar 2026 19:48:10 +0000 (20:48 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 3 Mar 2026 19:48:10 +0000 (20:48 +0100)
src/rename.c
src/rename.h

index 12060ef63d3090098b6247a87d6759b607f6a596..4c12247403a56e8fd5822438d6220f66ecdbed35 100644 (file)
@@ -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)
index db3e99b9811273773b16b3f65f2a1d93fec4a2ea..16be40139775e83aa89688a42a948768728acf79 100644 (file)
@@ -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);