typed-encoding-0.5.2.1: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Conv.Text

Description

Text encoding combinators specific to Text @since 0.2.2.0

Synopsis

Documentation

>>> :set -XDataKinds -XTypeFamilies -XTypeApplications

pack :: (UnSnoc xs ~ (,) ys y, Superset "r-UNICODE.D76" y, encs ~ RemoveRs ys, AllEncodeInto "r-UNICODE.D76" encs) => Enc xs c String -> Enc xs c Text Source #

This assumes that each of the encodings in xs work work equivalently in String and Text. See discussion in Examples.TypedEncoding.Conversions and "Data.TypedEncoding.Conv.ByteString.Char8.pack"

pack1 :: Superset "r-UNICODE.D76" y => Enc '[y] c String -> Enc '[y] c Text Source #

simplified version of pack that works on single r- encodings @since 0.5.2.0

unpack :: (UnSnoc xs ~ (,) ys y, Superset "r-UNICODE.D76" y, encs ~ RemoveRs ys, AllEncodeInto "r-UNICODE.D76" encs) => Enc xs c Text -> Enc xs c String Source #

This assumes that each of the encodings in xs work work equivalently in String and Text. This is similar to the assumptions made in pack.

unpack1 :: Superset "r-UNICODE.D76" y => Enc '[y] c Text -> Enc '[y] c String Source #

simplified version of unpack that works on single r- encodings @since 0.5.2.0

utf8Promote :: Enc xs c Text -> Enc (Snoc xs "r-UTF8") c Text Source #

Text is automatically "r-UTF8" encoded

Adding "r-UTF8" annotation simply adds type level interpretion requirement that Text is treated as UTF8. The internals of Text (currently UTF-16) are not relevant and utf8Promote is implemented as id. This is not the same as encoding Word8 layouts into Char-s. This, in typed-encoding terminology, would be "enc-UTF8", not @"r-UTF8".

>>> displ $ utf8Promote $ toEncoding () ("text" :: T.Text)
"Enc '[r-UTF8] () (Text text)"

utf8Demote :: UnSnoc xs ~ (,) ys "r-UTF8" => Enc xs c Text -> Enc ys c Text Source #

For Text "r-UTF8" is redundant

>>> displ . utf8Demote $ (unsafeSetPayload () "Hello" :: Enc '["r-UTF8"] () T.Text)
"Enc '[] () (Text Hello)"

d76Promote :: Enc xs c Text -> Enc (Snoc xs "r-UNICODE.D76") c Text Source #

d76Demote :: UnSnoc xs ~ (,) ys "r-UNICODE.D76" => Enc xs c Text -> Enc ys c Text Source #