-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
We should explain how we escape symbols in Amber's text and command:
- We handle some symbols with special care
- We handle escape of some symbols with special care
- For other symbols that are escaped we leave it to Bash
match c {
'"' => match self.render_type {
InterpolableRenderType::StringLiteral => result += "\\\"",
InterpolableRenderType::GlobalContext => result.push('"'),
}
'$' => match self.render_type {
InterpolableRenderType::StringLiteral => result.push('$'),
InterpolableRenderType::GlobalContext => result += "\\$",
}
'`' => match self.render_type {
InterpolableRenderType::StringLiteral => result.push('`'),
InterpolableRenderType::GlobalContext => result += "\\`",
}
'!' => match self.render_type {
InterpolableRenderType::StringLiteral => result += "\"'!'\"",
InterpolableRenderType::GlobalContext => result.push('!'),
}
'\\' => {
// Escape symbols
match chars.peek() {
Some('\n') => {}
Some('n') => result.push('\n'),
Some('t') => result.push('\t'),
Some('r') => result.push('\r'),
Some('0') => result.push('\0'),
Some('{') => result.push('{'),
Some('$') => result.push('$'),
Some('\'') => match self.render_type {
InterpolableRenderType::StringLiteral => result.push('\''),
InterpolableRenderType::GlobalContext => result += "\\'",
}
Some('"') => match self.render_type {
InterpolableRenderType::StringLiteral => result += "\\\"",
InterpolableRenderType::GlobalContext => result.push('"'),
}
Some('\\') => match self.render_type {
InterpolableRenderType::StringLiteral => result += "\\\\",
InterpolableRenderType::GlobalContext => result.push('\\'),
}
_ => {
result.push(c);
continue;
}
}
chars.next();
},
_ => result.push(c)
}
lens0021
Metadata
Metadata
Assignees
Labels
No labels