-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Safe conversions between textual types -- -- Safe conversions between textual types @package text-conversions @version 0.2.0 -- | This module provides a set of typeclasses for safely converting -- between textual data. The built-in String type, as well as -- strict Text and lazy Text, are safely convertible -- between one another. The ByteString type is frequently treated -- in much the same manner, but this is unsafe for two reasons: -- -- -- -- This module addresses both problems by providing a DecodeText -- typeclass for decoding binary data in a way that can fail and by -- providing a UTF8 wrapper type for selecting the desired -- encoding. -- -- Most of the time, you will not need to create your own instances or -- use the underlying functions that make the conversion machinery tick. -- Instead, just use the convertText method to convert between two -- textual datatypes or the decodeConvertText method to perform a -- conversion that can fail. -- -- Examples: -- --
--   >>> convertText ("hello" :: String) :: Text
--   "hello"
--   
--   >>> decodeConvertText (UTF8 ("hello" :: ByteString)) :: Maybe Text
--   Just "hello"
--   
--   >>> decodeConvertText (UTF8 ("\xc3\x28" :: ByteString)) :: Maybe Text
--   Nothing
--   
module Data.Text.Conversions -- | A simple typeclass that handles converting arbitrary datatypes to -- Text when the operation can fail. If you have a type that -- satisfies that requirement, implement this typeclass, but if the -- operation cannot fail, use ToText instead. class Functor f => DecodeText f a decodeText :: DecodeText f a => a -> f Text -- | A simple typeclass that handles converting Text to arbitrary -- datatypes. If you have a type that can be produced from text, -- implement this typeclass, not ConvertText. However, -- you probably do not want to call fromText directly; call -- convertText, instead. class FromText a fromText :: FromText a => Text -> a -- | A simple typeclass that handles converting arbitrary datatypes to -- Text when the operation cannot fail. If you have a type that -- satisfies that requirement, implement this typeclass, but if the -- operation can fail, use DecodeText instead. class ToText a toText :: ToText a => a -> Text -- | Simple wrapper type that is used to select a desired encoding when -- encoding or decoding text from binary data, such as -- ByteStrings. newtype UTF8 a UTF8 :: a -> UTF8 a [unUTF8] :: UTF8 a -> a -- | A function that provides a way to safely convert between -- arbitrary textual datatypes where the conversion to text cannot fail. -- --
--   >>> convertText ("hello" :: String) :: Text
--   "hello"
--   
convertText :: (ToText a, FromText b) => a -> b -- | A function that provides a way to safely convert between -- arbitrary textual datatypes where the conversion to text can fail, -- such as decoding binary data to text. Since binary data can represent -- text in many different potential encodings, it is necessary to use a -- newtype that picks the particular encoding, like UTF8: -- --
--   >>> convertText (UTF8 ("hello" :: ByteString)) :: Maybe Text
--   Just "hello"
--   
decodeConvertText :: (DecodeText f a, FromText b) => a -> f b instance GHC.Base.Functor Data.Text.Conversions.UTF8 instance GHC.Show.Show a => GHC.Show.Show (Data.Text.Conversions.UTF8 a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Text.Conversions.UTF8 a) instance Data.Text.Conversions.ToText Data.Text.Internal.Text instance Data.Text.Conversions.FromText Data.Text.Internal.Text instance Data.Text.Conversions.ToText GHC.Base.String instance Data.Text.Conversions.FromText GHC.Base.String instance Data.Text.Conversions.ToText Data.Text.Internal.Lazy.Text instance Data.Text.Conversions.FromText Data.Text.Internal.Lazy.Text instance Data.Text.Conversions.DecodeText GHC.Base.Maybe (Data.Text.Conversions.UTF8 Data.ByteString.Internal.ByteString) instance Data.Text.Conversions.FromText (Data.Text.Conversions.UTF8 Data.ByteString.Internal.ByteString) instance Data.Text.Conversions.DecodeText GHC.Base.Maybe (Data.Text.Conversions.UTF8 Data.ByteString.Lazy.Internal.ByteString) instance Data.Text.Conversions.FromText (Data.Text.Conversions.UTF8 Data.ByteString.Lazy.Internal.ByteString)