fmt-0.2.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.

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 #

indent' :: 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.