0.3 Release (#115)

* Add total ConvertText alternative to Conv

* Explain ConvertText's meaning

* Rename convertText to toS for compatibility

* 0.3.0 Refactor (#111)

* Begin work on 0.3 refactor

* Remove old docs folder

* Fix dodgy exports

* 4.8 constraint for null and length

* Guards for Semigroup export for base<4.9

* Fix Data.Bits exports

* Guards for typeable exports

* Remove unused pragmas

* Update hlint.yaml

* Use liftM because of pre-AMP quirkk

* Data.Char exports

* Rework Exception exports

* Fix bounds

* Adding Monad.Fail shim

* Fix displayException export

* Explicit GHC.Prim import for ancient ghc

* Explicit raise# for base-4.7

* Flush legacy testing infrastructure

* Update git location

* Update README

* Add Partial module

* Add concurrency exports

* Explicit GHC.Float exports

* Bounds for threadWaitReadSTM, threadWaitWriteSTM, forkOSWithUnmask

* Fix for weird undocumented underflowError weirdness

* forkOSWithUnask for base>4.8

* Fix GHC.Real exports pre base-4.7

* Fix withMVarMasked for base-4.7

* Update nix derivation

* Update derivation

* Update derivation

* Explicit functor exports

* <$ export

* Overwrite binary

* Fix some missing exports

* Update Changelog

* Minor export fixes base<4.9

* Explicit exports

* Export handler

* Generate export lists for multiple versions (#114)

* Generate export lists for #112

* Make export lists format OccName uniformly

* Make compile on ancient GHC

* Use Foldable.concat

* Hacks to make ghc-7.6 API happy

* liftIO shim

* Fix sortOn warning

* Update ChangeLog

* Update base bounds

* Export conventions

* Update Haddocks

* Document GHC magic
This commit is contained in:
Stephen Diehl
2020-01-24 11:06:09 +00:00
committed by GitHub
parent 03f73d8cde
commit 2666f1e830
93 changed files with 8668 additions and 2839 deletions
+44
View File
@@ -0,0 +1,44 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
-- | Non-partial text conversion typeclass and functions.
-- For an alternative with partial conversions import 'Protolude.Conv'.
module Protolude.ConvertText (
ConvertText (toS)
, toUtf8
, toUtf8Lazy
) where
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import Data.Function (id, (.))
import Data.String (String)
import Data.Text.Encoding (encodeUtf8)
-- | Convert from one Unicode textual type to another. Not for serialization/deserialization,
-- so doesn't have instances for bytestrings.
class ConvertText a b where
toS :: a -> b
instance ConvertText String String where toS = id
instance ConvertText String T.Text where toS = T.pack
instance ConvertText String LT.Text where toS = LT.pack
instance ConvertText T.Text String where toS = T.unpack
instance ConvertText T.Text LT.Text where toS = LT.fromStrict
instance ConvertText T.Text T.Text where toS = id
instance ConvertText LT.Text String where toS = LT.unpack
instance ConvertText LT.Text T.Text where toS = LT.toStrict
instance ConvertText LT.Text LT.Text where toS = id
toUtf8 :: ConvertText a T.Text => a -> B.ByteString
toUtf8 =
encodeUtf8 . toS
toUtf8Lazy :: ConvertText a T.Text => a -> LB.ByteString
toUtf8Lazy =
LB.fromStrict . encodeUtf8 . toS