buffer-builder-0.2.1.0: Library for efficiently building up buffers, one piece at a time

Safe HaskellNone
LanguageHaskell2010

Data.BufferBuilder.Utf8

Contents

Description

A library for efficiently building up a buffer of UTF-8-encoded text. If only safe functions are used, the resulting ByteString is guaranteed to be valid UTF-8.

To run a sequence of Utf8Builder actions and retrieve the resulting buffer, use runUtf8Builder.

In special situations, for maximum performance, unsafe functions are also provided. The unsafe functions do not guarantee the buffer is correct UTF-8.

This module is built on top of Data.BufferBuilder.

Synopsis

The Utf8Builder Monad

runUtf8Builder :: Utf8Builder () -> ByteString Source

Run a sequence of Utf8Builder actions and extracting the resulting buffer as a ByteString.

Text encoding

appendText :: Text -> Utf8Builder () Source

Encodes the given Text in UTF-8, appending it to the buffer.

appendString :: String -> Utf8Builder () Source

Encodes the given String in UTF-8, appending it to the buffer.

appendChar :: Char -> Utf8Builder () Source

Encodes a single Char in UTF-8, appending it to the buffer.

ASCII-7

appendByte7 :: Word8 -> Utf8Builder () Source

Appends the bottom 7 bits of a byte to the buffer.

appendChar7 :: Char -> Utf8Builder () Source

Appends the bottom 7 bits of a Char to the buffer.

appendBS7 :: ByteString -> Utf8Builder () Source

Appends the given ByteString to the buffer, taking the bottom 7 bits of each byte.

appendLiteral7 :: Addr# -> Utf8Builder () Source

Appends the zero-terminated byte string at the given address to the buffer, taking the bottom 7 bits of each byte.

Printing numbers

Escaped JSON

Unsafe append operations

unsafeAppendByte :: Word8 -> Utf8Builder () Source

Directly append a byte into the UTF-8 code stream. Incorrect use of this function can result in invalid UTF-8.

unsafeAppendChar8 :: Char -> Utf8Builder () Source

Directly append the bottom 8 bits of the given character to the UTF-8 code stream. Incorrect use of this function can result in invalid UTF-8.

unsafeAppendLiteral :: Addr# -> Utf8Builder () Source

Directly append the zero-terminated byte sequence pointed to by the given address. Be careful that the referenced byte sequence contains valid UTF-8.

unsafeAppendLiteralN :: Int -> Addr# -> Utf8Builder () Source

Directly append the given byte sequence pointed to by the given address. Be careful that the referenced byte sequence contains valid UTF-8.

WARNING: passing an incorrect length value is likely to cause an access violation or worse.

unsafeAppendBS :: ByteString -> Utf8Builder () Source

Directly append the given ByteString to the output buffer. Be careful that the referenced ByteString contains valid UTF-8.