base16

Pure Haskell base16 encoding/decoding (docs.ppad.tech/base16).
git clone git://git.ppad.tech/base16.git
Log | Files | Refs | README | LICENSE

commit 8e191be7f9227b4a59051b04c3e964f3f32f1155
parent 4439e0efafbb5185bd7d9bfb352a17c2a31b96b4
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 28 Feb 2025 09:05:23 +0400

lib: more efficient word8 -> word4

Diffstat:
Mlib/Data/ByteString/Base16.hs | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/Data/ByteString/Base16.hs b/lib/Data/ByteString/Base16.hs @@ -122,8 +122,12 @@ encode bs@(BI.PS _ _ l) let !w16 = expand_w8 h in BSB.word16BE w16 <> go16 t +-- word8 hex character to word4 word4 :: Word8 -> Maybe Word8 -word4 w8 = fmap fi (BS.elemIndex w8 hex_charset) +word4 c + | c > 47 && c < 58 = pure $! c - 48 + | c > 96 && c < 103 = pure $! c - 87 + | otherwise = Nothing {-# INLINE word4 #-} -- | Decode a base16 'ByteString' to base256.