module ELynx.Tools.ByteString
(
alignRightWith,
alignRight,
alignLeftWith,
alignLeft,
)
where
import qualified Data.ByteString.Lazy.Char8 as BL
alignRightWith :: Char -> Int -> BL.ByteString -> BL.ByteString
alignRightWith :: Char -> Int -> ByteString -> ByteString
alignRightWith Char
c Int
n ByteString
s =
Int64 -> Char -> ByteString
BL.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
l) Char
c ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int64 -> ByteString -> ByteString
BL.take (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) ByteString
s
where
l :: Int64
l = ByteString -> Int64
BL.length ByteString
s
alignRight :: Int -> BL.ByteString -> BL.ByteString
alignRight :: Int -> ByteString -> ByteString
alignRight = Char -> Int -> ByteString -> ByteString
alignRightWith Char
' '
alignLeftWith :: Char -> Int -> BL.ByteString -> BL.ByteString
alignLeftWith :: Char -> Int -> ByteString -> ByteString
alignLeftWith Char
c Int
n ByteString
s =
Int64 -> ByteString -> ByteString
BL.take (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) ByteString
s ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int64 -> Char -> ByteString
BL.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
l) Char
c
where
l :: Int64
l = ByteString -> Int64
BL.length ByteString
s
alignLeft :: Int -> BL.ByteString -> BL.ByteString
alignLeft :: Int -> ByteString -> ByteString
alignLeft = Char -> Int -> ByteString -> ByteString
alignLeftWith Char
' '