mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
scanner: fix string slash line breaks error
This commit is contained in:
parent
cd5dccd855
commit
e0e064ff08
@ -728,3 +728,14 @@ fn test_split_into_lines() {
|
||||
assert line == line_content
|
||||
}
|
||||
}
|
||||
|
||||
fn test_string_literal_with_backslash(){
|
||||
a := 'Hello\
|
||||
World'
|
||||
assert a == 'HelloWorld'
|
||||
|
||||
b := 'One\
|
||||
Two\
|
||||
Three'
|
||||
assert b == 'OneTwoThree'
|
||||
}
|
||||
|
@ -900,13 +900,31 @@ fn (s mut Scanner) ident_string() string {
|
||||
if s.is_inside_string {
|
||||
end++
|
||||
}
|
||||
if start > s.pos {}
|
||||
else {
|
||||
lit = s.text[start..end]
|
||||
if start <= s.pos {
|
||||
if s.text[start..end].contains('\\\n') {
|
||||
lit = trim_slash_line_break(s.text[start..end])
|
||||
} else {
|
||||
lit = s.text[start..end]
|
||||
}
|
||||
}
|
||||
return lit
|
||||
}
|
||||
|
||||
fn trim_slash_line_break(s string) string {
|
||||
mut start := 0
|
||||
mut ret_str := s
|
||||
for {
|
||||
idx := ret_str.index_after('\\\n', start)
|
||||
if idx != -1 {
|
||||
ret_str = ret_str[..idx] + ret_str[idx+2..].trim_left(' \n\t\v\f\r')
|
||||
start = idx
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return ret_str
|
||||
}
|
||||
|
||||
fn (s mut Scanner) ident_char() string {
|
||||
start := s.pos
|
||||
slash := `\\`
|
||||
|
Loading…
Reference in New Issue
Block a user