fmt-0.5.0.0: A new formatting library

Safe HaskellNone
LanguageHaskell2010

Fmt.Internal

Contents

Description

A module providing access to internals (in case you really need them). Can change at any time, though probably won't.

It also provides some functions that are used in Time (so that Time wouldn't need to import Fmt).

Synopsis

Classes

class FromBuilder a where #

Minimal complete definition

fromBuilder

Methods

fromBuilder :: Builder -> a #

Convert a Builder to something else.

Instances

FromBuilder Builder # 
FromBuilder Text # 

Methods

fromBuilder :: Builder -> Text #

FromBuilder Text # 

Methods

fromBuilder :: Builder -> Text #

(~) * a Char => FromBuilder [a] # 

Methods

fromBuilder :: Builder -> [a] #

(~) * a () => FromBuilder (IO a) # 

Methods

fromBuilder :: Builder -> IO a #

class FormatAsHex a where #

Minimal complete definition

hexF

Methods

hexF :: a -> Builder #

Format a number or bytestring as hex:

>>> hexF 3635
"e33"
>>> hexF ("\0\50\63\80" :: BS.ByteString)
"00323f50"

Instances

class FormatAsBase64 a where #

Minimal complete definition

base64F, base64UrlF

Methods

base64F :: a -> Builder #

Convert a bytestring to base64:

>>> base64F ("\0\50\63\80" :: BS.ByteString)
"ADI/UA=="

base64UrlF :: a -> Builder #

Convert a bytestring to base64url (a variant of base64 which omits / and thus can be used in URLs):

>>> base64UrlF ("\0\50\63\80" :: BS.ByteString)
"ADI_UA=="

class TupleF a where #

Minimal complete definition

tupleF

Methods

tupleF :: a -> Builder #

Format a tuple (of up to 8 elements):

>>> tupleF (1,2,"hi")
"(1, 2, hi)"

If any of the elements takes several lines, an alternate format is used:

>>> fmt $ tupleF ("test","foo\nbar","more test")
( test
,
  foo
  bar
,
  more test )

Classes used for genericF

class GBuildable f where #

Minimal complete definition

gbuild

Methods

gbuild :: f a -> Builder #

class GetFields f where #

Minimal complete definition

getFields

Methods

getFields :: f a -> [(String, Builder)] #

Get fields, together with their names if available

class Buildable' a where #

A more powerful Buildable used for genericF. Can build functions, tuples, lists, maps, etc., as well as combinations thereof.

Minimal complete definition

build'

Methods

build' :: a -> Builder #

Polyvariadic format

class FormatType r where #

Something like PrintfType in Text.Printf.

Minimal complete definition

format'

Methods

format' :: Format -> [Builder] -> r #

Instances

FromBuilder r => FormatType r # 

Methods

format' :: Format -> [Builder] -> r #

(Buildable a, FormatType r) => FormatType (a -> r) # 

Methods

format' :: Format -> [Builder] -> a -> r #

Helpers

groupInt :: (Buildable a, Integral a) => Int -> Char -> a -> Builder #

atBase :: Integral a => Int -> a -> String #

showSigned' :: Real a => (a -> ShowS) -> a -> ShowS #

indentF' :: Int -> Text -> Builder -> Builder #

Add a prefix to the first line, and indent all lines but the first one.

The output will always end with a newline, even when the input doesn't.

Functions used in Time

fixedF :: Real a => Int -> a -> Builder #

Format a floating-point number without scientific notation:

>>> listF' (fixedF 5) [pi,0.1,10]
"[3.14159, 0.10000, 10.00000]"

ordinalF :: (Buildable a, Integral a) => a -> Builder #

Add an ordinal suffix to a number:

>>> ordinalF 15
"15th"
>>> ordinalF 22
"22nd"