use Str use Char char-u8 use Mem u8-size use Iter map reduce use Error or-fail use Into use SmolStr # official octal number function. fn from-octal(arr): arr Iter.reduce(0, fn(elem, b): b * 8 + elem) fn hex-digit(c Char) if c >= '0' and c <= '9' return Just(char-u8(c) - char-u8('0')) if c >= 'a' and c <= 'f' return Just(char-u8(c) - char-u8('a') + 10) if c >= 'A' and c <= 'F' return Just(char-u8(c) - char-u8('A') + 10) return None # official hexadecimal number function. # I WILL ADD 0x and 0o integer format. It's just funny to do those things like this. fn from-hex(arr): arr map(fn c: c hex-digit() or-fail('"\(c)" is not a hex digit.') u8-size() from-integral()) reduce(0, fn(elem, b): b * 16 + elem) fn u8-str(byte U8) fn b16-char (b U8) -> U8 if b >= 10 return (b - 10) + char-u8('a') else return b + char-u8('0') return SmolStr.from-byte-array([b16-char(byte / 16), b16-char(byte Math.mod(16))])