pub(super) const SHELL_SPECIAL_CHARS: &[char] = &[
' ', '\t', '\n', '\r', '\'', '"', '`', '$', '!', '&', '|', ';', '(', ')', '{', '}', '[', ']', '<', '>', '*', '?', '\\', '#', '~', '^', ];
pub(super) fn shell_single_quote(input: &str) -> String {
let escaped = input.replace('\'', "'\\''");
format!("'{}'", escaped)
}
pub(super) fn shell_double_quote(input: &str) -> String {
let mut result = String::with_capacity(input.len() + 10);
result.push('"');
for c in input.chars() {
match c {
'$' | '`' | '\\' | '"' | '!' => {
result.push('\\');
result.push(c);
}
_ => result.push(c),
}
}
result.push('"');
result
}
pub(super) fn shell_backslash_escape(input: &str) -> String {
let mut result = String::with_capacity(input.len() * 2);
for c in input.chars() {
if SHELL_SPECIAL_CHARS.contains(&c) {
result.push('\\');
}
result.push(c);
}
result
}