typed-encoding-0.5.2.1: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Instances.Restriction.ASCII

Contents

Description

Strings can be encoded as 'Enc "r-ASCII"@ only if they contain only ASCII characters (first 128 characters of the Unicode character set).

This is sometimes referred to as ASCII-7 and future versions of type-encoding may change "r-ASCII" symbol annotation to reflect this.

B8.all ((< 128) . ord) . getPayload @ '["r-ASCII"] @() @B.ByteString
>>> :set -XOverloadedStrings -XMultiParamTypeClasses -XDataKinds
>>> _runEncodings encodings . toEncoding () $ "Hello World" :: Either EncodeEx (Enc '["r-ASCII"] () T.Text)
Right (UnsafeMkEnc Proxy () "Hello World")
>>> _runEncodings encodings . toEncoding () $ "\194\160" :: Either EncodeEx (Enc '["r-ASCII"] () T.Text)
Left (EncodeEx "r-ASCII" (NonAsciiChar '\194'))

Since: 0.1.0.0

Synopsis

Documentation

>>> :set -XDataKinds -XTypeApplications
>>> import qualified Data.Text as T
>>> import qualified Data.ByteString as B
>>> import qualified Data.ByteString.Char8 as B8
>>> import Test.QuickCheck
>>> import Test.QuickCheck.Instances.ByteString()
>>> import Data.TypedEncoding
>>> :{
instance Arbitrary (Enc '["r-ASCII"] () B.ByteString) where 
     arbitrary =  fmap (unsafeSetPayload ()) 
                  . flip suchThat (B8.all isAscii) 
                       $ arbitrary 
:}

Encoding

encASCIIChar :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source #

encASCII :: Char8Find str => Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source #

Decoding

Orphan instances

(Char8Find str, RecreateErr f, Applicative f) => Validate f "r-ASCII" "r-ASCII" () str Source # 
Instance details

Methods

validation :: Validation f "r-ASCII" "r-ASCII" () str Source #

Applicative f => Decode f "r-ASCII" "r-ASCII" c str Source # 
Instance details

Methods

decoding :: Decoding f "r-ASCII" "r-ASCII" c str Source #

Char8Find str => Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source # 
Instance details

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source #

Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source # 
Instance details

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source #