mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
32c027a0bf
commit
f336c2c5cc
5
vlib/v/checker/tests/string_escape_x_err_a.out
Normal file
5
vlib/v/checker/tests/string_escape_x_err_a.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/string_escape_x_err_a.vv:2:15: error: `\x` used with no following hex digits
|
||||
1 | fn main() {
|
||||
2 | println('\x')
|
||||
| ^
|
||||
3 | }
|
3
vlib/v/checker/tests/string_escape_x_err_a.vv
Normal file
3
vlib/v/checker/tests/string_escape_x_err_a.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println('\x')
|
||||
}
|
5
vlib/v/checker/tests/string_escape_x_err_b.out
Normal file
5
vlib/v/checker/tests/string_escape_x_err_b.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/string_escape_x_err_b.vv:2:15: error: `\x` used with no following hex digits
|
||||
1 | fn main() {
|
||||
2 | println('\xhh')
|
||||
| ^
|
||||
3 | }
|
3
vlib/v/checker/tests/string_escape_x_err_b.vv
Normal file
3
vlib/v/checker/tests/string_escape_x_err_b.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println('\xhh')
|
||||
}
|
@ -1039,6 +1039,12 @@ fn (mut s Scanner) ident_string() string {
|
||||
s.error(r'cannot use `\x00` (NULL character) in the string literal')
|
||||
}
|
||||
}
|
||||
// Escape `\x`
|
||||
if prevc == slash &&
|
||||
c == `x` && s.count_symbol_before(s.pos - 2, slash) % 2 == 0 && !is_raw && !is_cstr &&
|
||||
(s.text[s.pos + 1] == s.quote || !s.text[s.pos + 1].is_hex_digit()) {
|
||||
s.error(r'`\x` used with no following hex digits')
|
||||
}
|
||||
// ${var} (ignore in vfmt mode) (skip \$)
|
||||
if prevc == `$` && c == `{` && !is_raw && s.count_symbol_before(s.pos - 2, slash) % 2 == 0 {
|
||||
s.is_inside_string = true
|
||||
|
@ -136,3 +136,8 @@ fn test_ref_ref_array_ref_ref_foo() {
|
||||
assert result[5] == .amp
|
||||
assert result[6] == .name
|
||||
}
|
||||
|
||||
fn test_escape_string() {
|
||||
assert '\x61' == 'a'
|
||||
assert '\x62' == 'b'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user