module Data.Bytes.Formatting
(
formatSized,
formatSizedDirected,
CaseFormat (..),
IntegralFormatter (..),
FloatingFormatter (..),
SizeFormat (..),
SizedFormatter (MkSizedFormatter),
sizedFormatterUnix,
sizedFormatterNatural,
sizedFormatterVerbose,
DirectionFormat (..),
DirectedFormatter (MkDirectedFormatter),
directedFormatterUnix,
directedFormatterVerbose,
Default (def),
)
where
import Data.Bytes.Class.RawNumeric (RawNumeric (Raw, toRaw))
import Data.Bytes.Formatting.Base
( BaseFormatter,
CaseFormat (CaseFormatLower, CaseFormatTitle, CaseFormatUpper),
FloatingFormatter (MkFloatingFormatter),
Formatter,
IntegralFormatter (MkIntegralFormatter),
formatBase,
)
import Data.Bytes.Formatting.Direction
( DirectedFormatter (MkDirectedFormatter),
DirectionFormat (DirectionFormatLong, DirectionFormatShort),
directedFormatterUnix,
directedFormatterVerbose,
formatDirection,
)
import Data.Bytes.Formatting.Size
( SizeFormat (SizeFormatLong, SizeFormatMedium, SizeFormatShort),
SizedFormatter (MkSizedFormatter),
formatSize,
sizedFormatterNatural,
sizedFormatterUnix,
sizedFormatterVerbose,
)
import Data.Bytes.Network.Direction (Directed)
import Data.Bytes.Size (Sized)
import Data.Default (Default (def))
import Data.Text (Text)
import Text.Printf (PrintfArg)
formatSized ::
( Formatter (BaseFormatter (Raw a)),
PrintfArg (Raw a),
RawNumeric a,
Sized a
) =>
BaseFormatter (Raw a) ->
SizedFormatter ->
a ->
Text
formatSized :: forall a.
(Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a),
RawNumeric a, Sized a) =>
BaseFormatter (Raw a) -> SizedFormatter -> a -> Text
formatSized BaseFormatter (Raw a)
basefmt SizedFormatter
sizefmt a
x =
BaseFormatter (Raw a) -> Raw a -> Text
forall a f.
(BaseFormatter a ~ f, Formatter f, PrintfArg a) =>
f -> a -> Text
formatBase BaseFormatter (Raw a)
basefmt (a -> Raw a
forall a. RawNumeric a => a -> Raw a
toRaw a
x) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> SizedFormatter -> a -> Text
forall a. Sized a => SizedFormatter -> a -> Text
formatSize SizedFormatter
sizefmt a
x
formatSizedDirected ::
( Directed a,
Formatter (BaseFormatter (Raw a)),
PrintfArg (Raw a),
RawNumeric a,
Sized a
) =>
BaseFormatter (Raw a) ->
SizedFormatter ->
DirectedFormatter ->
a ->
Text
formatSizedDirected :: forall a.
(Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a),
RawNumeric a, Sized a) =>
BaseFormatter (Raw a)
-> SizedFormatter -> DirectedFormatter -> a -> Text
formatSizedDirected BaseFormatter (Raw a)
basefmt SizedFormatter
sizefmt DirectedFormatter
dirfmt a
x =
[Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ BaseFormatter (Raw a) -> Raw a -> Text
forall a f.
(BaseFormatter a ~ f, Formatter f, PrintfArg a) =>
f -> a -> Text
formatBase BaseFormatter (Raw a)
basefmt (a -> Raw a
forall a. RawNumeric a => a -> Raw a
toRaw a
x),
SizedFormatter -> a -> Text
forall a. Sized a => SizedFormatter -> a -> Text
formatSize SizedFormatter
sizefmt a
x,
DirectedFormatter -> a -> Text
forall a. Directed a => DirectedFormatter -> a -> Text
formatDirection DirectedFormatter
dirfmt a
x
]