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

Base on UTF8 compatible textual builders from Builder, we provide a newtype wrapper TextBuilder which can be directly used to build Text.

We also provide faster alternative to Show class, i.e. ToText, which also provides Generic based instances deriving.

Synopsis

ToText class

class ToText a where Source #

A class similar to Show, serving the purpose that quickly convert a data type to a Text value.

Minimal complete definition

Nothing

Methods

toTextBuilder :: Int -> a -> TextBuilder () Source #

toTextBuilder :: (Generic a, GToText (Rep a)) => Int -> a -> TextBuilder () Source #

Instances
ToText Bool Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Char Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Double Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Float Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Int Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Int8 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Int16 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Int32 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Int64 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Integer Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Natural Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Ordering Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Word Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Word8 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Word16 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Word32 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Word64 Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText () Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> () -> TextBuilder () Source #

ToText Version Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText Text Source #

To keep sync with Show instance's escaping rule, we reuse show here, so it won't be as fast as memcpy.

Instance details

Defined in Std.Data.TextBuilder

ToText Scientific Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Scientific -> TextBuilder () Source #

ToText Str Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText FlatIntSet Source # 
Instance details

Defined in Std.Data.Vector.FlatIntSet

ToText Value Source # 
Instance details

Defined in Std.Data.JSON.Value

ToText a => ToText [a] Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> [a] -> TextBuilder () Source #

ToText a => ToText (Maybe a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Maybe a -> TextBuilder () Source #

(ToText a, Integral a) => ToText (Ratio a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Ratio a -> TextBuilder () Source #

HasResolution a => ToText (Fixed a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Fixed a -> TextBuilder () Source #

ToText a => ToText (Min a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Min a -> TextBuilder () Source #

ToText a => ToText (Max a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Max a -> TextBuilder () Source #

ToText a => ToText (First a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> First a -> TextBuilder () Source #

ToText a => ToText (Last a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Last a -> TextBuilder () Source #

ToText a => ToText (WrappedMonoid a) Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText a => ToText (Identity a) Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText a => ToText (First a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> First a -> TextBuilder () Source #

ToText a => ToText (Last a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Last a -> TextBuilder () Source #

ToText a => ToText (Dual a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Dual a -> TextBuilder () Source #

ToText a => ToText (NonEmpty a) Source # 
Instance details

Defined in Std.Data.TextBuilder

(Prim a, ToText a) => ToText (PrimVector a) Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText a => ToText (Vector a) Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText (TextBuilder a) Source # 
Instance details

Defined in Std.Data.TextBuilder

ToText v => ToText (FlatSet v) Source # 
Instance details

Defined in Std.Data.Vector.FlatSet

ToText v => ToText (FlatIntMap v) Source # 
Instance details

Defined in Std.Data.Vector.FlatIntMap

(ToText a, ToText b) => ToText (Either a b) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Either a b -> TextBuilder () Source #

(ToText a, ToText b) => ToText (a, b) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b) -> TextBuilder () Source #

ToText (Proxy a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Proxy a -> TextBuilder () Source #

(ToText k, ToText v) => ToText (FlatMap k v) Source # 
Instance details

Defined in Std.Data.Vector.FlatMap

Methods

toTextBuilder :: Int -> FlatMap k v -> TextBuilder () Source #

(ToText a, ToText b, ToText c) => ToText (a, b, c) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b, c) -> TextBuilder () Source #

ToText a => ToText (Const a b) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Const a b -> TextBuilder () Source #

ToText b => ToText (Tagged a b) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Tagged a b -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d) => ToText (a, b, c, d) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b, c, d) -> TextBuilder () Source #

(ToText (f a), ToText (g a)) => ToText (Product f g a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Product f g a -> TextBuilder () Source #

(ToText (f a), ToText (g a), ToText a) => ToText (Sum f g a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Sum f g a -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e) => ToText (a, b, c, d, e) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b, c, d, e) -> TextBuilder () Source #

ToText (f (g a)) => ToText (Compose f g a) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> Compose f g a -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e, ToText f) => ToText (a, b, c, d, e, f) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b, c, d, e, f) -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e, ToText f, ToText g) => ToText (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

toTextBuilder :: Int -> (a, b, c, d, e, f, g) -> TextBuilder () Source #

toText :: ToText a => a -> Text Source #

Directly convert data to Text.

toBuilder :: ToText a => a -> Builder () Source #

Directly convert data to Builder.

toBytes :: ToText a => a -> Bytes Source #

Directly convert data to Bytes.

toString :: ToText a => a -> String Source #

Faster show replacement.

Str newtype

newtype Str Source #

Newtype wrapper for [Char] to provide textual instances.

To encourage using Text as the textual representation, we didn't provide special treatment to differentiate instances between [a] and [Char] in various places. This newtype is therefore to provide instances similar to T.Text, in case you really need to wrap a String.

Constructors

Str 

Fields

Instances
Eq Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

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

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

Data Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Str -> c Str #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Str #

toConstr :: Str -> Constr #

dataTypeOf :: Str -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Str) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Str) #

gmapT :: (forall b. Data b => b -> b) -> Str -> Str #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Str -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Str -> r #

gmapQ :: (forall d. Data d => d -> u) -> Str -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Str -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Str -> m Str #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Str -> m Str #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Str -> m Str #

Ord Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

compare :: Str -> Str -> Ordering #

(<) :: Str -> Str -> Bool #

(<=) :: Str -> Str -> Bool #

(>) :: Str -> Str -> Bool #

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

max :: Str -> Str -> Str #

min :: Str -> Str -> Str #

Read Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Show Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

showsPrec :: Int -> Str -> ShowS #

show :: Str -> String #

showList :: [Str] -> ShowS #

Generic Str Source # 
Instance details

Defined in Std.Data.TextBuilder

Associated Types

type Rep Str :: Type -> Type #

Methods

from :: Str -> Rep Str x #

to :: Rep Str x -> Str #

ToText Str Source # 
Instance details

Defined in Std.Data.TextBuilder

FromValue Str Source # 
Instance details

Defined in Std.Data.JSON.Base

EncodeJSON Str Source # 
Instance details

Defined in Std.Data.JSON.Base

Methods

encodeJSON :: Str -> Builder () Source #

ToValue Str Source # 
Instance details

Defined in Std.Data.JSON.Base

Methods

toValue :: Str -> Value Source #

type Rep Str Source # 
Instance details

Defined in Std.Data.TextBuilder

type Rep Str = D1 (MetaData "Str" "Std.Data.TextBuilder" "stdio-0.2.0.0-5YmH16k3vlO7FAtmF9PgfB" True) (C1 (MetaCons "Str" PrefixI True) (S1 (MetaSel (Just "chrs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Char])))

Textual Builder

data 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, there's a rewrite rule to turn encoding loop into a memcpy, which is much faster (the same rule also apply to stringUTF8). Different from Builder (), TextBuilder ()'s IsString instance will give you desired UTF8 guarantees:

  • NUL will be written directly as x00.
  • xD800 ~ xDFFF will be replaced by replacement char.
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 #

Show (TextBuilder a) Source # 
Instance details

Defined in Std.Data.TextBuilder

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

Arbitrary (TextBuilder ()) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

arbitrary :: Gen (TextBuilder ())

shrink :: TextBuilder () -> [TextBuilder ()]

CoArbitrary (TextBuilder ()) Source # 
Instance details

Defined in Std.Data.TextBuilder

Methods

coarbitrary :: TextBuilder () -> Gen b -> Gen b

ToText (TextBuilder a) Source # 
Instance details

Defined in Std.Data.TextBuilder

unsafeFromBuilder :: Builder a -> TextBuilder a Source #

Unsafely turn a Builder into TextBuilder, thus it's user's responsibility to ensure only UTF-8 complied bytes are written.

buildText :: TextBuilder a -> Text Source #

Build a Text using TextBuilder, which provide UTF-8 encoding guarantee.

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

Arbitrary IFormat Source # 
Instance details

Defined in Std.Data.Builder.Numeric

Methods

arbitrary :: Gen IFormat

shrink :: IFormat -> [IFormat]

defaultIFormat :: IFormat Source #

defaultIFormat = IFormat 0 NoPadding False

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.

Builder helpers

paren :: TextBuilder () -> TextBuilder () Source #

add (...) to original builder.

parenWhen :: Bool -> TextBuilder () -> TextBuilder () Source #

Add "(..)" around builders when condition is met, otherwise add nothing.

This is useful when defining ToText instances.

curly :: TextBuilder () -> TextBuilder () Source #

add {...} to original builder.

square :: TextBuilder () -> TextBuilder () Source #

add [...] to original builder.

angle :: TextBuilder () -> TextBuilder () Source #

add ... to original builder.

quotes :: TextBuilder () -> TextBuilder () Source #

add "..." to original builder.

squotes :: TextBuilder () -> TextBuilder () Source #

add ... to original builder.

colon :: TextBuilder () Source #

write an ASCII :

comma :: TextBuilder () Source #

write an ASCII ,

intercalateVec Source #

Arguments

:: Vec v a 
=> TextBuilder ()

the seperator

-> (a -> TextBuilder ())

value formatter

-> v a

value list

-> TextBuilder () 

Use separator to connect a vector of builders.

intercalateList Source #

Arguments

:: TextBuilder ()

the seperator

-> (a -> TextBuilder ())

value formatter

-> [a]

value vector

-> TextBuilder () 

Use separator to connect a list of builders.