libro-backend-0.1.0.0: Restful data backend of the LiBro app
Safe HaskellSafe-Inferred
LanguageHaskell2010

LiBro.Data.SafeText

Description

Thin wrapper around Text, but without unsafe characters.

Synopsis

Definition of unsafe

unsafeChars :: [Char] Source #

A list of all characters considered unsafe in our setting: '\NUL' and '\r'.

A thin Text wrapper with smart data constructor

SafeText is only a thin newtype wrapper around Text. To ensure that its characters are safe, the standard data constructor is hidden from exports.

How to create SafeText values?

Can SafeText be used exactly like Text?

No. There are very useful instances: Arbitrary for property tests with Test.QuickCheck, ToJSON and FromJSON for JSON stuff with Data.Aeson and ToField and FromField for CSV stuff with Data.Csv (Cassava).

Also, there's safeModify that allows Text modifying functions to be applied inside a SafeText. But it seems to be a bit overkill to export everything Data.Text has to offer.

data SafeText Source #

A simple newtype wrapper around Text, but ensures the absence of unsafe characters.

Instances

Instances details
Arbitrary SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

FromJSON SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

ToJSON SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

IsString SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

Read SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

Show SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

FromField SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

ToField SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

Methods

toField :: SafeText -> Field #

Eq SafeText Source # 
Instance details

Defined in LiBro.Data.SafeText

getText :: SafeText -> Text Source #

Extracts the Text value from SafeText.

Safety checks

isSafeChar :: Char -> Bool Source #

Checks if a Char is considered safe.

isSafeText :: Text -> Bool Source #

Checks if a Text is considered safe.

isSafeString :: String -> Bool Source #

Checks if a String is considered safe.

Explicit value creation

safePackText :: Text -> Maybe SafeText Source #

Creates a SafeText value or Nothing if the given Text was unsafe.

safePack :: String -> Maybe SafeText Source #

Creates a SafeText value or Nothing if the given String was unsafe.

safeModify :: (Text -> Text) -> SafeText -> Maybe SafeText Source #

Safe application of a function that modifies Text values.

Other useful stuff

safeTextParser :: ReadS SafeText Source #

A simple ReadS parser for SafeText, useful for Read instances.