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 Source #

Minimal complete definition

fromBuilder

Methods

fromBuilder :: Builder -> a Source #

Convert a Builder to something else.

class FormatAsHex a where Source #

Minimal complete definition

hexF

Methods

hexF :: a -> Builder Source #

Format a number or bytestring as hex:

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

class FormatAsBase64 a where Source #

Minimal complete definition

base64F, base64UrlF

Methods

base64F :: a -> Builder Source #

Convert a bytestring to base64:

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

base64UrlF :: a -> Builder Source #

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 Source #

Minimal complete definition

tupleF

Methods

tupleF :: a -> Builder Source #

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 Source #

Minimal complete definition

gbuild

Methods

gbuild :: f a -> Builder Source #

class GetFields f where Source #

Minimal complete definition

getFields

Methods

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

Get fields, together with their names if available

class Buildable' a where Source #

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 Source #

Polyvariadic format

class FormatType r where Source #

Something like PrintfType in Text.Printf.

Minimal complete definition

format'

Methods

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

Instances

FromBuilder r => FormatType r Source # 

Methods

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

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

Methods

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

Helpers

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

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

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

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

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 Source #

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 Source #

Add an ordinal suffix to a number:

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