| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Bytes.Formatting
Description
Provides high level formatters for different byte types. This module contains the functions and types for typical usage. Additional functionality (e.g. optics, type classes/families for defining custom formatters) can be found in:
Since: 0.1
Synopsis
- formatSized :: (Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) => BaseFormatter (Raw a) -> SizedFormatter -> a -> Text
- formatSizedDirected :: (Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) => BaseFormatter (Raw a) -> SizedFormatter -> DirectedFormatter -> a -> Text
- data CaseFormat
- data IntegralFormatter = MkIntegralFormatter
- newtype FloatingFormatter = MkFloatingFormatter (Maybe Word8)
- data SizeFormat
- data SizedFormatter = MkSizedFormatter CaseFormat Bool SizeFormat
- sizedFormatterUnix :: SizedFormatter
- sizedFormatterNatural :: SizedFormatter
- sizedFormatterVerbose :: SizedFormatter
- data DirectionFormat
- data DirectedFormatter = MkDirectedFormatter CaseFormat DirectionFormat
- directedFormatterUnix :: DirectedFormatter
- directedFormatterVerbose :: DirectedFormatter
- class Default a where
- def :: a
High-level functions
Arguments
| :: (Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) | |
| => BaseFormatter (Raw a) | Formatter to use on the underlying value i.e. |
| -> SizedFormatter | Formatter to use on the size units. |
| -> a | Value to be formatted. |
| -> Text | Result. |
Formats a value with Size units. Can be used with all byte types
in this package.
Examples
>>>import Data.Default (Default (..))>>>import Data.Bytes (Bytes (..), Size (..), hideSize)>>>let bf1 = MkIntegralFormatter>>>let b1 = MkBytes @M @Int 7>>>formatSized bf1 def b1"7 mb"
>>>formatSized bf1 sizedFormatterUnix b1"7M"
>>>let bf2 = MkFloatingFormatter (Just 2)>>>let b2 = hideSize $ MkBytes @G @Float 20.248>>>formatSized bf2 sizedFormatterVerbose b2"20.25 gigabytes"
Since: 0.1
Arguments
| :: (Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) | |
| => BaseFormatter (Raw a) | Formatter to use on the underlying value i.e. |
| -> SizedFormatter | Formatter to use on the size units. |
| -> DirectedFormatter | Formatter to use on the direction units. |
| -> a | Value to be formatted. |
| -> Text | Result. |
Formats a value with Size and
Direction units. Can only be used when both units
are present.
Examples
>>>import Data.Default (Default (..))>>>import Data.Bytes.Network (Direction (..), NetBytes (..), Size (..))>>>import Data.Bytes.Size (Sized (..))>>>let bf1 = MkIntegralFormatter>>>let b1 = MkNetBytesP @Up @M @Int 7>>>formatSizedDirected bf1 def def b1"7 mb up"
>>>formatSizedDirected bf1 sizedFormatterUnix directedFormatterUnix b1"7M U"
>>>let bf2 = MkFloatingFormatter (Just 2)>>>let b2 = hideSize $ MkNetBytesP @Down @G @Float 20.248>>>formatSizedDirected bf2 sizedFormatterVerbose directedFormatterVerbose b2"20.25 gigabytes down"
Since: 0.1
Types
Base
data CaseFormat Source #
Case formatting.
Since: 0.1
Constructors
| CaseFormatLower | Since: 0.1 |
| CaseFormatTitle | Since: 0.1 |
| CaseFormatUpper | Since: 0.1 |
Instances
| Show CaseFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base Methods showsPrec :: Int -> CaseFormat -> ShowS # show :: CaseFormat -> String # showList :: [CaseFormat] -> ShowS # | |
| Eq CaseFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base | |
data IntegralFormatter Source #
Formatter for integral types.
Since: 0.1
Constructors
| MkIntegralFormatter |
Instances
| Formatter IntegralFormatter Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base Methods formatStr :: IntegralFormatter -> Text Source # | |
newtype FloatingFormatter Source #
Formatter for floating types. Takes an optional param for rounding digits.
Since: 0.1
Constructors
| MkFloatingFormatter (Maybe Word8) |
Instances
| Formatter FloatingFormatter Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Base Methods formatStr :: FloatingFormatter -> Text Source # | |
Size
data SizeFormat Source #
Determines how to format the size units.
Examples
>>>def @SizeFormatSizeFormatMedium
Since: 0.1
Constructors
| SizeFormatShort | Since: 0.1 |
| SizeFormatMedium | Since: 0.1 |
| SizeFormatLong | Since: 0.1 |
Instances
| Show SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size Methods showsPrec :: Int -> SizeFormat -> ShowS # show :: SizeFormat -> String # showList :: [SizeFormat] -> ShowS # | |
| Default SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size Methods def :: SizeFormat Source # | |
| Eq SizeFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Size | |
data SizedFormatter Source #
Formatting size units.
Examples
>>>def @SizedFormatterMkSizedFormatter {caseFormat = CaseFormatLower, leadingSpace = True, sizeFormat = SizeFormatMedium}
Since: 0.1
Constructors
| MkSizedFormatter CaseFormat Bool SizeFormat |
Instances
sizedFormatterUnix :: SizedFormatter Source #
Unix-style formatter:
- Upper case.
- No space between value and unit.
- Single letter unit.
For example: 7G.
Since: 0.1
sizedFormatterNatural :: SizedFormatter Source #
Natural-style formatter:
- Lower case.
- Space between value and unit.
- Two letter units.
For example: 7 gb.
Since: 0.1
sizedFormatterVerbose :: SizedFormatter Source #
Verbose formatter:
- Lower case.
- Space between value and unit.
- Full spelling.
For example: 7 gigabytes.
Since: 0.1
Direction
data DirectionFormat Source #
Determines how to format the direction units.
Examples
>>>def @DirectionFormatDirectionFormatLong
Since: 0.1
Constructors
| DirectionFormatShort | Since: 0.1 |
| DirectionFormatLong | Since: 0.1 |
Instances
| Show DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction Methods showsPrec :: Int -> DirectionFormat -> ShowS # show :: DirectionFormat -> String # showList :: [DirectionFormat] -> ShowS # | |
| Default DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction Methods | |
| Eq DirectionFormat Source # | Since: 0.1 |
Defined in Data.Bytes.Formatting.Direction Methods (==) :: DirectionFormat -> DirectionFormat -> Bool # (/=) :: DirectionFormat -> DirectionFormat -> Bool # | |
data DirectedFormatter Source #
Formats bytes over floating types.
Examples
>>>def @DirectedFormatterMkDirectedFormatter {caseFormat = CaseFormatLower, directionFormat = DirectionFormatLong}
Since: 0.1
Constructors
| MkDirectedFormatter CaseFormat DirectionFormat |
Instances
directedFormatterUnix :: DirectedFormatter Source #
"unix"-style formatter:
- Upper case.
- Short spelling.
For example: 7 U.
Since: 0.1
directedFormatterVerbose :: DirectedFormatter Source #
Verbose formatter:
- Lower case.
- Full spelling.
For example: 7 down.
Since: 0.1
Reexports
class Default a where Source #
A class for types with a default value.
Minimal complete definition
Nothing
Methods
The default value for this type.