Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- data Utf8Builder a
- runUtf8Builder :: Utf8Builder () -> ByteString
- appendText :: Text -> Utf8Builder ()
- appendString :: String -> Utf8Builder ()
- appendChar :: Char -> Utf8Builder ()
- appendByte7 :: Word8 -> Utf8Builder ()
- appendChar7 :: Char -> Utf8Builder ()
- appendBS7 :: ByteString -> Utf8Builder ()
- appendLiteral7 :: Addr# -> Utf8Builder ()
- appendDecimalSignedInt :: Int -> Utf8Builder ()
- appendDecimalDouble :: Double -> Utf8Builder ()
- appendEscapedJson :: ByteString -> Utf8Builder ()
- appendEscapedJsonLiteral :: Addr# -> Utf8Builder ()
- appendEscapedJsonText :: Text -> Utf8Builder ()
- unsafeAppendByte :: Word8 -> Utf8Builder ()
- unsafeAppendChar8 :: Char -> Utf8Builder ()
- unsafeAppendLiteral :: Addr# -> Utf8Builder ()
- unsafeAppendLiteralN :: Int -> Addr# -> Utf8Builder ()
- unsafeAppendBS :: ByteString -> Utf8Builder ()
The Utf8Builder Monad
data Utf8Builder a Source #
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
appendDecimalSignedInt :: Int -> Utf8Builder () Source #
appendDecimalDouble :: Double -> Utf8Builder () Source #
Escaped JSON
appendEscapedJson :: ByteString -> Utf8Builder () Source #
appendEscapedJsonLiteral :: Addr# -> Utf8Builder () Source #
appendEscapedJsonText :: Text -> Utf8Builder () Source #
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.