parser/cgen: fix order of escape replacements

pull/4000/head
Joe Conigliaro 2020-03-13 00:21:43 +11:00
parent b750f1d1bb
commit 597811093c
2 changed files with 4 additions and 4 deletions

View File

@ -2595,8 +2595,8 @@ fn (p mut Parser) char_expr() {
fn format_str(_str string) string {
// TODO don't call replace 3 times for every string, do this in scanner.v
return _str.replace_each(['"', '\\"',
'\n', '\\n',
'\r\n', '\\n'])
'\r\n', '\\n',
'\n', '\\n'])
}
// m := map[string]int{}

View File

@ -810,8 +810,8 @@ fn (g mut Gen) expr(node ast.Expr) {
// In C calls we have to generate C strings
// `C.printf("hi")` => `printf("hi");`
escaped_val := it.val.replace_each(['"', '\\"',
'\n', '\\n',
'\r\n', '\\n'])
'\r\n', '\\n',
'\n', '\\n'])
if g.is_c_call {
g.write('"$escaped_val"')
}