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

fmt: remove space in front of ? and ! (#14366)

This commit is contained in:
Daniel Däschle
2022-05-13 05:56:21 +02:00
committed by GitHub
parent df029da942
commit d679146a80
324 changed files with 1865 additions and 1879 deletions

View File

@ -15,24 +15,24 @@ pub fn decode(s string) ?[]u8 {
if hex_str.len == 0 {
return []u8{}
} else if hex_str.len == 1 {
return [char2nibble(hex_str[0]) ?]
return [char2nibble(hex_str[0])?]
} else if hex_str.len == 2 {
n1 := char2nibble(hex_str[0]) ?
n0 := char2nibble(hex_str[1]) ?
n1 := char2nibble(hex_str[0])?
n0 := char2nibble(hex_str[1])?
return [(n1 << 4) | n0]
}
// calculate the first byte depending on if hex_str.len is odd
mut val := char2nibble(hex_str[0]) ?
mut val := char2nibble(hex_str[0])?
if hex_str.len & 1 == 0 {
val = (val << 4) | char2nibble(hex_str[1]) ?
val = (val << 4) | char2nibble(hex_str[1])?
}
// set cap to hex_str.len/2 rounded up
mut bytes := []u8{len: 1, cap: (hex_str.len + 1) >> 1, init: val}
// iterate over every 2 bytes
// the start index depends on if hex_str.len is odd
for i := 2 - (hex_str.len & 1); i < hex_str.len; i += 2 {
n1 := char2nibble(hex_str[i]) ?
n0 := char2nibble(hex_str[i + 1]) ?
n1 := char2nibble(hex_str[i])?
n0 := char2nibble(hex_str[i + 1])?
bytes << (n1 << 4) | n0
}
return bytes