conduit-extra-1.1.9.2: Batteries included conduit: adapters for common libraries.

Copyright | 2011 Michael Snoyman, 2010-2011 John Millikin
License | MIT
Safe Haskell | None
Language | Haskell98

Data.Conduit.Text

Contents

- Text codecs

Description

Handle streams of text.

Parts of this code were taken from enumerator and adapted for conduits.

For many purposes, it's recommended to use the conduit-combinators library, which provides a more complete set of functions.

Synopsis

- data Codec
- encode :: MonadThrow m => Codec -> Conduit Text m ByteString
- decode :: MonadThrow m => Codec -> Conduit ByteString m Text
- utf8 :: Codec
- utf16_le :: Codec
- utf16_be :: Codec
- utf32_le :: Codec
- utf32_be :: Codec
- ascii :: Codec
- iso8859_1 :: Codec
- lines :: Monad m => Conduit Text m Text
- linesBounded :: MonadThrow m => Int -> Conduit Text m Text
- data TextException
  - = DecodeException Codec Word8
  - | EncodeException Codec Char
  - | LengthExceeded Int
  - | TextException SomeException
  - | NewDecodeException !Text !Int !ByteString
- takeWhile :: Monad m => (Char -> Bool) -> Conduit Text m Text
- dropWhile :: Monad m => (Char -> Bool) -> Consumer Text m ()
- take :: Monad m => Int -> Conduit Text m Text
- drop :: Monad m => Int -> Consumer Text m ()
- foldLines :: Monad m => (a -> ConduitM Text o m a) -> a -> ConduitM Text o m a
- withLine :: Monad m => Sink Text m a -> Consumer Text m (Maybe a)
- decodeUtf8 :: MonadThrow m => Conduit ByteString m Text
- decodeUtf8Lenient :: Monad m => Conduit ByteString m Text
- encodeUtf8 :: Monad m => Conduit Text m ByteString
- detectUtf :: MonadThrow m => Conduit ByteString m Text

# Text codecs

data Codec Source

A specific character encoding.

Since 0.3.0

Instances

Show Codec Source |

encode :: MonadThrow m => Codec -> Conduit Text m ByteString Source

Convert text into bytes, using the provided codec. If the codec is not capable of representing an input character, an exception will be thrown.

Since 0.3.0

decode :: MonadThrow m => Codec -> Conduit ByteString m Text Source

Convert bytes into text, using the provided codec. If the codec is not capable of decoding an input byte sequence, an exception will be thrown.

Since 0.3.0

utf8 :: Codec Source

Since 0.3.0

utf16_le :: Codec Source

Since 0.3.0

utf16_be :: Codec Source

Since 0.3.0

utf32_le :: Codec Source

Since 0.3.0

utf32_be :: Codec Source

Since 0.3.0

ascii :: Codec Source

Since 0.3.0

iso8859_1 :: Codec Source

Since 0.3.0

lines :: Monad m => Conduit Text m Text Source

Emit each line separately

Since 0.4.1

linesBounded :: MonadThrow m => Int -> Conduit Text m Text Source

Variant of the lines function with an integer parameter. The text length of any emitted line never exceeds the value of the parameter. Whenever this is about to happen a LengthExceeded exception is thrown. This function should be used instead of the lines function whenever we are dealing with user input (e.g. a file upload) because we can't be sure that user input won't have extraordinarily large lines which would require large amounts of memory if consumed.

data TextException Source

Since 0.3.0

Constructors

DecodeException Codec Word8 |
EncodeException Codec Char |
LengthExceeded Int |
TextException SomeException |
NewDecodeException !Text !Int !ByteString |

Instances

Show TextException Source |
Exception TextException Source |

takeWhile :: Monad m => (Char -> Bool) -> Conduit Text m Text Source

Since 1.0.8

dropWhile :: Monad m => (Char -> Bool) -> Consumer Text m () Source

Since 1.0.8

take :: Monad m => Int -> Conduit Text m Text Source

Since 1.0.8

drop :: Monad m => Int -> Consumer Text m () Source

Since 1.0.8

foldLines :: Monad m => (a -> ConduitM Text o m a) -> a -> ConduitM Text o m a Source

Since 1.0.8

withLine :: Monad m => Sink Text m a -> Consumer Text m (Maybe a) Source

Since 1.0.8

decodeUtf8 :: MonadThrow m => Conduit ByteString m Text Source

Decode a stream of UTF8-encoded bytes into a stream of text, throwing an exception on invalid input.

Since 1.0.15

decodeUtf8Lenient :: Monad m => Conduit ByteString m Text Source

Decode a stream of UTF8 data, and replace invalid bytes with the Unicode replacement character.

Since 1.1.1

encodeUtf8 :: Monad m => Conduit Text m ByteString Source

Encode a stream of text into a stream of bytes.

Since 1.0.15

detectUtf :: MonadThrow m => Conduit ByteString m Text Source

Automatically determine which UTF variant is being used. This function checks for BOMs, removing them as necessary. It defaults to assuming UTF-8.

Since 1.1.9