mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a19a4ba299
commit
064e35fbc4
@ -80,7 +80,10 @@ fn insert_template_code(fn_name string, tmpl_str_start string, line string) stri
|
|||||||
round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$']
|
round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$']
|
||||||
round2 := [r'$$', r'\@', r'.$', r'.@']
|
round2 := [r'$$', r'\@', r'.$', r'.@']
|
||||||
mut rline := line.replace_each(round1).replace_each(round2)
|
mut rline := line.replace_each(round1).replace_each(round2)
|
||||||
|
comptime_call_str := rline.find_between('\${', '}')
|
||||||
|
if comptime_call_str.contains("\\'") {
|
||||||
|
rline = rline.replace(comptime_call_str, comptime_call_str.replace("\\'", r"'"))
|
||||||
|
}
|
||||||
if rline.ends_with('\\') {
|
if rline.ends_with('\\') {
|
||||||
rline = rline[0..rline.len - 2] + trailing_bs
|
rline = rline[0..rline.len - 2] + trailing_bs
|
||||||
}
|
}
|
||||||
|
3
vlib/v/tests/tmpl/template.in
Normal file
3
vlib/v/tests/tmpl/template.in
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
someval: @{s.someval('huh')}
|
||||||
|
|
||||||
|
someotherval: @{s.m['hah']}
|
27
vlib/v/tests/tmpl_with_single_quotes_test.v
Normal file
27
vlib/v/tests/tmpl_with_single_quotes_test.v
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
pub struct SomeThing {
|
||||||
|
pub:
|
||||||
|
m map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (s SomeThing) someval(what string) string {
|
||||||
|
return s.m[what]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (s SomeThing) template() string {
|
||||||
|
return $tmpl('tmpl/template.in')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_tmpl_with_single_quotes() {
|
||||||
|
mut sm := map[string]string{}
|
||||||
|
sm['huh'] = 'monkey'
|
||||||
|
sm['hah'] = 'parrot'
|
||||||
|
|
||||||
|
s := SomeThing{sm}
|
||||||
|
result := s.template()
|
||||||
|
println(result)
|
||||||
|
assert result.trim_space() == 'someval: monkey
|
||||||
|
|
||||||
|
someotherval: parrot'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user