stdio-0.1.0.0: A simple and high performance IO toolkit for Haskell

Copyright(c) Dong Han 2017-2019
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Std.Data.TextBuilder

Contents

Description

UTF8 compatible textual builders.

Synopsis

Textual Builder

newtype TextBuilder a Source #

Buidlers which guarantee UTF-8 encoding, thus can be used to build text directly.

Notes on IsString instance: It's recommended to use IsString instance instead of stringUTF8 or string7 since there's a rewrite rule to turn encoding loop into a memcpy, which is much faster.

Different from 'Builder ()', 'TextBuilder ()''s IsString instance will gives desired UTF8 guarantees:

  • "NUL" will be written directly as x00.
  • xD800 ~ xDFFF will be replaced by replacement char.

Constructors

TextBuilder 

Fields

Instances
Monad TextBuilder Source # 
Instance details

Defined in Std.Data.TextBuilder

Functor TextBuilder Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

fmap :: (a -> b) -> TextBuilder a -> TextBuilder b #

(<$) :: a -> TextBuilder b -> TextBuilder a #

Applicative TextBuilder Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

pure :: a -> TextBuilder a #

(<*>) :: TextBuilder (a -> b) -> TextBuilder a -> TextBuilder b #

liftA2 :: (a -> b -> c) -> TextBuilder a -> TextBuilder b -> TextBuilder c #

(*>) :: TextBuilder a -> TextBuilder b -> TextBuilder b #

(<*) :: TextBuilder a -> TextBuilder b -> TextBuilder a #

a ~ () => IsString (TextBuilder a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Semigroup (TextBuilder ()) Source # 
Instance details

Defined in Std.Data.TextBuilder

Monoid (TextBuilder ()) Source # 
Instance details

Defined in Std.Data.TextBuilder

Basic UTF8 builders

stringUTF8 :: String -> TextBuilder () Source #

Turn String into TextBuilder with UTF8 encoding

Illegal codepoints will be written as replacementChars. This function will be rewritten into a memcpy if possible, (running a fast UTF-8 validation at runtime first).

charUTF8 :: Char -> TextBuilder () Source #

Turn Char into TextBuilder with UTF8 encoding

Illegal codepoints will be written as replacementChars.

string7 :: String -> TextBuilder () Source #

Turn String into TextBuilder with ASCII7 encoding

Codepoints beyond '\x7F' will be chopped.

char7 :: Char -> TextBuilder () Source #

Turn Char into TextBuilder with ASCII7 encoding

Codepoints beyond '\x7F' will be chopped.

text :: Text -> TextBuilder () Source #

Write UTF8 encoded Text using Builder.

Note, if you're trying to write string literals builders, please open OverloadedStrings and use Builders IsString instance, it will be rewritten into a memcpy.

Numeric builders

Integral type formatting

data IFormat Source #

Integral formatting options.

Constructors

IFormat 

Fields

Instances
Eq IFormat Source # 
Instance details

Defined in Std.Data.Builder.Numeric

Methods

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

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

Ord IFormat Source # 
Instance details

Defined in Std.Data.Builder.Numeric

Show IFormat Source # 
Instance details

Defined in Std.Data.Builder.Numeric

defaultIFormat :: IFormat Source #

defaultIFormat = IFormat 0 NoPadding False Decimal

int :: (Integral a, Bounded a) => a -> TextBuilder () Source #

int = intWith defaultIFormat

intWith :: (Integral a, Bounded a) => IFormat -> a -> TextBuilder () Source #

Format a Bounded Integral type like Int or Word16 into decimal ascii digits.

integer :: Integer -> TextBuilder () Source #

Format a Integer into decimal ascii digits.

Fixded size hexidecimal formatting

hex :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #

Format a FiniteBits Integral type into hex nibbles.

heX :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #

The UPPERCASED version of hex.

IEEE float formating

data FFormat Source #

Control the rendering of floating point numbers.

Constructors

Exponent

Scientific notation (e.g. 2.3e123).

Fixed

Standard decimal notation.

Generic

Use decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

double :: Double -> TextBuilder () Source #

Decimal encoding of an IEEE Double.

Using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

doubleWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Double 
-> TextBuilder () 

Format double-precision float using drisu3 with dragon4 fallback.

float :: Float -> TextBuilder () Source #

Decimal encoding of an IEEE Float.

Using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

floatWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Float 
-> TextBuilder () 

Format single-precision float using drisu3 with dragon4 fallback.

scientific :: Scientific -> TextBuilder () Source #

A Builder which renders a scientific number to full precision, using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

scientificWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Scientific 
-> TextBuilder () 

Like scientific but provides rendering options.