module ELynx.Tools.ByteString
(
alignRightWith
, alignRight
, alignLeftWith
, alignLeft
, summarizeByteString
, c2w
, w2c
, bsShow
) where
import Data.ByteString.Internal (c2w, w2c)
import qualified Data.ByteString.Lazy.Char8 as L
alignRightWith :: Char -> Int -> L.ByteString -> L.ByteString
alignRightWith c n s = L.replicate (fromIntegral n - l) c <> L.take (fromIntegral n) s
where l = L.length s
alignRight :: Int -> L.ByteString -> L.ByteString
alignRight = alignRightWith ' '
alignLeftWith :: Char -> Int -> L.ByteString -> L.ByteString
alignLeftWith c n s = L.take (fromIntegral n) s <> L.replicate (fromIntegral n - l) c
where l = L.length s
alignLeft :: Int -> L.ByteString -> L.ByteString
alignLeft = alignLeftWith ' '
summarizeByteString :: Int -> L.ByteString -> L.ByteString
summarizeByteString l s | L.length s >= fromIntegral l = L.take (fromIntegral l) s <> L.pack "..."
| otherwise = s
bsShow :: Show a => a -> L.ByteString
bsShow = L.pack . show