Text.Blaze.Builder.Core
Contents
Description
The builder monoid from BlazeHtml.
Usage is fairly straightforward. Builders can be constructed from many
values, including String and Text values.
strings :: [String] strings = replicate 10000 "Hello there!"
Concatenation should happen through the Monoid interface.
concatenation :: Builder concatenation = mconcat $ map fromString strings
There is only one way to efficiently obtain the result: to convert the
Builder to a lazy ByteString using toLazyByteString.
result :: L.ByteString result = toLazyByteString concatenation
- data Builder
- data Write = Write !Int (Ptr Word8 -> IO ())
- writeByte :: Word8 -> Write
- writeByteString :: ByteString -> Write
- writeSingleton :: (a -> Write) -> a -> Builder
- writeList :: (a -> Write) -> [a] -> Builder
- singleton :: Word8 -> Builder
- fromByteString :: ByteString -> Builder
- toLazyByteString :: Builder -> ByteString
Main builder type
Main builder type. It simply contains a function to extract the actual data.
Custom writes to the builder
Write abstraction so we can avoid some gory and bloody details. A write abstration holds the exact size of the write in bytes, and a function to carry out the write operation.
Arguments
| :: ByteString |
|
| -> Write | Resulting write |
Write a strict ByteString.
Construct a builder writing a list of data from a write abstraction.
Creating builders
Construct a Builder from a single byte.
Arguments
| :: ByteString | Strict |
| -> Builder | Resulting |
O(n). A Builder taking a ByteString, copying it.
Extracting the result from a builder
Arguments
| :: Builder |
|
| -> ByteString | Resulting UTF-8 encoded |
O(n). Extract the lazy ByteString from the builder.