Copyright | (c) 2011 MailRank Inc. |
---|---|
License | BSD-style |
Maintainer | bos@serpentine.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
Data.Text.Format
Description
Fast, efficient, flexible support for formatting text strings.
Synopsis
- data Format
- newtype Only a = Only {
- fromOnly :: a
- newtype Shown a = Shown {
- shown :: a
- format :: Params ps => Format -> ps -> Text
- print :: (MonadIO m, Params ps) => Format -> ps -> m ()
- hprint :: (MonadIO m, Params ps) => Handle -> Format -> ps -> m ()
- build :: Params ps => Format -> ps -> Builder
- left :: Buildable a => Int -> Char -> a -> Builder
- right :: Buildable a => Int -> Char -> a -> Builder
- hex :: Integral a => a -> Builder
- expt :: Real a => Int -> a -> Builder
- fixed :: Real a => Int -> a -> Builder
- prec :: Real a => Int -> a -> Builder
- shortest :: Real a => a -> Builder
Types
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.
Use this newtype
wrapper for your single parameter if you are
formatting a string containing exactly one substitution site.
Instances
Bounded a => Bounded (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Enum a => Enum (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Eq a => Eq (Only a) Source # | |
Floating a => Floating (Only a) Source # | |
Fractional a => Fractional (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Integral a => Integral (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Num a => Num (Only a) Source # | |
Ord a => Ord (Only a) Source # | |
Read a => Read (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Real a => Real (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal Methods toRational :: Only a -> Rational | |
RealFloat a => RealFloat (Only a) Source # | |
Defined in Data.Text.Format.Types.Internal Methods floatRadix :: Only a -> Integer floatDigits :: Only a -> Int floatRange :: Only a -> (Int, Int) decodeFloat :: Only a -> (Integer, Int) encodeFloat :: Integer -> Int -> Only a significand :: Only a -> Only a scaleFloat :: Int -> Only a -> Only a isInfinite :: Only a -> Bool isDenormalized :: Only a -> Bool isNegativeZero :: Only a -> Bool | |
RealFrac a => RealFrac (Only a) Source # | |
Show a => Show (Only a) Source # | |
Buildable a => Params (Only a) Source # | |
Defined in Data.Text.Format.Params Methods buildParams :: Only a -> [Builder] Source # |
Types for format control
Render a value using its Show
instance.
Instances
Bounded a => Bounded (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Enum a => Enum (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Eq a => Eq (Shown a) Source # | |
Floating a => Floating (Shown a) Source # | |
Fractional a => Fractional (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Integral a => Integral (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Num a => Num (Shown a) Source # | |
Ord a => Ord (Shown a) Source # | |
Read a => Read (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal | |
Real a => Real (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal Methods toRational :: Shown a -> Rational | |
RealFloat a => RealFloat (Shown a) Source # | |
Defined in Data.Text.Format.Types.Internal Methods floatRadix :: Shown a -> Integer floatDigits :: Shown a -> Int floatRange :: Shown a -> (Int, Int) decodeFloat :: Shown a -> (Integer, Int) encodeFloat :: Integer -> Int -> Shown a significand :: Shown a -> Shown a scaleFloat :: Int -> Shown a -> Shown a isInfinite :: Shown a -> Bool isDenormalized :: Shown a -> Bool isNegativeZero :: Shown a -> Bool | |
RealFrac a => RealFrac (Shown a) Source # | |
Show a => Show (Shown a) Source # | |
Show a => Buildable (Shown a) Source # | |
Defined in Data.Text.Buildable |
Rendering
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
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.
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.
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.