mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
fix indentation and simplify hex.decode_sequence
This commit is contained in:
+10
-11
@@ -36,22 +36,21 @@ decode :: proc(src: []byte, allocator := context.allocator) -> (dst: []byte, ok:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decodes the given sequence into one byte.
|
// Decodes the given sequence into one byte.
|
||||||
// Should be called with one rune worth of the source, eg: 0x23 -> '#'.
|
// Should be called with one byte worth of the source, eg: 0x23 -> '#'.
|
||||||
decode_sequence :: proc(str: string) -> (byte, bool) {
|
decode_sequence :: proc(str: string) -> (res: byte, ok: bool) {
|
||||||
no_prefix_str := strings.trim_prefix(str, "0x")
|
str := str
|
||||||
val: byte
|
if strings.has_prefix(str, "0x") || strings.has_prefix(str, "0X") {
|
||||||
for i := 0; i < len(no_prefix_str); i += 1 {
|
str = str[2:]
|
||||||
index := (len(no_prefix_str) - 1) - i // reverse the loop.
|
}
|
||||||
|
|
||||||
hd, ok := hex_digit(no_prefix_str[i])
|
if len(str) != 2 {
|
||||||
if !ok {
|
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
val += u8(hd) << uint(4 * index)
|
upper := hex_digit(str[0]) or_return
|
||||||
}
|
lower := hex_digit(str[1]) or_return
|
||||||
|
|
||||||
return val, true
|
return upper << 4 | lower, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
|
|||||||
Reference in New Issue
Block a user