    module TextBuilderDev.Domains.Digits where

    import qualified Data.ByteString as ByteString
    import qualified Data.List.Split as Split
    import TextBuilder
    import TextBuilderDev.Prelude hiding (intercalate)

    -- | Decimal digit.
    {-# INLINE decimalDigit #-}
    decimalDigit :: (Integral a) => a -> TextBuilder
    decimalDigit :: forall a. Integral a => a -> TextBuilder
    decimalDigit (a -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral -> Int
    n) =
      Int -> TextBuilder
    unicodeCodepoint (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    48)

    -- | Hexadecimal digit.
    {-# INLINE hexadecimalDigit #-}
    hexadecimalDigit :: (Integral a) => a -> TextBuilder
    hexadecimalDigit :: forall a. Integral a => a -> TextBuilder
    hexadecimalDigit (a -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral -> Int
    n) =
      if Int
    n Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    <= Int
    9
        then Int -> TextBuilder
    unicodeCodepoint (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    48)
        else Int -> TextBuilder
    unicodeCodepoint (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    87)

    {-# INLINE signed #-}
    signed :: (Ord a, Num a) => (a -> TextBuilder) -> a -> TextBuilder
    signed :: forall a. (Ord a, Num a) => (a -> TextBuilder) -> a -> TextBuilder
    signed a -> TextBuilder
    onUnsigned a
    i =
      if a
    i a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= a
    0
        then a -> TextBuilder
    onUnsigned a
    i
        else Int -> TextBuilder
    unicodeCodepoint Int
    45 TextBuilder -> TextBuilder -> TextBuilder
    forall a. Semigroup a => a -> a -> a
    <> a -> TextBuilder
    onUnsigned (a -> a
    forall a. Num a => a -> a
    negate a
    i)

    -- | Hexadecimal readable representation of binary data.
    --
    -- >>> byteStringHexEncoding "Hello"
    -- "4865 6c6c 6f"
    {-# INLINE byteStringHexEncoding #-}
    byteStringHexEncoding :: ByteString -> TextBuilder
    byteStringHexEncoding :: ByteString -> TextBuilder
    byteStringHexEncoding =
      TextBuilder -> [TextBuilder] -> TextBuilder
    forall (f :: * -> *).
    Foldable f =>
    TextBuilder -> f TextBuilder -> TextBuilder
    intercalate TextBuilder
    " "
        ([TextBuilder] -> TextBuilder)
    -> (ByteString -> [TextBuilder]) -> ByteString -> TextBuilder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . ([TextBuilder] -> TextBuilder) -> [[TextBuilder]] -> [TextBuilder]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap [TextBuilder] -> TextBuilder
    forall a. Monoid a => [a] -> a
    mconcat
        ([[TextBuilder]] -> [TextBuilder])
    -> (ByteString -> [[TextBuilder]]) -> ByteString -> [TextBuilder]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . Int -> [TextBuilder] -> [[TextBuilder]]
    forall e. Int -> [e] -> [[e]]
    Split.chunksOf Int
    2
        ([TextBuilder] -> [[TextBuilder]])
    -> (ByteString -> [TextBuilder]) -> ByteString -> [[TextBuilder]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . (Word8 -> TextBuilder) -> [Word8] -> [TextBuilder]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Word8 -> TextBuilder
    forall a. (FiniteBits a, Integral a) => a -> TextBuilder
    hexadecimal
        ([Word8] -> [TextBuilder])
    -> (ByteString -> [Word8]) -> ByteString -> [TextBuilder]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . ByteString -> [Word8]
    ByteString.unpack