text-format-0.3.2.1: Text formatting
Copyright(c) 2011 MailRank Inc.
LicenseBSD-style
Maintainerbos@serpentine.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell98

Data.Text.Format

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.

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

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

Defined in Data.Text.Format.Types.Internal

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

Defined in Data.Text.Format.Types.Internal

Methods

succ :: Only a -> Only a Source #

pred :: Only a -> Only a Source #

toEnum :: Int -> Only a Source #

fromEnum :: Only a -> Int Source #

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

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

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

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

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

Defined in Data.Text.Format.Types.Internal

Methods

pi :: Only a Source #

exp :: Only a -> Only a Source #

log :: Only a -> Only a Source #

sqrt :: Only a -> Only a Source #

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

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

sin :: Only a -> Only a Source #

cos :: Only a -> Only a Source #

tan :: Only a -> Only a Source #

asin :: Only a -> Only a Source #

acos :: Only a -> Only a Source #

atan :: Only a -> Only a Source #

sinh :: Only a -> Only a Source #

cosh :: Only a -> Only a Source #

tanh :: Only a -> Only a Source #

asinh :: Only a -> Only a Source #

acosh :: Only a -> Only a Source #

atanh :: Only a -> Only a Source #

log1p :: Only a -> Only a Source #

expm1 :: Only a -> Only a Source #

log1pexp :: Only a -> Only a Source #

log1mexp :: Only a -> Only a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

recip :: Only a -> Only a Source #

fromRational :: Rational -> Only a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

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

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

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

toInteger :: Only a -> Integer Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

negate :: Only a -> Only a Source #

abs :: Only a -> Only a Source #

signum :: Only a -> Only a Source #

fromInteger :: Integer -> Only a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Defined in Data.Text.Format.Types.Internal

Methods

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

show :: Only a -> String Source #

showList :: [Only a] -> ShowS Source #

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

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

Defined in Data.Text.Format.Types.Internal

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

Defined in Data.Text.Format.Types.Internal

Methods

succ :: Shown a -> Shown a Source #

pred :: Shown a -> Shown a Source #

toEnum :: Int -> Shown a Source #

fromEnum :: Shown a -> Int Source #

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

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

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

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

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

Defined in Data.Text.Format.Types.Internal

Methods

pi :: Shown a Source #

exp :: Shown a -> Shown a Source #

log :: Shown a -> Shown a Source #

sqrt :: Shown a -> Shown a Source #

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

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

sin :: Shown a -> Shown a Source #

cos :: Shown a -> Shown a Source #

tan :: Shown a -> Shown a Source #

asin :: Shown a -> Shown a Source #

acos :: Shown a -> Shown a Source #

atan :: Shown a -> Shown a Source #

sinh :: Shown a -> Shown a Source #

cosh :: Shown a -> Shown a Source #

tanh :: Shown a -> Shown a Source #

asinh :: Shown a -> Shown a Source #

acosh :: Shown a -> Shown a Source #

atanh :: Shown a -> Shown a Source #

log1p :: Shown a -> Shown a Source #

expm1 :: Shown a -> Shown a Source #

log1pexp :: Shown a -> Shown a Source #

log1mexp :: Shown a -> Shown a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

recip :: Shown a -> Shown a Source #

fromRational :: Rational -> Shown a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

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

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

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

toInteger :: Shown a -> Integer Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

negate :: Shown a -> Shown a Source #

abs :: Shown a -> Shown a Source #

signum :: Shown a -> Shown a Source #

fromInteger :: Integer -> Shown a Source #

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

Defined in Data.Text.Format.Types.Internal

Methods

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Defined in Data.Text.Format.Types.Internal

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.