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:
@ -9,9 +9,9 @@ fn main() {
|
||||
|
||||
fn test_encode_int() ? {
|
||||
a := 0x24 // should be 'd' in base58
|
||||
assert encode_int(a) ? == 'd'
|
||||
assert encode_int(a)? == 'd'
|
||||
|
||||
test_encode_int_walpha() ?
|
||||
test_encode_int_walpha()?
|
||||
}
|
||||
|
||||
fn test_encode_int_walpha() ? {
|
||||
@ -20,14 +20,14 @@ fn test_encode_int_walpha() ? {
|
||||
panic(@MOD + '.' + @FN + ': this should never happen')
|
||||
}
|
||||
a := 0x24 // should be '_' in base58 with our custom alphabet
|
||||
assert encode_int_walpha(a, abc) ? == '_'
|
||||
assert encode_int_walpha(a, abc)? == '_'
|
||||
}
|
||||
|
||||
fn test_decode_int() ? {
|
||||
a := 'd'
|
||||
assert decode_int(a) ? == 0x24
|
||||
assert decode_int(a)? == 0x24
|
||||
|
||||
test_decode_int_walpha() ?
|
||||
test_decode_int_walpha()?
|
||||
}
|
||||
|
||||
fn test_decode_int_walpha() ? {
|
||||
@ -35,7 +35,7 @@ fn test_decode_int_walpha() ? {
|
||||
panic(@MOD + '.' + @FN + ': this should never happen')
|
||||
}
|
||||
a := '_'
|
||||
assert decode_int_walpha(a, abc) ? == 0x24
|
||||
assert decode_int_walpha(a, abc)? == 0x24
|
||||
}
|
||||
|
||||
fn test_encode_string() {
|
||||
@ -51,13 +51,13 @@ fn test_encode_string() {
|
||||
|
||||
fn test_decode_string() ? {
|
||||
a := 'TtaR6twpTGu8VpY'
|
||||
assert decode(a) ? == 'lorem ipsum'
|
||||
assert decode(a)? == 'lorem ipsum'
|
||||
|
||||
abc := new_alphabet('abcdefghij\$lmnopqrstuvwxyz0123456789_ABCDEFGHIJLMNOPQRSTUV') or {
|
||||
panic(@MOD + '.' + @FN + ': this should never happen')
|
||||
}
|
||||
b := '0P7yfPSL0pQh2L5'
|
||||
assert decode_walpha(b, abc) ? == 'lorem ipsum'
|
||||
assert decode_walpha(b, abc)? == 'lorem ipsum'
|
||||
}
|
||||
|
||||
fn test_fails() ? {
|
||||
|
@ -69,7 +69,7 @@ pub fn new_reader(data string, config ReaderConfig) &Reader {
|
||||
// read reads a row from the CSV data.
|
||||
// If successful, the result holds an array of each column's data.
|
||||
pub fn (mut r Reader) read() ?[]string {
|
||||
l := r.read_record() ?
|
||||
l := r.read_record()?
|
||||
return l
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ fn (mut r Reader) read_record() ?[]string {
|
||||
mut i := -1
|
||||
for {
|
||||
if need_read {
|
||||
l := r.read_line() ?
|
||||
l := r.read_line()?
|
||||
if l.len <= 0 {
|
||||
if keep_raw {
|
||||
line += '\n'
|
||||
|
@ -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
|
||||
|
@ -1,16 +1,16 @@
|
||||
module hex
|
||||
|
||||
fn test_decode() ? {
|
||||
assert decode('') ? == []
|
||||
assert decode('0') ? == [u8(0x0)]
|
||||
assert decode('f') ? == [u8(0xf)]
|
||||
assert decode('0f') ? == [u8(0x0f)]
|
||||
assert decode('ff') ? == [u8(0xff)]
|
||||
assert decode('123') ? == [u8(0x1), 0x23]
|
||||
assert decode('1234') ? == [u8(0x12), 0x34]
|
||||
assert decode('12345') ? == [u8(0x1), 0x23, 0x45]
|
||||
assert decode('0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('')? == []
|
||||
assert decode('0')? == [u8(0x0)]
|
||||
assert decode('f')? == [u8(0xf)]
|
||||
assert decode('0f')? == [u8(0x0f)]
|
||||
assert decode('ff')? == [u8(0xff)]
|
||||
assert decode('123')? == [u8(0x1), 0x23]
|
||||
assert decode('1234')? == [u8(0x12), 0x34]
|
||||
assert decode('12345')? == [u8(0x1), 0x23, 0x45]
|
||||
assert decode('0123456789abcdef')? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('123456789ABCDEF')? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
}
|
||||
|
||||
fn test_decode_fails() ? {
|
||||
@ -32,23 +32,23 @@ fn test_decode_fails() ? {
|
||||
}
|
||||
|
||||
fn test_encode() ? {
|
||||
assert encode(decode('') ?) == ''
|
||||
assert encode(decode('0') ?) == '00'
|
||||
assert encode(decode('f') ?) == '0f'
|
||||
assert encode(decode('0f') ?) == '0f'
|
||||
assert encode(decode('ff') ?) == 'ff'
|
||||
assert encode(decode('123') ?) == '0123'
|
||||
assert encode(decode('1234') ?) == '1234'
|
||||
assert encode(decode('12345') ?) == '012345'
|
||||
assert encode(decode('abcdef') ?) == 'abcdef'
|
||||
assert encode(decode('ABCDEF') ?) == 'abcdef'
|
||||
assert encode(decode('')?) == ''
|
||||
assert encode(decode('0')?) == '00'
|
||||
assert encode(decode('f')?) == '0f'
|
||||
assert encode(decode('0f')?) == '0f'
|
||||
assert encode(decode('ff')?) == 'ff'
|
||||
assert encode(decode('123')?) == '0123'
|
||||
assert encode(decode('1234')?) == '1234'
|
||||
assert encode(decode('12345')?) == '012345'
|
||||
assert encode(decode('abcdef')?) == 'abcdef'
|
||||
assert encode(decode('ABCDEF')?) == 'abcdef'
|
||||
}
|
||||
|
||||
fn test_decode_0x() ? {
|
||||
assert decode('0x') ? == []
|
||||
assert decode('0x0') ? == [u8(0x0)]
|
||||
assert decode('0X1234') ? == [u8(0x12), 0x34]
|
||||
assert decode('0x12345') ? == [u8(0x1), 0x23, 0x45]
|
||||
assert decode('0x0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('0X123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('0x')? == []
|
||||
assert decode('0x0')? == [u8(0x0)]
|
||||
assert decode('0X1234')? == [u8(0x12), 0x34]
|
||||
assert decode('0x12345')? == [u8(0x1), 0x23, 0x45]
|
||||
assert decode('0x0123456789abcdef')? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
assert decode('0X123456789ABCDEF')? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||
}
|
||||
|
Reference in New Issue
Block a user