1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: bugfix for raw'"'

This commit is contained in:
Delyan Angelov 2020-02-09 17:29:05 +02:00 committed by GitHub
parent 984fd8c05e
commit f76651604d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -585,6 +585,13 @@ fn test_raw() {
println('raw string: "$raw"') println('raw string: "$raw"')
} }
fn test_raw_with_quotes() {
raw := r"some'" + r'"thing' // " should be escaped in the generated C code
assert raw[0] == `s`
assert raw[5] == `"`
assert raw[6] == `t`
}
fn test_escape() { fn test_escape() {
// TODO // TODO
//a := 10 //a := 10

View File

@ -12,7 +12,7 @@ fn (p mut Parser) string_expr() {
str := p.lit str := p.lit
// No ${}, just return a simple string // No ${}, just return a simple string
if p.peek() != .str_dollar || is_raw { if p.peek() != .str_dollar || is_raw {
f := if is_raw { cescaped_path(str) } else { format_str(str) } f := if is_raw { cescaped_path(str).replace('"', '\\"') } else { format_str(str) }
// `C.puts('hi')` => `puts("hi");` // `C.puts('hi')` => `puts("hi");`
/* /*
Calling a C function sometimes requires a call to a string method Calling a C function sometimes requires a call to a string method