{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Fmt.Internal.Formatters where
import Data.List (intersperse)
import Lens.Micro
#if __GLASGOW_HASKELL__ < 804
import Data.Monoid ((<>))
#endif
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Text (Text)
import Formatting.Buildable
import qualified Formatting.Internal.Raw as F
import Data.Text.Lazy.Builder hiding (fromString)
import Data.Foldable (toList)
import GHC.Exts (IsList, Item)
import qualified GHC.Exts as IsList (toList)
import Fmt.Internal.Core
indentF :: Int -> Builder -> Builder
indentF :: Int -> Builder -> Builder
indentF Int
n Builder
a = case Text -> [Text]
TL.lines (Builder -> Text
toLazyText Builder
a) of
[] -> Text -> Builder
fromLazyText (Text
spaces Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n")
[Text]
xs -> Text -> Builder
fromLazyText (Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
TL.unlines ((Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text
spaces Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) [Text]
xs)
where
spaces :: Text
spaces = Int64 -> Text -> Text
TL.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) (Char -> Text
TL.singleton Char
' ')
indentF' :: Int -> T.Text -> Builder -> Builder
indentF' :: Int -> Text -> Builder -> Builder
indentF' Int
n Text
pref Builder
a = case Text -> [Text]
TL.lines (Builder -> Text
toLazyText Builder
a) of
[] -> Text -> Builder
fromText Text
pref Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n"
(Text
x:[Text]
xs) -> Text -> Builder
fromLazyText (Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$
[Text] -> Text
TL.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Text
TL.fromStrict Text
pref Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x) Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text
spaces Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) [Text]
xs
where
spaces :: Text
spaces = Int64 -> Text -> Text
TL.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) (Char -> Text
TL.singleton Char
' ')
nameF :: Builder -> Builder -> Builder
nameF :: Builder -> Builder -> Builder
nameF Builder
k Builder
v = case Text -> [Text]
TL.lines (Builder -> Text
toLazyText Builder
v) of
[] -> Builder
k Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":\n"
[Text
l] -> Builder
k Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
": " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
fromLazyText Text
l Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n"
[Text]
ls -> Builder
k Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
fromLazyText Text
s Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n" | Text
s <- [Text]
ls]
unwordsF :: (Foldable f, Buildable a) => f a -> Builder
unwordsF :: f a -> Builder
unwordsF = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder) -> (f a -> [Builder]) -> f a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse Builder
" " ([Builder] -> [Builder]) -> (f a -> [Builder]) -> f a -> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Builder) -> [a] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map a -> Builder
forall p. Buildable p => p -> Builder
build ([a] -> [Builder]) -> (f a -> [a]) -> f a -> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
{-# SPECIALIZE unwordsF :: Buildable a => [a] -> Builder #-}
unlinesF :: (Foldable f, Buildable a) => f a -> Builder
unlinesF :: f a -> Builder
unlinesF = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder) -> (f a -> [Builder]) -> f a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Builder) -> [a] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (Builder -> Builder
nl (Builder -> Builder) -> (a -> Builder) -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Builder
forall p. Buildable p => p -> Builder
build) ([a] -> [Builder]) -> (f a -> [a]) -> f a -> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
where
nl :: Builder -> Builder
nl Builder
x | Text
"\n" Text -> Text -> Bool
`TL.isSuffixOf` Builder -> Text
toLazyText Builder
x = Builder
x
| Bool
otherwise = Builder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n"
{-# SPECIALIZE unlinesF :: Buildable a => [a] -> Builder #-}
listF :: (Foldable f, Buildable a) => f a -> Builder
listF :: f a -> Builder
listF = (a -> Builder) -> f a -> Builder
forall (f :: * -> *) a.
Foldable f =>
(a -> Builder) -> f a -> Builder
listF' a -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE listF #-}
listF' :: (Foldable f) => (a -> Builder) -> f a -> Builder
listF' :: (a -> Builder) -> f a -> Builder
listF' a -> Builder
fbuild f a
xs = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$
Builder
"[" Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
:
Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse Builder
", " ((a -> Builder) -> [a] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map a -> Builder
fbuild (f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f a
xs)) [Builder] -> [Builder] -> [Builder]
forall a. [a] -> [a] -> [a]
++
[Builder
"]"]
{-# SPECIALIZE listF' :: (a -> Builder) -> [a] -> Builder #-}
blockListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder
blockListF :: f a -> Builder
blockListF = Text -> (a -> Builder) -> f a -> Builder
forall (f :: * -> *) a.
Foldable f =>
Text -> (a -> Builder) -> f a -> Builder
blockListF' Text
"-" a -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE blockListF #-}
blockListF'
:: forall f a. Foldable f
=> Text
-> (a -> Builder)
-> f a
-> Builder
blockListF' :: Text -> (a -> Builder) -> f a -> Builder
blockListF' Text
bullet a -> Builder
fbuild f a
xs = if [Builder] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Builder]
items then Builder
"[]\n" else [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder]
items
where
items :: [Builder]
items = (a -> Builder) -> [a] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map a -> Builder
buildItem (f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f a
xs)
spaces :: Builder
spaces = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ Int -> Builder -> [Builder]
forall a. Int -> a -> [a]
replicate (Text -> Int
T.length Text
bullet Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Char -> Builder
singleton Char
' ')
buildItem :: a -> Builder
buildItem a
x = case Text -> [Text]
TL.lines (Builder -> Text
toLazyText (a -> Builder
fbuild a
x)) of
[] -> Text
bullet Text -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
"\n"
(Text
l:[Text]
ls) -> Text
bullet Text -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Text
l Text -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
"\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder
spaces Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
fromLazyText Text
s Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n" | Text
s <- [Text]
ls]
{-# SPECIALIZE blockListF' :: Text -> (a -> Builder) -> [a] -> Builder #-}
jsonListF :: forall f a. (Foldable f, Buildable a) => f a -> Builder
jsonListF :: f a -> Builder
jsonListF = (a -> Builder) -> f a -> Builder
forall (f :: * -> *) a.
Foldable f =>
(a -> Builder) -> f a -> Builder
jsonListF' a -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE jsonListF #-}
jsonListF' :: forall f a. (Foldable f) => (a -> Builder) -> f a -> Builder
jsonListF' :: (a -> Builder) -> f a -> Builder
jsonListF' a -> Builder
fbuild f a
xs
| [Builder] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Builder]
items = Builder
"[]\n"
| Bool
otherwise = Builder
"[\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder]
items Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"]\n"
where
items :: [Builder]
items = (Bool -> a -> Builder) -> [Bool] -> [a] -> [Builder]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Bool -> a -> Builder
buildItem (Bool
True Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: Bool -> [Bool]
forall a. a -> [a]
repeat Bool
False) (f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f a
xs)
buildItem :: Bool -> a -> Builder
buildItem :: Bool -> a -> Builder
buildItem Bool
isFirst a
x =
case (Text -> Builder) -> [Text] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Builder
fromLazyText (Text -> [Text]
TL.lines (Builder -> Text
toLazyText (a -> Builder
fbuild a
x))) of
[] | Bool
isFirst -> Builder
"\n"
| Bool
otherwise -> Builder
",\n"
[Builder]
ls ->
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder)
-> ([Builder] -> [Builder]) -> [Builder] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> Builder) -> [Builder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n") ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$
[Builder]
ls [Builder] -> ([Builder] -> [Builder]) -> [Builder]
forall a b. a -> (a -> b) -> b
& (Builder -> Identity Builder) -> [Builder] -> Identity [Builder]
forall s a. Cons s s a a => Traversal' s a
_head ((Builder -> Identity Builder) -> [Builder] -> Identity [Builder])
-> (Builder -> Builder) -> [Builder] -> [Builder]
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (if Bool
isFirst then (Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) else (Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>))
[Builder] -> ([Builder] -> [Builder]) -> [Builder]
forall a b. a -> (a -> b) -> b
& ([Builder] -> Identity [Builder])
-> [Builder] -> Identity [Builder]
forall s a. Cons s s a a => Traversal' s s
_tail(([Builder] -> Identity [Builder])
-> [Builder] -> Identity [Builder])
-> ((Builder -> Identity Builder)
-> [Builder] -> Identity [Builder])
-> (Builder -> Identity Builder)
-> [Builder]
-> Identity [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Builder -> Identity Builder) -> [Builder] -> Identity [Builder]
forall s t a b. Each s t a b => Traversal s t a b
each ((Builder -> Identity Builder) -> [Builder] -> Identity [Builder])
-> (Builder -> Builder) -> [Builder] -> [Builder]
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>)
{-# SPECIALIZE jsonListF' :: (a -> Builder) -> [a] -> Builder #-}
mapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder
mapF :: t -> Builder
mapF = (k -> Builder) -> (v -> Builder) -> t -> Builder
forall t k v.
(IsList t, Item t ~ (k, v)) =>
(k -> Builder) -> (v -> Builder) -> t -> Builder
mapF' k -> Builder
forall p. Buildable p => p -> Builder
build v -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE mapF #-}
mapF'
:: (IsList t, Item t ~ (k, v))
=> (k -> Builder) -> (v -> Builder) -> t -> Builder
mapF' :: (k -> Builder) -> (v -> Builder) -> t -> Builder
mapF' k -> Builder
fbuild_k v -> Builder
fbuild_v t
xs =
Builder
"{" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat (Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse Builder
", " (((k, v) -> Builder) -> [(k, v)] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (k, v) -> Builder
buildPair (t -> [Item t]
forall l. IsList l => l -> [Item l]
IsList.toList t
xs))) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"}"
where
buildPair :: (k, v) -> Builder
buildPair (k
k, v
v) = k -> Builder
fbuild_k k
k Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
": " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> v -> Builder
fbuild_v v
v
blockMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder
blockMapF :: t -> Builder
blockMapF = (k -> Builder) -> (v -> Builder) -> t -> Builder
forall t k v.
(IsList t, Item t ~ (k, v)) =>
(k -> Builder) -> (v -> Builder) -> t -> Builder
blockMapF' k -> Builder
forall p. Buildable p => p -> Builder
build v -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE blockMapF #-}
blockMapF'
:: (IsList t, Item t ~ (k, v))
=> (k -> Builder) -> (v -> Builder) -> t -> Builder
blockMapF' :: (k -> Builder) -> (v -> Builder) -> t -> Builder
blockMapF' k -> Builder
fbuild_k v -> Builder
fbuild_v t
xs
| [Builder] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Builder]
items = Builder
"{}\n"
| Bool
otherwise = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder]
items
where
items :: [Builder]
items = ((k, v) -> Builder) -> [(k, v)] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (\(k
k, v
v) -> Builder -> Builder -> Builder
nameF (k -> Builder
fbuild_k k
k) (v -> Builder
fbuild_v v
v)) (t -> [Item t]
forall l. IsList l => l -> [Item l]
IsList.toList t
xs)
jsonMapF :: (IsList t, Item t ~ (k, v), Buildable k, Buildable v) => t -> Builder
jsonMapF :: t -> Builder
jsonMapF = (k -> Builder) -> (v -> Builder) -> t -> Builder
forall t k v.
(IsList t, Item t ~ (k, v)) =>
(k -> Builder) -> (v -> Builder) -> t -> Builder
jsonMapF' k -> Builder
forall p. Buildable p => p -> Builder
build v -> Builder
forall p. Buildable p => p -> Builder
build
{-# INLINE jsonMapF #-}
jsonMapF'
:: forall t k v.
(IsList t, Item t ~ (k, v))
=> (k -> Builder) -> (v -> Builder) -> t -> Builder
jsonMapF' :: (k -> Builder) -> (v -> Builder) -> t -> Builder
jsonMapF' k -> Builder
fbuild_k v -> Builder
fbuild_v t
xs
| [Builder] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Builder]
items = Builder
"{}\n"
| Bool
otherwise = Builder
"{\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder]
items Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"}\n"
where
items :: [Builder]
items = (Bool -> (k, v) -> Builder) -> [Bool] -> [(k, v)] -> [Builder]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Bool -> (k, v) -> Builder
buildItem (Bool
True Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: Bool -> [Bool]
forall a. a -> [a]
repeat Bool
False) (t -> [Item t]
forall l. IsList l => l -> [Item l]
IsList.toList t
xs)
buildItem :: Bool -> (k, v) -> Builder
buildItem :: Bool -> (k, v) -> Builder
buildItem Bool
isFirst (k
k, v
v) = do
let kb :: Builder
kb = (if Bool
isFirst then Builder
" " else Builder
", ") Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> k -> Builder
fbuild_k k
k
case (Text -> Builder) -> [Text] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Builder
fromLazyText (Text -> [Text]
TL.lines (Builder -> Text
toLazyText (v -> Builder
fbuild_v v
v))) of
[] -> Builder
kb Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":\n"
[Builder
l] -> Builder
kb Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
": " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
l Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n"
[Builder]
ls -> Builder
kb Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat [Builder
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
s Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n" | Builder
s <- [Builder]
ls]
maybeF :: Buildable a => Maybe a -> Builder
maybeF :: Maybe a -> Builder
maybeF = Builder -> (a -> Builder) -> Maybe a -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"<Nothing>" a -> Builder
forall p. Buildable p => p -> Builder
build
eitherF :: (Buildable a, Buildable b) => Either a b -> Builder
eitherF :: Either a b -> Builder
eitherF = (a -> Builder) -> (b -> Builder) -> Either a b -> Builder
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\a
x -> Builder
"<Left: " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> a -> Builder
forall p. Buildable p => p -> Builder
build a
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
">")
(\b
x -> Builder
"<Right: " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> b -> Builder
forall p. Buildable p => p -> Builder
build b
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
">")
prefixF :: Buildable a => Int -> a -> Builder
prefixF :: Int -> a -> Builder
prefixF Int
size =
Text -> Builder
fromLazyText (Text -> Builder) -> (a -> Text) -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Text -> Text
TL.take (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
size) (Text -> Text) -> (a -> Text) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
toLazyText (Builder -> Text) -> (a -> Builder) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Builder
forall p. Buildable p => p -> Builder
build
suffixF :: Buildable a => Int -> a -> Builder
suffixF :: Int -> a -> Builder
suffixF Int
size =
Text -> Builder
fromLazyText (Text -> Builder) -> (a -> Text) -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(\Text
t -> Int64 -> Text -> Text
TL.drop (Text -> Int64
TL.length Text
t Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
size) Text
t) (Text -> Text) -> (a -> Text) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Builder -> Text
toLazyText (Builder -> Text) -> (a -> Builder) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Builder
forall p. Buildable p => p -> Builder
build
padLeftF :: Buildable a => Int -> Char -> a -> Builder
padLeftF :: Int -> Char -> a -> Builder
padLeftF = Int -> Char -> a -> Builder
forall a. Buildable a => Int -> Char -> a -> Builder
F.left
padRightF :: Buildable a => Int -> Char -> a -> Builder
padRightF :: Int -> Char -> a -> Builder
padRightF = Int -> Char -> a -> Builder
forall a. Buildable a => Int -> Char -> a -> Builder
F.right
padBothF :: Buildable a => Int -> Char -> a -> Builder
padBothF :: Int -> Char -> a -> Builder
padBothF Int
i Char
c =
Text -> Builder
fromLazyText (Text -> Builder) -> (a -> Text) -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Char -> Text -> Text
TL.center (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i) Char
c (Text -> Text) -> (a -> Text) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
toLazyText (Builder -> Text) -> (a -> Builder) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Builder
forall p. Buildable p => p -> Builder
build
whenF :: Bool -> Builder -> Builder
whenF :: Bool -> Builder -> Builder
whenF Bool
True Builder
x = Builder
x
whenF Bool
False Builder
_ = Builder
forall a. Monoid a => a
mempty
{-# INLINE whenF #-}
unlessF :: Bool -> Builder -> Builder
unlessF :: Bool -> Builder -> Builder
unlessF Bool
False Builder
x = Builder
x
unlessF Bool
True Builder
_ = Builder
forall a. Monoid a => a
mempty
{-# INLINE unlessF #-}