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)
#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);