1
0
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:
yuyi 2020-05-04 16:19:23 +08:00 committed by GitHub
parent cd5dccd855
commit e0e064ff08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -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'
}

View File

@ -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 := `\\`