Fix escaping of characters in C strings
This commit is contained in:
parent
1468b349b5
commit
c76a155174
1 changed files with 7 additions and 3 deletions
|
|
@ -931,10 +931,14 @@ impl Generator {
|
|||
fn sanitize_string(&self, name: &str) -> String {
|
||||
let mut result = String::with_capacity(name.len());
|
||||
for c in name.chars() {
|
||||
if ['\\', '\n', '\r', '\"'].contains(&c) {
|
||||
result.push('\\');
|
||||
match c {
|
||||
'\"' => result += "\\\"",
|
||||
'\\' => result += "\\\\",
|
||||
'\t' => result += "'\\t'",
|
||||
'\n' => result += "'\\n'",
|
||||
'\r' => result += "'\\r'",
|
||||
_ => result.push(c),
|
||||
}
|
||||
result.push(c);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue