text-format-0.3.2: Text formatting

Copyright(c) 2011 MailRank Inc.
LicenseBSD-style
Maintainerbos@serpentine.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell98

Data.Text.Format

Contents

Description

Fast, efficient, flexible support for formatting text strings.

Synopsis

Types

data Format Source #

A format string. This is intentionally incompatible with other string types, to make it difficult to construct a format string by concatenating string fragments (a very common way to accidentally make code vulnerable to malicious data).

This type is an instance of IsString, so the easiest way to construct a query is to enable the OverloadedStrings language extension and then simply write the query in double quotes.

{-# LANGUAGE OverloadedStrings #-}

import Data.Text.Format

f :: Format
f = "hello {}"

The underlying type is Text, so literal Haskell strings that contain Unicode characters will be correctly handled.

Instances
Eq Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(==) :: Format -> Format -> Bool #

(/=) :: Format -> Format -> Bool #

Ord Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Show Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

IsString Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

fromString :: String -> Format #

Semigroup Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Monoid Format Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

newtype Only a Source #

Use this newtype wrapper for your single parameter if you are formatting a string containing exactly one substitution site.

Constructors

Only 

Fields

Instances
Bounded a => Bounded (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

minBound :: Only a #

maxBound :: Only a #

Enum a => Enum (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

succ :: Only a -> Only a #

pred :: Only a -> Only a #

toEnum :: Int -> Only a #

fromEnum :: Only a -> Int #

enumFrom :: Only a -> [Only a] #

enumFromThen :: Only a -> Only a -> [Only a] #

enumFromTo :: Only a -> Only a -> [Only a] #

enumFromThenTo :: Only a -> Only a -> Only a -> [Only a] #

Eq a => Eq (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(==) :: Only a -> Only a -> Bool #

(/=) :: Only a -> Only a -> Bool #

Floating a => Floating (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

pi :: Only a #

exp :: Only a -> Only a #

log :: Only a -> Only a #

sqrt :: Only a -> Only a #

(**) :: Only a -> Only a -> Only a #

logBase :: Only a -> Only a -> Only a #

sin :: Only a -> Only a #

cos :: Only a -> Only a #

tan :: Only a -> Only a #

asin :: Only a -> Only a #

acos :: Only a -> Only a #

atan :: Only a -> Only a #

sinh :: Only a -> Only a #

cosh :: Only a -> Only a #

tanh :: Only a -> Only a #

asinh :: Only a -> Only a #

acosh :: Only a -> Only a #

atanh :: Only a -> Only a #

log1p :: Only a -> Only a #

expm1 :: Only a -> Only a #

log1pexp :: Only a -> Only a #

log1mexp :: Only a -> Only a #

Fractional a => Fractional (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(/) :: Only a -> Only a -> Only a #

recip :: Only a -> Only a #

fromRational :: Rational -> Only a #

Integral a => Integral (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

quot :: Only a -> Only a -> Only a #

rem :: Only a -> Only a -> Only a #

div :: Only a -> Only a -> Only a #

mod :: Only a -> Only a -> Only a #

quotRem :: Only a -> Only a -> (Only a, Only a) #

divMod :: Only a -> Only a -> (Only a, Only a) #

toInteger :: Only a -> Integer #

Num a => Num (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(+) :: Only a -> Only a -> Only a #

(-) :: Only a -> Only a -> Only a #

(*) :: Only a -> Only a -> Only a #

negate :: Only a -> Only a #

abs :: Only a -> Only a #

signum :: Only a -> Only a #

fromInteger :: Integer -> Only a #

Ord a => Ord (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

compare :: Only a -> Only a -> Ordering #

(<) :: Only a -> Only a -> Bool #

(<=) :: Only a -> Only a -> Bool #

(>) :: Only a -> Only a -> Bool #

(>=) :: Only a -> Only a -> Bool #

max :: Only a -> Only a -> Only a #

min :: Only a -> Only a -> Only a #

Read a => Read (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Real a => Real (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

toRational :: Only a -> Rational #

RealFloat a => RealFloat (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

RealFrac a => RealFrac (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

properFraction :: Integral b => Only a -> (b, Only a) #

truncate :: Integral b => Only a -> b #

round :: Integral b => Only a -> b #

ceiling :: Integral b => Only a -> b #

floor :: Integral b => Only a -> b #

Show a => Show (Only a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

showsPrec :: Int -> Only a -> ShowS #

show :: Only a -> String #

showList :: [Only a] -> ShowS #

Buildable a => Params (Only a) Source # 
Instance details

Defined in Data.Text.Format.Params

Methods

buildParams :: Only a -> [Builder] Source #

Types for format control

newtype Shown a Source #

Render a value using its Show instance.

Constructors

Shown 

Fields

Instances
Bounded a => Bounded (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

minBound :: Shown a #

maxBound :: Shown a #

Enum a => Enum (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

succ :: Shown a -> Shown a #

pred :: Shown a -> Shown a #

toEnum :: Int -> Shown a #

fromEnum :: Shown a -> Int #

enumFrom :: Shown a -> [Shown a] #

enumFromThen :: Shown a -> Shown a -> [Shown a] #

enumFromTo :: Shown a -> Shown a -> [Shown a] #

enumFromThenTo :: Shown a -> Shown a -> Shown a -> [Shown a] #

Eq a => Eq (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(==) :: Shown a -> Shown a -> Bool #

(/=) :: Shown a -> Shown a -> Bool #

Floating a => Floating (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

pi :: Shown a #

exp :: Shown a -> Shown a #

log :: Shown a -> Shown a #

sqrt :: Shown a -> Shown a #

(**) :: Shown a -> Shown a -> Shown a #

logBase :: Shown a -> Shown a -> Shown a #

sin :: Shown a -> Shown a #

cos :: Shown a -> Shown a #

tan :: Shown a -> Shown a #

asin :: Shown a -> Shown a #

acos :: Shown a -> Shown a #

atan :: Shown a -> Shown a #

sinh :: Shown a -> Shown a #

cosh :: Shown a -> Shown a #

tanh :: Shown a -> Shown a #

asinh :: Shown a -> Shown a #

acosh :: Shown a -> Shown a #

atanh :: Shown a -> Shown a #

log1p :: Shown a -> Shown a #

expm1 :: Shown a -> Shown a #

log1pexp :: Shown a -> Shown a #

log1mexp :: Shown a -> Shown a #

Fractional a => Fractional (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(/) :: Shown a -> Shown a -> Shown a #

recip :: Shown a -> Shown a #

fromRational :: Rational -> Shown a #

Integral a => Integral (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

quot :: Shown a -> Shown a -> Shown a #

rem :: Shown a -> Shown a -> Shown a #

div :: Shown a -> Shown a -> Shown a #

mod :: Shown a -> Shown a -> Shown a #

quotRem :: Shown a -> Shown a -> (Shown a, Shown a) #

divMod :: Shown a -> Shown a -> (Shown a, Shown a) #

toInteger :: Shown a -> Integer #

Num a => Num (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

(+) :: Shown a -> Shown a -> Shown a #

(-) :: Shown a -> Shown a -> Shown a #

(*) :: Shown a -> Shown a -> Shown a #

negate :: Shown a -> Shown a #

abs :: Shown a -> Shown a #

signum :: Shown a -> Shown a #

fromInteger :: Integer -> Shown a #

Ord a => Ord (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

compare :: Shown a -> Shown a -> Ordering #

(<) :: Shown a -> Shown a -> Bool #

(<=) :: Shown a -> Shown a -> Bool #

(>) :: Shown a -> Shown a -> Bool #

(>=) :: Shown a -> Shown a -> Bool #

max :: Shown a -> Shown a -> Shown a #

min :: Shown a -> Shown a -> Shown a #

Read a => Read (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Real a => Real (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

toRational :: Shown a -> Rational #

RealFloat a => RealFloat (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

RealFrac a => RealFrac (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

properFraction :: Integral b => Shown a -> (b, Shown a) #

truncate :: Integral b => Shown a -> b #

round :: Integral b => Shown a -> b #

ceiling :: Integral b => Shown a -> b #

floor :: Integral b => Shown a -> b #

Show a => Show (Shown a) Source # 
Instance details

Defined in Data.Text.Format.Types.Internal

Methods

showsPrec :: Int -> Shown a -> ShowS #

show :: Shown a -> String #

showList :: [Shown a] -> ShowS #

Show a => Buildable (Shown a) Source # 
Instance details

Defined in Data.Text.Buildable

Methods

build :: Shown a -> Builder Source #

Rendering

format :: Params ps => Format -> ps -> Text Source #

Render a format string and arguments to a Text.

print :: (MonadIO m, Params ps) => Format -> ps -> m () Source #

Render a format string and arguments, then print the result.

hprint :: (MonadIO m, Params ps) => Handle -> Format -> ps -> m () Source #

Render a format string and arguments, then print the result to the given file handle.

build :: Params ps => Format -> ps -> Builder Source #

Render a format string and arguments to a Builder.

Format control

left :: Buildable a => Int -> Char -> a -> Builder 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 -> a -> Builder Source #

Pad the right hand side of a string until it reaches k characters wide, if necessary filling with character c.

Integers

hex :: Integral a => a -> Builder Source #

Render an integer using hexadecimal notation. (No leading "0x" is added.)

Floating point numbers

expt Source #

Arguments

:: Real a 
=> Int

Number of digits of precision after the decimal.

-> a 
-> Builder 

Render a floating point number using scientific/engineering notation (e.g. 2.3e123), with the given number of decimal places.

fixed Source #

Arguments

:: Real a 
=> Int

Number of digits of precision after the decimal.

-> a 
-> Builder 

Render a floating point number using normal notation, with the given number of decimal places.

prec Source #

Arguments

:: Real a 
=> Int

Number of digits of precision.

-> a 
-> Builder 

Render a floating point number, with the given number of digits of precision. Uses decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

shortest :: Real a => a -> Builder Source #

Render a floating point number using the smallest number of digits that correctly represent it.