summaryrefslogtreecommitdiff
path: root/src/core/misc.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2017-02-21 15:54:31 +0100
committerLemonBoy <thatlemon@gmail.com>2017-02-22 11:49:09 +0100
commit027acffb4208d7e6ba8e229cbf6c3dae6f5dabaf (patch)
treedbd545231f3d041717bf978ea54b5b48f9caebb8 /src/core/misc.c
parentdb85ab7c90f23e00cd444728f6a5b3d1f63254df (diff)
downloadirssi-027acffb4208d7e6ba8e229cbf6c3dae6f5dabaf.zip
Handle file names with quotes.
Let's repurpose escape_string and make it more flexible by letting us choose the characters to escape.
Diffstat (limited to 'src/core/misc.c')
-rw-r--r--src/core/misc.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/core/misc.c b/src/core/misc.c
index 1cfa15b6..03fcce59 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -724,18 +724,20 @@ int expand_escape(const char **data)
}
}
-/* Escape all '"', "'" and '\' chars with '\' */
-char *escape_string(const char *str)
+/* Escape all the characters in `what' with a backslash */
+char *escape_string(const char *str, const char *what)
{
- char *ret, *p;
+ const char *p;
+ char *ret;
- p = ret = g_malloc(strlen(str)*2+1);
- while (*str != '\0') {
- if (*str == '"' || *str == '\'' || *str == '\\')
- *p++ = '\\';
- *p++ = *str++;
+ ret = g_malloc(strlen(str) * 2 + 1);
+ for (p = str; *p != '\0'; p++, ret++) {
+ if (strchr(what, *p) != NULL) {
+ *ret++ = '\\';
+ }
+ *ret = *p;
}
- *p = '\0';
+ *ret = '\0';
return ret;
}