Copyright | (c) Automattic Inc. 2018 |
---|---|
License | BSD3 |
Maintainer | Nathan Bloomfield, nathan.bloomfield@a8c.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Simple utilities for converting between legacy byte encodings and Unicode.
Synopsis
- class ByteEncoding enc where
- decodeByte :: enc -> Word8 -> Char
- encodeByte :: enc -> Char -> Either Char Word8
- decodeToText :: ByteEncoding enc => enc -> ByteString -> Text
- decodeToString :: ByteEncoding enc => enc -> ByteString -> String
- encodeWithDefault :: ByteEncoding enc => enc -> Word8 -> Char -> Word8
- encodeFromText :: ByteEncoding enc => enc -> Text -> Either Char ByteString
- encodeFromTextWithDefault :: ByteEncoding enc => enc -> Word8 -> Text -> ByteString
- encodeFromString :: ByteEncoding enc => enc -> String -> Either Char ByteString
- encodeFromStringWithDefault :: ByteEncoding enc => enc -> Word8 -> String -> ByteString
- data CodePage437 = CodePage437
- data CodePage437Graphic = CodePage437Graphic
- byte0 :: Char -> Word8
- byte1 :: Char -> Word8
- byte2 :: Char -> Word8
- byte3 :: Char -> Word8
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.
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
.
Instances
ByteEncoding CodePage437 Source # | |
Defined in Data.Char.Decode.CodePage437 decodeByte :: CodePage437 -> Word8 -> Char Source # encodeByte :: CodePage437 -> Char -> Either Char Word8 Source # | |
ByteEncoding CodePage437Graphic Source # | |
Defined in Data.Char.Decode.CodePage437.Graphic decodeByte :: CodePage437Graphic -> Word8 -> Char Source # encodeByte :: CodePage437Graphic -> Char -> Either Char Word8 Source # |
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
data CodePage437 Source #
Instances
Eq CodePage437 Source # | |
Defined in Data.Char.Decode.CodePage437 (==) :: CodePage437 -> CodePage437 -> Bool # (/=) :: CodePage437 -> CodePage437 -> Bool # | |
Show CodePage437 Source # | |
Defined in Data.Char.Decode.CodePage437 showsPrec :: Int -> CodePage437 -> ShowS # show :: CodePage437 -> String # showList :: [CodePage437] -> ShowS # | |
ByteEncoding CodePage437 Source # | |
Defined in Data.Char.Decode.CodePage437 decodeByte :: CodePage437 -> Word8 -> Char Source # encodeByte :: CodePage437 -> Char -> Either Char Word8 Source # |
data CodePage437Graphic Source #
Instances
Eq CodePage437Graphic Source # | |
Defined in Data.Char.Decode.CodePage437.Graphic (==) :: CodePage437Graphic -> CodePage437Graphic -> Bool # (/=) :: CodePage437Graphic -> CodePage437Graphic -> Bool # | |
Show CodePage437Graphic Source # | |
Defined in Data.Char.Decode.CodePage437.Graphic showsPrec :: Int -> CodePage437Graphic -> ShowS # show :: CodePage437Graphic -> String # showList :: [CodePage437Graphic] -> ShowS # | |
ByteEncoding CodePage437Graphic Source # | |
Defined in Data.Char.Decode.CodePage437.Graphic decodeByte :: CodePage437Graphic -> Word8 -> Char Source # encodeByte :: CodePage437Graphic -> Char -> Either Char Word8 Source # |