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

scanner: ignore CR signs in string literals

This commit is contained in:
Delyan Angelov 2020-06-23 21:10:51 +03:00
parent 74af88bc92
commit fcd73bcb63

View File

@ -1177,6 +1177,7 @@ fn (mut s Scanner) ident_string() string {
// println('\nident_string() at char=${s.text[s.pos].str()}') // println('\nident_string() at char=${s.text[s.pos].str()}')
// println('linenr=$s.line_nr quote= $qquote ${qquote.str()}') // println('linenr=$s.line_nr quote= $qquote ${qquote.str()}')
// } // }
mut n_cr_chars := 0
mut start := s.pos mut start := s.pos
s.is_inside_string = false s.is_inside_string = false
slash := `\\` slash := `\\`
@ -1192,6 +1193,9 @@ fn (mut s Scanner) ident_string() string {
// handle '123\\' slash at the end // handle '123\\' slash at the end
break break
} }
if c == `\r` {
n_cr_chars++
}
if c == `\n` { if c == `\n` {
s.inc_line_number() s.inc_line_number()
} }
@ -1230,10 +1234,14 @@ fn (mut s Scanner) ident_string() string {
end++ end++
} }
if start <= s.pos { if start <= s.pos {
if s.text[start..end].contains('\\\n') { mut string_so_far := s.text[start..end]
lit = trim_slash_line_break(s.text[start..end]) if n_cr_chars > 0 {
string_so_far = string_so_far.replace('\r', '')
}
if string_so_far.contains('\\\n') {
lit = trim_slash_line_break(string_so_far)
} else { } else {
lit = s.text[start..end] lit = string_so_far
} }
} }
return lit return lit