Copyright | (c) 2013 Chris Done 2013 Shachaf Ben-Kiki |
---|---|
License | BSD3 |
Maintainer | chrisdone@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
Formatting functions.
- text :: Format r (Text -> r)
- stext :: Format r (Text -> r)
- string :: Format r (String -> r)
- shown :: Show a => Format r (a -> r)
- char :: Format r (Char -> r)
- builder :: Format r (Builder -> r)
- fconst :: Builder -> Format r (a -> r)
- int :: Buildable a => Format r (a -> r)
- float :: Real a => Format r (a -> r)
- fixed :: Real a => Int -> Format r (a -> r)
- sci :: Format r (Scientific -> r)
- scifmt :: FPFormat -> Maybe Int -> Format r (Scientific -> r)
- shortest :: Real a => Format r (a -> r)
- groupInt :: (Buildable n, Integral n) => Int -> Char -> Format r (n -> r)
- commas :: (Buildable n, Integral n) => Format r (n -> r)
- ords :: Integral n => Format r (n -> r)
- plural :: (Num a, Eq a) => Text -> Text -> Format r (a -> r)
- asInt :: Enum a => Format r (a -> r)
- left :: Buildable a => Int -> Char -> Format r (a -> r)
- right :: Buildable a => Int -> Char -> Format r (a -> r)
- center :: Buildable a => Int -> Char -> Format r (a -> r)
- fitLeft :: Buildable a => Int -> Format r (a -> r)
- fitRight :: Buildable a => Int -> Format r (a -> r)
- base :: Integral a => Int -> Format r (a -> r)
- bin :: Integral a => Format r (a -> r)
- oct :: Integral a => Format r (a -> r)
- hex :: Integral a => Format r (a -> r)
- prefixBin :: Integral a => Format r (a -> r)
- prefixOct :: Integral a => Format r (a -> r)
- prefixHex :: Integral a => Format r (a -> r)
- bytes :: (Ord f, Integral a, Fractional f) => Format Builder (f -> Builder) -> Format r (a -> r)
- build :: Buildable a => Format r (a -> r)
- class Buildable p
Text/string types
Numbers
float :: Real a => Format r (a -> r) Source #
Render some floating point with the usual notation, e.g. 123.32 => "123.32"
fixed :: Real a => Int -> Format r (a -> r) Source #
Render a floating point number using normal notation, with the given number of decimal places.
sci :: Format r (Scientific -> r) Source #
Render a scientific number.
scifmt :: FPFormat -> Maybe Int -> Format r (Scientific -> r) Source #
Render a scientific number with options.
shortest :: Real a => Format r (a -> r) Source #
Render a floating point number using the smallest number of digits that correctly represent it.
groupInt :: (Buildable n, Integral n) => Int -> Char -> Format r (n -> r) Source #
Group integral numbers, e.g. groupInt 2 .
on 123456 -> "12.34.56".
commas :: (Buildable n, Integral n) => Format r (n -> r) Source #
Add commas to an integral, e.g 12000 -> "12,000".
ords :: Integral n => Format r (n -> r) Source #
Add a suffix to an integral, e.g. 1st, 2nd, 3rd, 21st.
plural :: (Num a, Eq a) => Text -> Text -> Format r (a -> r) Source #
English plural suffix for an integral.
asInt :: Enum a => Format r (a -> r) Source #
Shows the Int value of Enum instances using fromEnum
.
>>>
format ("Got: " % char % " (" % asInt % ")") 'a' 'a'
"Got: a (97)"
Padding
left :: Buildable a => Int -> Char -> Format r (a -> r) Source #
Pad the left hand side of a string until it reaches k characters wide, if necessary filling with character c.
right :: Buildable a => Int -> Char -> Format r (a -> r) Source #
Pad the right hand side of a string until it reaches k characters wide, if necessary filling with character c.
center :: Buildable a => Int -> Char -> Format r (a -> r) Source #
Pad the left & right hand side of a string until it reaches k characters wide, if necessary filling with character c.
fitLeft :: Buildable a => Int -> Format r (a -> r) Source #
Fit in the given length, truncating on the left.
fitRight :: Buildable a => Int -> Format r (a -> r) Source #
Fit in the given length, truncating on the right.
Bases
bin :: Integral a => Format r (a -> r) Source #
Render an integer using binary notation. (No leading 0b is
added.) Defined as bin =
.base
2
oct :: Integral a => Format r (a -> r) Source #
Render an integer using octal notation. (No leading 0o is
added.) Defined as oct =
.base
8
hex :: Integral a => Format r (a -> r) Source #
Render an integer using hexadecimal notation. (No leading 0x is added.) Has a specialized implementation.
prefixBin :: Integral a => Format r (a -> r) Source #
Render an integer using binary notation with a leading 0b.
prefixOct :: Integral a => Format r (a -> r) Source #
Render an integer using octal notation with a leading 0o.
prefixHex :: Integral a => Format r (a -> r) Source #
Render an integer using hexadecimal notation with a leading 0x.
:: (Ord f, Integral a, Fractional f) | |
=> Format Builder (f -> Builder) | formatter for the decimal part |
-> Format r (a -> r) |
Renders a given byte count using an appropiate decimal binary suffix:
>>>
format (bytes shortest) 1024
"1KB"
>>>
format (bytes (fixed 2 % " ")) (1024*1024*5)
"5.00 MB"
Buildables
build :: Buildable a => Format r (a -> r) Source #
Build anything that implements the Buildable class.
The class of types that can be rendered to a Builder
.