encoding-0.3: A library for various character encodings

Data.Encoding

Synopsis

Documentation

class Encoding enc whereSource

Represents an encoding, supporting various methods of de- and encoding. Minimal complete definition: encode, decode

Methods

encode :: enc -> String -> ByteStringSource

Encode a String into a strict ByteString. Throws the HasNoRepresentation-Exception if it encounters an unrepresentable character.

encodeLazy :: enc -> String -> ByteStringSource

Encode a String into a lazy Data.ByteString.Lazy.ByteString.

encodable :: enc -> Char -> BoolSource

Whether or not the given Char is representable in this encoding. Default: True.

decode :: enc -> ByteString -> StringSource

Decode a strict ByteString into a String. If the string is not decodable, a DecodingException is thrown.

decodeLazy :: enc -> ByteString -> StringSource

decodable :: enc -> ByteString -> BoolSource

Whether or no a given ByteString is decodable. Default: True.

data EncodingException Source

This exception type is thrown whenever something went wrong during the encoding-process.

Constructors

HasNoRepresentation Char

Thrown if a specific character is not representable in an encoding.

data DecodingException Source

This exception type is thrown whenever something went wrong during the decoding-process.

Constructors

IllegalCharacter Word8

The sequence contained an illegal byte that couldn't be decoded.

UnexpectedEnd

more bytes were needed to allow a successfull decoding.

OutOfRange

the decoded value was out of the unicode range

recode :: (Encoding from, Encoding to) => from -> to -> ByteString -> ByteStringSource

This decodes a string from one encoding and encodes it into another.

recodeLazy :: (Encoding from, Encoding to) => from -> to -> ByteString -> ByteStringSource

data DynEncoding Source

An untyped encoding. Used in System.IO.Encoding.getSystemEncoding.

encodingFromString :: String -> DynEncodingSource

Takes the name of an encoding and creates a dynamic encoding from it.