mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
eebc82d83a
commit
34d115d883
@ -202,6 +202,9 @@ fn cgen_attrs(attrs []ast.Attr) []string {
|
||||
if attr.arg.len > 0 {
|
||||
s += ': $attr.arg'
|
||||
}
|
||||
if attr.kind == .string {
|
||||
s = escape_quotes(s)
|
||||
}
|
||||
res << '_SLIT("$s")'
|
||||
}
|
||||
return res
|
||||
|
7
vlib/v/gen/c/testdata/attr_string_quotes_escape.out
vendored
Normal file
7
vlib/v/gen/c/testdata/attr_string_quotes_escape.out
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
FunctionData{
|
||||
name: 'sample_method'
|
||||
attrs: ['option: "1"']
|
||||
args: []
|
||||
return_type: 1
|
||||
typ: 0
|
||||
}
|
11
vlib/v/gen/c/testdata/attr_string_quotes_escape.vv
vendored
Normal file
11
vlib/v/gen/c/testdata/attr_string_quotes_escape.vv
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
struct Dummy {}
|
||||
|
||||
['option: "1"']
|
||||
fn (d Dummy) sample_method() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for method in Dummy.methods {
|
||||
println(method)
|
||||
}
|
||||
}
|
@ -83,3 +83,15 @@ fn (mut g Gen) fn_var_signature(return_type ast.Type, arg_types []ast.Type, var_
|
||||
sig += ')'
|
||||
return sig
|
||||
}
|
||||
|
||||
// escape quotes for string
|
||||
fn escape_quotes(val string) string {
|
||||
bs := '\\'
|
||||
unescaped_val := val.replace('$bs$bs', '\x01').replace_each([
|
||||
"$bs'",
|
||||
"'",
|
||||
'$bs"',
|
||||
'"',
|
||||
])
|
||||
return unescaped_val.replace_each(['\x01', '$bs$bs', "'", "$bs'", '"', '$bs"'])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user