char-decode-0.0.1: Convert legacy byte encodings to and from Unicode

Copyright(c) Automattic Inc. 2018
LicenseBSD3
MaintainerNathan Bloomfield, nathan.bloomfield@a8c.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Data.Char.Decode

Contents

Description

Simple utilities for converting between legacy byte encodings and Unicode.

Synopsis

Class

class ByteEncoding enc where Source #

Represents encodings of bytes as characters. It's not expected that you will need to implement this class directly.

Methods

decodeByte :: enc -> Word8 -> Char Source #

Mapping from bytes to chars.

encodeByte :: enc -> Char -> Either Char Word8 Source #

Mapping from chars to bytes. If the character c has no analog in the encoding, returns Left c.

Decoding

decodeToText :: ByteEncoding enc => enc -> ByteString -> Text Source #

Convert a legacy encoded ByteString to a UTF-8 encoded Text.

decodeToString :: ByteEncoding enc => enc -> ByteString -> String Source #

Convert a legacy encoded ByteString to a UTF-8 encoded String.

Encoding

encodeWithDefault :: ByteEncoding enc => enc -> Word8 -> Char -> Word8 Source #

If the character has no analog in the encoding, returns the default byte.

encodeFromText :: ByteEncoding enc => enc -> Text -> Either Char ByteString Source #

If any input characters are out of range, returns Left c where c is the first such character.

encodeFromTextWithDefault :: ByteEncoding enc => enc -> Word8 -> Text -> ByteString Source #

If any input characters are out of range, replace them with the given default.

encodeFromString :: ByteEncoding enc => enc -> String -> Either Char ByteString Source #

If any input characters are out of range, returns Left c where c is the first such character.

encodeFromStringWithDefault :: ByteEncoding enc => enc -> Word8 -> String -> ByteString Source #

If any input characters are out of range, replace them with the given default.

Character Mappings

Utilities

byte0 :: Char -> Word8 Source #

Extract the least significant byte (byte 0) of a UTF-8 code point.

byte1 :: Char -> Word8 Source #

Extract the next-to-least significant byte (byte 1) of a UTF-8 code point.

byte2 :: Char -> Word8 Source #

Extract byte 2 of a UTF-8 code point.

byte3 :: Char -> Word8 Source #

Extract byte 3 of a UTF-8 code point.