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

tests: test with valgrind rune.bytes(), fix leak in .str_escaped()

This commit is contained in:
Delyan Angelov 2022-01-11 15:14:42 +02:00
parent 8acd84d04a
commit ecc7accc8e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 39 additions and 11 deletions

View File

@ -471,19 +471,45 @@ pub fn (b byte) ascii_str() string {
// str_escaped returns the contents of `byte` as an escaped `string`. // str_escaped returns the contents of `byte` as an escaped `string`.
// Example: assert byte(0).str_escaped() == r'`\0`' // Example: assert byte(0).str_escaped() == r'`\0`'
[manualfree]
pub fn (b byte) str_escaped() string { pub fn (b byte) str_escaped() string {
str := match b { str := match b {
0 { r'`\0`' } 0 {
7 { r'`\a`' } r'`\0`'
8 { r'`\b`' } }
9 { r'`\t`' } 7 {
10 { r'`\n`' } r'`\a`'
11 { r'`\v`' } }
12 { r'`\f`' } 8 {
13 { r'`\r`' } r'`\b`'
27 { r'`\e`' } }
32...126 { b.ascii_str() } 9 {
else { '0x' + b.hex() } r'`\t`'
}
10 {
r'`\n`'
}
11 {
r'`\v`'
}
12 {
r'`\f`'
}
13 {
r'`\r`'
}
27 {
r'`\e`'
}
32...126 {
b.ascii_str()
}
else {
xx := b.hex()
yy := '0x' + xx
unsafe { xx.free() }
yy
}
} }
return str return str
} }

View File

@ -1,4 +1,6 @@
fn main() { fn main() {
a := `Y`.str() a := `Y`.str()
println(a) println(a)
b := ``.bytes()
println(b)
} }