binrep-1.0.0: Encode precise binary representations directly in types
Safe HaskellNone
LanguageGHC2021

Binrep.Type.Text.Internal

Synopsis

Documentation

type AsText (enc :: k) = Refined enc Text Source #

A string of a given encoding, stored in the Text type.

Essentially Text carrying a proof that it can be successfully encoded into the given encoding. For example, AsText ASCII means the Text stored is pure ASCII.

class Encode (enc :: k) where Source #

Bytestring encoders for text validated for a given encoding.

Methods

encode' :: Text -> Bytes Source #

Encode text to bytes. Internal function, use encode.

Instances

Instances details
Encode Ascii Source #

We reuse UTF-8 encoding for ASCII, since it is a subset of UTF-8.

Instance details

Defined in Binrep.Type.Text.Encoding.Ascii

Methods

encode' :: Text -> Bytes Source #

Encode ShiftJis Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.ShiftJis

Methods

encode' :: Text -> Bytes Source #

Encode Utf8 Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf8

Methods

encode' :: Text -> Bytes Source #

Encode (Utf16 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Methods

encode' :: Text -> Bytes Source #

Encode (Utf16 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Methods

encode' :: Text -> Bytes Source #

Encode (Utf32 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Methods

encode' :: Text -> Bytes Source #

Encode (Utf32 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Methods

encode' :: Text -> Bytes Source #

class Decode (enc :: k) where Source #

Methods

decode :: Bytes -> Either String (AsText enc) Source #

Decode a ByteString to Text with an explicit encoding.

This is intended to be used with visible type applications.

Instances

Instances details
Decode Ascii Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Ascii

Decode ShiftJis Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.ShiftJis

Decode Utf8 Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf8

Decode (Utf16 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Decode (Utf16 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Decode (Utf32 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Decode (Utf32 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

decodeText :: forall {k} (enc :: k) e. (e -> String) -> (Bytes -> Either e Text) -> Bytes -> Either String (AsText enc) Source #

Helper for decoding a Bytes to a Text tagged with its encoding.

wrapUnsafeDecoder :: (Bytes -> Text) -> Bytes -> Either UnicodeException Text Source #

Run an unsafe decoder safely.

Copied from Data.Text.Encoding.decodeUtf8', so should be bulletproof?