diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-10-27 22:08:47 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-11-06 21:06:49 +0100 |
| commit | e0762612e95b0816721165c5aba6189809fcde58 (patch) | |
| tree | 57a2b7eed322086e6e19bfa652798d3dceceb6f6 /src/Erebos/Util.hs | |
| parent | 0bb8daa7da52240a971a4ce83d97cfb62971ea78 (diff) | |
ByteString conversion classes
Diffstat (limited to 'src/Erebos/Util.hs')
| -rw-r--r-- | src/Erebos/Util.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Erebos/Util.hs b/src/Erebos/Util.hs index 0d53e98..1c14417 100644 --- a/src/Erebos/Util.hs +++ b/src/Erebos/Util.hs @@ -2,12 +2,12 @@ module Erebos.Util where import Control.Monad -import Data.ByteArray (ByteArray, ByteArrayAccess) -import Data.ByteArray qualified as BA import Data.ByteString (ByteString) import Data.ByteString qualified as B import Data.Char +import ConvertByteString + uniq :: Eq a => [a] -> [a] uniq (x:y:xs) | x == y = uniq (x:xs) @@ -47,15 +47,15 @@ intersectsSorted (x:xs) (y:ys) | x < y = intersectsSorted xs (y:ys) intersectsSorted _ _ = False -showHex :: ByteArrayAccess ba => ba -> ByteString -showHex = B.concat . map showHexByte . BA.unpack +showHex :: ToByteString ba => ba -> ByteString +showHex = B.concat . map showHexByte . B.unpack . toByteString where showHexChar x | x < 10 = x + o '0' | otherwise = x + o 'a' - 10 showHexByte x = B.pack [ showHexChar (x `div` 16), showHexChar (x `mod` 16) ] o = fromIntegral . ord -readHex :: ByteArray ba => ByteString -> Maybe ba -readHex = return . BA.concat <=< readHex' +readHex :: FromByteString ba => ByteString -> Maybe ba +readHex = return . fromByteString . B.concat <=< readHex' where readHex' bs | B.null bs = Just [] readHex' bs = do (bx, bs') <- B.uncons bs (by, bs'') <- B.uncons bs' |