{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE EmptyDataDeriving #-}
{-# LANGUAGE DerivingStrategies #-}
-- | promoted character functions

module Predicate.Data.Char (
 -- ** constructor

    C

 -- ** character predicates

  , IsLower
  , IsUpper
  , IsDigit
  , IsSpace
  , IsPunctuation
  , IsControl
  , IsHexDigit
  , IsOctDigit
  , IsSeparator
  , IsLatin1

 -- ** string predicates

  , IsLowerAll
  , IsUpperAll
  , IsDigitAll
  , IsSpaceAll
  , IsPunctuationAll
  , IsControlAll
  , IsHexDigitAll
  , IsOctDigitAll
  , IsSeparatorAll
  , IsLatin1All
 -- ** change case

  , ToTitle
  , ToUpper
  , ToLower
 ) where
import Predicate.Core
import Predicate.Misc
import Predicate.Util
import Control.Lens
import qualified Data.Text.Lens as DTL
import GHC.TypeLits (Symbol, KnownSymbol)
import qualified GHC.TypeLits as GL
import Data.Proxy (Proxy(Proxy))
import Data.Char
import qualified Data.Type.Equality as DE

-- $setup

-- >>> :set -XDataKinds

-- >>> :set -XTypeApplications

-- >>> :set -XTypeOperators

-- >>> :set -XOverloadedStrings

-- >>> import qualified Data.Text as T

-- >>> import Predicate.Prelude


-- | extracts the first character from a non empty 'GHC.TypeLits.Symbol'

--

-- >>> pz @(C "aBc") ()

-- Val 'a'

--

data C (s :: Symbol) deriving Int -> C s -> ShowS
[C s] -> ShowS
C s -> String
(Int -> C s -> ShowS)
-> (C s -> String) -> ([C s] -> ShowS) -> Show (C s)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (s :: Symbol). Int -> C s -> ShowS
forall (s :: Symbol). [C s] -> ShowS
forall (s :: Symbol). C s -> String
showList :: [C s] -> ShowS
$cshowList :: forall (s :: Symbol). [C s] -> ShowS
show :: C s -> String
$cshow :: forall (s :: Symbol). C s -> String
showsPrec :: Int -> C s -> ShowS
$cshowsPrec :: forall (s :: Symbol). Int -> C s -> ShowS
Show
instance ( KnownSymbol s
         , FailUnlessT (GL.CmpSymbol s "" DE.== 'GT)
              ('GL.Text "C symbol cannot be empty")
         ) => P (C s) a where
  type PP (C s) a = Char
  eval :: proxy (C s) -> POpts -> a -> m (TT (PP (C s) a))
eval proxy (C s)
_ POpts
opts a
_ =
     case KnownSymbol s => String
forall (s :: Symbol). KnownSymbol s => String
symb @s of
       [] -> String -> m (TT Char)
forall x. HasCallStack => String -> x
errorInProgram String
"C: found empty Symbol/string"
       Char
c:String
_ -> TT Char -> m (TT Char)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT Char -> m (TT Char)) -> TT Char -> m (TT Char)
forall a b. (a -> b) -> a -> b
$ POpts -> Val Char -> String -> [Tree PE] -> TT Char
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Char -> Val Char
forall a. a -> Val a
Val Char
c) (String
"C " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> Char -> String
forall a. Show a => POpts -> a -> String
showL POpts
opts Char
c) []


-- | a predicate for determining if a character belongs to the given character set

--

-- >>> pz @(Map '(IsControl, IsLatin1, IsHexDigit, IsOctDigit, IsDigit, IsPunctuation, IsSeparator, IsSpace)) "abc134"

-- Val [(False,True,True,False,False,False,False,False),(False,True,True,False,False,False,False,False),(False,True,True,False,False,False,False,False),(False,True,True,True,True,False,False,False),(False,True,True,True,True,False,False,False),(False,True,True,True,True,False,False,False)]

--

data IsCharSet (cs :: CharSet) deriving Int -> IsCharSet cs -> ShowS
[IsCharSet cs] -> ShowS
IsCharSet cs -> String
(Int -> IsCharSet cs -> ShowS)
-> (IsCharSet cs -> String)
-> ([IsCharSet cs] -> ShowS)
-> Show (IsCharSet cs)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (cs :: CharSet). Int -> IsCharSet cs -> ShowS
forall (cs :: CharSet). [IsCharSet cs] -> ShowS
forall (cs :: CharSet). IsCharSet cs -> String
showList :: [IsCharSet cs] -> ShowS
$cshowList :: forall (cs :: CharSet). [IsCharSet cs] -> ShowS
show :: IsCharSet cs -> String
$cshow :: forall (cs :: CharSet). IsCharSet cs -> String
showsPrec :: Int -> IsCharSet cs -> ShowS
$cshowsPrec :: forall (cs :: CharSet). Int -> IsCharSet cs -> ShowS
Show

instance ( x ~ Char
         , GetCharSet cs
         ) => P (IsCharSet cs) x where
  type PP (IsCharSet cs) x = Bool
  eval :: proxy (IsCharSet cs) -> POpts -> x -> m (TT (PP (IsCharSet cs) x))
eval proxy (IsCharSet cs)
_ POpts
opts x
c =
    let msg0 :: String
msg0 = String
"Is" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 (CharSet -> String
forall a. Show a => a -> String
show CharSet
cs)
        (CharSet
cs,Char -> Bool
f) = GetCharSet cs => (CharSet, Char -> Bool)
forall (cs :: CharSet). GetCharSet cs => (CharSet, Char -> Bool)
getCharSet @cs
        b :: Bool
b = Char -> Bool
f x
Char
c
    in TT Bool -> m (TT Bool)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT Bool -> m (TT Bool)) -> TT Bool -> m (TT Bool)
forall a b. (a -> b) -> a -> b
$ POpts -> Bool -> String -> [Tree PE] -> TT Bool
mkNodeB POpts
opts Bool
b (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " ([x
Char
c] :: String)) []

-- | predicate similar to 'Data.Char.isLower'

--

-- >>> pz @IsLower 'X'

-- Val False

--

-- >>> pz @IsLower '1'

-- Val False

--

-- >>> pz @IsLower 'a'

-- Val True

--

data IsLower deriving Int -> IsLower -> ShowS
[IsLower] -> ShowS
IsLower -> String
(Int -> IsLower -> ShowS)
-> (IsLower -> String) -> ([IsLower] -> ShowS) -> Show IsLower
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsLower] -> ShowS
$cshowList :: [IsLower] -> ShowS
show :: IsLower -> String
$cshow :: IsLower -> String
showsPrec :: Int -> IsLower -> ShowS
$cshowsPrec :: Int -> IsLower -> ShowS
Show
type IsLowerT = IsCharSet 'CLower

instance P IsLowerT x => P IsLower x where
  type PP IsLower x = PP IsLowerT x
  eval :: proxy IsLower -> POpts -> x -> m (TT (PP IsLower x))
eval proxy IsLower
_ = Proxy IsLowerT -> POpts -> x -> m (TT (PP IsLowerT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsLowerT
forall k (t :: k). Proxy t
Proxy @IsLowerT)

-- | predicate similar to 'Data.Char.isUpper'

--

data IsUpper deriving Int -> IsUpper -> ShowS
[IsUpper] -> ShowS
IsUpper -> String
(Int -> IsUpper -> ShowS)
-> (IsUpper -> String) -> ([IsUpper] -> ShowS) -> Show IsUpper
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsUpper] -> ShowS
$cshowList :: [IsUpper] -> ShowS
show :: IsUpper -> String
$cshow :: IsUpper -> String
showsPrec :: Int -> IsUpper -> ShowS
$cshowsPrec :: Int -> IsUpper -> ShowS
Show
type IsUpperT = IsCharSet 'CUpper

instance P IsUpperT x => P IsUpper x where
  type PP IsUpper x = PP IsUpperT x
  eval :: proxy IsUpper -> POpts -> x -> m (TT (PP IsUpper x))
eval proxy IsUpper
_ = Proxy IsUpperT -> POpts -> x -> m (TT (PP IsUpperT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsUpperT
forall k (t :: k). Proxy t
Proxy @IsUpperT)

-- | predicate similar to 'Data.Char.isDigit'

--

-- >>> pz @IsDigit 'g'

-- Val False

--

-- >>> pz @IsDigit '9'

-- Val True

--

data IsDigit deriving Int -> IsDigit -> ShowS
[IsDigit] -> ShowS
IsDigit -> String
(Int -> IsDigit -> ShowS)
-> (IsDigit -> String) -> ([IsDigit] -> ShowS) -> Show IsDigit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsDigit] -> ShowS
$cshowList :: [IsDigit] -> ShowS
show :: IsDigit -> String
$cshow :: IsDigit -> String
showsPrec :: Int -> IsDigit -> ShowS
$cshowsPrec :: Int -> IsDigit -> ShowS
Show
type IsDigitT = IsCharSet 'CNumber
instance P IsDigitT x => P IsDigit x where
  type PP IsDigit x = Bool
  eval :: proxy IsDigit -> POpts -> x -> m (TT (PP IsDigit x))
eval proxy IsDigit
_ = Proxy IsDigitT -> POpts -> x -> m (TT (PP IsDigitT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsDigitT
forall k (t :: k). Proxy t
Proxy @IsDigitT)

-- | predicate similar to 'Data.Char.isSpace'

--

-- >>> pz @IsSpace '\t'

-- Val True

--

-- >>> pz @IsSpace ' '

-- Val True

--

-- >>> pz @IsSpace 'x'

-- Val False

--

data IsSpace deriving Int -> IsSpace -> ShowS
[IsSpace] -> ShowS
IsSpace -> String
(Int -> IsSpace -> ShowS)
-> (IsSpace -> String) -> ([IsSpace] -> ShowS) -> Show IsSpace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsSpace] -> ShowS
$cshowList :: [IsSpace] -> ShowS
show :: IsSpace -> String
$cshow :: IsSpace -> String
showsPrec :: Int -> IsSpace -> ShowS
$cshowsPrec :: Int -> IsSpace -> ShowS
Show
type IsSpaceT = IsCharSet 'CSpace
instance P IsSpaceT x => P IsSpace x where
  type PP IsSpace x = Bool
  eval :: proxy IsSpace -> POpts -> x -> m (TT (PP IsSpace x))
eval proxy IsSpace
_ = Proxy IsSpaceT -> POpts -> x -> m (TT (PP IsSpaceT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsSpaceT
forall k (t :: k). Proxy t
Proxy @IsSpaceT)

-- | predicate similar to 'Data.Char.isPunctuation'

--

data IsPunctuation deriving Int -> IsPunctuation -> ShowS
[IsPunctuation] -> ShowS
IsPunctuation -> String
(Int -> IsPunctuation -> ShowS)
-> (IsPunctuation -> String)
-> ([IsPunctuation] -> ShowS)
-> Show IsPunctuation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsPunctuation] -> ShowS
$cshowList :: [IsPunctuation] -> ShowS
show :: IsPunctuation -> String
$cshow :: IsPunctuation -> String
showsPrec :: Int -> IsPunctuation -> ShowS
$cshowsPrec :: Int -> IsPunctuation -> ShowS
Show
type IsPunctuationT = IsCharSet 'CPunctuation
instance P IsPunctuationT x => P IsPunctuation x where
  type PP IsPunctuation x = Bool
  eval :: proxy IsPunctuation -> POpts -> x -> m (TT (PP IsPunctuation x))
eval proxy IsPunctuation
_ = Proxy IsPunctuationT -> POpts -> x -> m (TT (PP IsPunctuationT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsPunctuationT
forall k (t :: k). Proxy t
Proxy @IsPunctuationT)

-- | predicate similar to 'Data.Char.isControl'

--

data IsControl deriving Int -> IsControl -> ShowS
[IsControl] -> ShowS
IsControl -> String
(Int -> IsControl -> ShowS)
-> (IsControl -> String)
-> ([IsControl] -> ShowS)
-> Show IsControl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsControl] -> ShowS
$cshowList :: [IsControl] -> ShowS
show :: IsControl -> String
$cshow :: IsControl -> String
showsPrec :: Int -> IsControl -> ShowS
$cshowsPrec :: Int -> IsControl -> ShowS
Show
type IsControlT = IsCharSet 'CControl
instance P IsControlT x => P IsControl x where
  type PP IsControl x = Bool
  eval :: proxy IsControl -> POpts -> x -> m (TT (PP IsControl x))
eval proxy IsControl
_ = Proxy IsControlT -> POpts -> x -> m (TT (PP IsControlT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsControlT
forall k (t :: k). Proxy t
Proxy @IsControlT)

-- | predicate similar to 'Data.Char.isHexDigit'

--

-- >>> pz @IsHexDigit 'A'

-- Val True

--

-- >>> pz @IsHexDigit 'g'

-- Val False

--

data IsHexDigit deriving Int -> IsHexDigit -> ShowS
[IsHexDigit] -> ShowS
IsHexDigit -> String
(Int -> IsHexDigit -> ShowS)
-> (IsHexDigit -> String)
-> ([IsHexDigit] -> ShowS)
-> Show IsHexDigit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsHexDigit] -> ShowS
$cshowList :: [IsHexDigit] -> ShowS
show :: IsHexDigit -> String
$cshow :: IsHexDigit -> String
showsPrec :: Int -> IsHexDigit -> ShowS
$cshowsPrec :: Int -> IsHexDigit -> ShowS
Show
type IsHexDigitT = IsCharSet 'CHexDigit
instance P IsHexDigitT x => P IsHexDigit x where
  type PP IsHexDigit x = Bool
  eval :: proxy IsHexDigit -> POpts -> x -> m (TT (PP IsHexDigit x))
eval proxy IsHexDigit
_ = Proxy IsHexDigitT -> POpts -> x -> m (TT (PP IsHexDigitT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsHexDigitT
forall k (t :: k). Proxy t
Proxy @IsHexDigitT)

-- | predicate similar to 'Data.Char.isOctDigit'

--

data IsOctDigit deriving Int -> IsOctDigit -> ShowS
[IsOctDigit] -> ShowS
IsOctDigit -> String
(Int -> IsOctDigit -> ShowS)
-> (IsOctDigit -> String)
-> ([IsOctDigit] -> ShowS)
-> Show IsOctDigit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsOctDigit] -> ShowS
$cshowList :: [IsOctDigit] -> ShowS
show :: IsOctDigit -> String
$cshow :: IsOctDigit -> String
showsPrec :: Int -> IsOctDigit -> ShowS
$cshowsPrec :: Int -> IsOctDigit -> ShowS
Show
type IsOctDigitT = IsCharSet 'COctDigit
instance P IsOctDigitT x => P IsOctDigit x where
  type PP IsOctDigit x = Bool
  eval :: proxy IsOctDigit -> POpts -> x -> m (TT (PP IsOctDigit x))
eval proxy IsOctDigit
_ = Proxy IsOctDigitT -> POpts -> x -> m (TT (PP IsOctDigitT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsOctDigitT
forall k (t :: k). Proxy t
Proxy @IsOctDigitT)

-- | predicate similar to 'Data.Char.isSeparator'

--

data IsSeparator deriving Int -> IsSeparator -> ShowS
[IsSeparator] -> ShowS
IsSeparator -> String
(Int -> IsSeparator -> ShowS)
-> (IsSeparator -> String)
-> ([IsSeparator] -> ShowS)
-> Show IsSeparator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsSeparator] -> ShowS
$cshowList :: [IsSeparator] -> ShowS
show :: IsSeparator -> String
$cshow :: IsSeparator -> String
showsPrec :: Int -> IsSeparator -> ShowS
$cshowsPrec :: Int -> IsSeparator -> ShowS
Show
type IsSeparatorT = IsCharSet 'CSeparator
instance P IsSeparatorT x => P IsSeparator x where
  type PP IsSeparator x = Bool
  eval :: proxy IsSeparator -> POpts -> x -> m (TT (PP IsSeparator x))
eval proxy IsSeparator
_ = Proxy IsSeparatorT -> POpts -> x -> m (TT (PP IsSeparatorT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsSeparatorT
forall k (t :: k). Proxy t
Proxy @IsSeparatorT)

-- | predicate similar to 'Data.Char.isLatin1'

--

data IsLatin1 deriving Int -> IsLatin1 -> ShowS
[IsLatin1] -> ShowS
IsLatin1 -> String
(Int -> IsLatin1 -> ShowS)
-> (IsLatin1 -> String) -> ([IsLatin1] -> ShowS) -> Show IsLatin1
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsLatin1] -> ShowS
$cshowList :: [IsLatin1] -> ShowS
show :: IsLatin1 -> String
$cshow :: IsLatin1 -> String
showsPrec :: Int -> IsLatin1 -> ShowS
$cshowsPrec :: Int -> IsLatin1 -> ShowS
Show
type IsLatin1T = IsCharSet 'CLatin1
instance P IsLatin1T x => P IsLatin1 x where
  type PP IsLatin1 x = Bool
  eval :: proxy IsLatin1 -> POpts -> x -> m (TT (PP IsLatin1 x))
eval proxy IsLatin1
_ = Proxy IsLatin1T -> POpts -> x -> m (TT (PP IsLatin1T x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsLatin1T
forall k (t :: k). Proxy t
Proxy @IsLatin1T)


-- | a predicate for determining if a string 'Data.Text.IsText' belongs to the given character set

--

-- >>> pl @('Just Uncons >> IsUpper &* IsLowerAll) "AbcdE"

-- False ((>>) False | {True (&*) False | (IsLowerAll | "bcdE")})

-- Val False

--

-- >>> pl @('Just Uncons >> IsUpper &* IsLowerAll) "Abcde"

-- True ((>>) True | {True (&*) True})

-- Val True

--

-- >>> pl @('Just Uncons >> IsUpper &* IsLowerAll) "xbcde"

-- False ((>>) False | {False (&*) True | (IsUpper | "x")})

-- Val False

--

-- >>> pl @('Just Uncons >> IsUpper &* IsLowerAll) "X"

-- True ((>>) True | {True (&*) True})

-- Val True

--

-- >>> pz @('(IsControlAll, IsLatin1All , IsHexDigitAll , IsOctDigitAll , IsDigitAll , IsPunctuationAll , IsSeparatorAll , IsSpaceAll)) "abc134"

-- Val (False,True,True,False,False,False,False,False)

--

-- >>> pl @(SplitAts [1,2,10] Id >> Para '[IsLowerAll, IsDigitAll, IsUpperAll]) "abdefghi"

-- Present [True,False,False] ((>>) [True,False,False] | {Para(0) [True,False,False] | ["a","bd","efghi"]})

-- Val [True,False,False]

--

-- >>> pl @(SplitAts [1,2,10] Id >> BoolsQuick "" '[IsLowerAll, IsDigitAll, IsUpperAll]) "a98efghi"

-- Error Bool(2) [] (IsUpperAll | "efghi") (["a","98","efghi"])

-- Fail "Bool(2) [] (IsUpperAll | \"efghi\")"

--

-- >>> pl @(SplitAts [1,2,10] Id >> BoolsQuick "" '[IsLowerAll, IsDigitAll, IsUpperAll || IsLowerAll]) "a98efghi"

-- True ((>>) True | {Bools})

-- Val True

--

-- >>> pl @(SplitAts [1,2,10] Id >> BoolsQuick "" '[IsLowerAll, IsDigitAll, IsUpperAll || IsLowerAll]) "a98efgHi"

-- Error Bool(2) [] (False || False | (IsUpperAll | "efgHi") || (IsLowerAll | "efgHi")) (["a","98","efgHi"])

-- Fail "Bool(2) [] (False || False | (IsUpperAll | \"efgHi\") || (IsLowerAll | \"efgHi\"))"

--

data IsCharSetAll (cs :: CharSet) deriving Int -> IsCharSetAll cs -> ShowS
[IsCharSetAll cs] -> ShowS
IsCharSetAll cs -> String
(Int -> IsCharSetAll cs -> ShowS)
-> (IsCharSetAll cs -> String)
-> ([IsCharSetAll cs] -> ShowS)
-> Show (IsCharSetAll cs)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (cs :: CharSet). Int -> IsCharSetAll cs -> ShowS
forall (cs :: CharSet). [IsCharSetAll cs] -> ShowS
forall (cs :: CharSet). IsCharSetAll cs -> String
showList :: [IsCharSetAll cs] -> ShowS
$cshowList :: forall (cs :: CharSet). [IsCharSetAll cs] -> ShowS
show :: IsCharSetAll cs -> String
$cshow :: forall (cs :: CharSet). IsCharSetAll cs -> String
showsPrec :: Int -> IsCharSetAll cs -> ShowS
$cshowsPrec :: forall (cs :: CharSet). Int -> IsCharSetAll cs -> ShowS
Show

instance ( GetCharSet cs
         , Show a
         , DTL.IsText a
         ) => P (IsCharSetAll cs) a where
  type PP (IsCharSetAll cs) a = Bool
  eval :: proxy (IsCharSetAll cs)
-> POpts -> a -> m (TT (PP (IsCharSetAll cs) a))
eval proxy (IsCharSetAll cs)
_ POpts
opts a
as =
    let b :: Bool
b = Getting All a Char -> (Char -> Bool) -> a -> Bool
forall s a. Getting All s a -> (a -> Bool) -> s -> Bool
allOf Getting All a Char
forall t. IsText t => IndexedTraversal' Int t Char
DTL.text Char -> Bool
f a
as
        msg0 :: String
msg0 = String
"Is" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 (CharSet -> String
forall a. Show a => a -> String
show CharSet
cs) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"All"
        (CharSet
cs,Char -> Bool
f) = GetCharSet cs => (CharSet, Char -> Bool)
forall (cs :: CharSet). GetCharSet cs => (CharSet, Char -> Bool)
getCharSet @cs
    in TT Bool -> m (TT Bool)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT Bool -> m (TT Bool)) -> TT Bool -> m (TT Bool)
forall a b. (a -> b) -> a -> b
$ POpts -> Bool -> String -> [Tree PE] -> TT Bool
mkNodeB POpts
opts Bool
b (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> a -> String
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " a
as) []

data CharSet = CLower
             | CUpper
             | CNumber
             | CSpace
             | CPunctuation
             | CControl
             | CHexDigit
             | COctDigit
             | CSeparator
             | CLatin1
             deriving stock (CharSet
CharSet -> CharSet -> Bounded CharSet
forall a. a -> a -> Bounded a
maxBound :: CharSet
$cmaxBound :: CharSet
minBound :: CharSet
$cminBound :: CharSet
Bounded, Int -> CharSet
CharSet -> Int
CharSet -> [CharSet]
CharSet -> CharSet
CharSet -> CharSet -> [CharSet]
CharSet -> CharSet -> CharSet -> [CharSet]
(CharSet -> CharSet)
-> (CharSet -> CharSet)
-> (Int -> CharSet)
-> (CharSet -> Int)
-> (CharSet -> [CharSet])
-> (CharSet -> CharSet -> [CharSet])
-> (CharSet -> CharSet -> [CharSet])
-> (CharSet -> CharSet -> CharSet -> [CharSet])
-> Enum CharSet
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CharSet -> CharSet -> CharSet -> [CharSet]
$cenumFromThenTo :: CharSet -> CharSet -> CharSet -> [CharSet]
enumFromTo :: CharSet -> CharSet -> [CharSet]
$cenumFromTo :: CharSet -> CharSet -> [CharSet]
enumFromThen :: CharSet -> CharSet -> [CharSet]
$cenumFromThen :: CharSet -> CharSet -> [CharSet]
enumFrom :: CharSet -> [CharSet]
$cenumFrom :: CharSet -> [CharSet]
fromEnum :: CharSet -> Int
$cfromEnum :: CharSet -> Int
toEnum :: Int -> CharSet
$ctoEnum :: Int -> CharSet
pred :: CharSet -> CharSet
$cpred :: CharSet -> CharSet
succ :: CharSet -> CharSet
$csucc :: CharSet -> CharSet
Enum, Int -> CharSet -> ShowS
[CharSet] -> ShowS
CharSet -> String
(Int -> CharSet -> ShowS)
-> (CharSet -> String) -> ([CharSet] -> ShowS) -> Show CharSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CharSet] -> ShowS
$cshowList :: [CharSet] -> ShowS
show :: CharSet -> String
$cshow :: CharSet -> String
showsPrec :: Int -> CharSet -> ShowS
$cshowsPrec :: Int -> CharSet -> ShowS
Show, ReadPrec [CharSet]
ReadPrec CharSet
Int -> ReadS CharSet
ReadS [CharSet]
(Int -> ReadS CharSet)
-> ReadS [CharSet]
-> ReadPrec CharSet
-> ReadPrec [CharSet]
-> Read CharSet
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CharSet]
$creadListPrec :: ReadPrec [CharSet]
readPrec :: ReadPrec CharSet
$creadPrec :: ReadPrec CharSet
readList :: ReadS [CharSet]
$creadList :: ReadS [CharSet]
readsPrec :: Int -> ReadS CharSet
$creadsPrec :: Int -> ReadS CharSet
Read, Eq CharSet
Eq CharSet
-> (CharSet -> CharSet -> Ordering)
-> (CharSet -> CharSet -> Bool)
-> (CharSet -> CharSet -> Bool)
-> (CharSet -> CharSet -> Bool)
-> (CharSet -> CharSet -> Bool)
-> (CharSet -> CharSet -> CharSet)
-> (CharSet -> CharSet -> CharSet)
-> Ord CharSet
CharSet -> CharSet -> Bool
CharSet -> CharSet -> Ordering
CharSet -> CharSet -> CharSet
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CharSet -> CharSet -> CharSet
$cmin :: CharSet -> CharSet -> CharSet
max :: CharSet -> CharSet -> CharSet
$cmax :: CharSet -> CharSet -> CharSet
>= :: CharSet -> CharSet -> Bool
$c>= :: CharSet -> CharSet -> Bool
> :: CharSet -> CharSet -> Bool
$c> :: CharSet -> CharSet -> Bool
<= :: CharSet -> CharSet -> Bool
$c<= :: CharSet -> CharSet -> Bool
< :: CharSet -> CharSet -> Bool
$c< :: CharSet -> CharSet -> Bool
compare :: CharSet -> CharSet -> Ordering
$ccompare :: CharSet -> CharSet -> Ordering
$cp1Ord :: Eq CharSet
Ord, CharSet -> CharSet -> Bool
(CharSet -> CharSet -> Bool)
-> (CharSet -> CharSet -> Bool) -> Eq CharSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CharSet -> CharSet -> Bool
$c/= :: CharSet -> CharSet -> Bool
== :: CharSet -> CharSet -> Bool
$c== :: CharSet -> CharSet -> Bool
Eq)

class GetCharSet (cs :: CharSet) where
  getCharSet :: (CharSet, Char -> Bool)
instance GetCharSet 'CLower where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CLower, Char -> Bool
isLower)
instance GetCharSet 'CUpper where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CUpper, Char -> Bool
isUpper)
instance GetCharSet 'CNumber where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CNumber, Char -> Bool
isNumber)
instance GetCharSet 'CSpace where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CSpace, Char -> Bool
isSpace)
instance GetCharSet 'CPunctuation where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CPunctuation, Char -> Bool
isPunctuation)
instance GetCharSet 'CControl where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CControl, Char -> Bool
isControl)
instance GetCharSet 'CHexDigit where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CHexDigit, Char -> Bool
isHexDigit)
instance GetCharSet 'COctDigit where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
COctDigit, Char -> Bool
isOctDigit)
instance GetCharSet 'CSeparator where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CSeparator, Char -> Bool
isSeparator)
instance GetCharSet 'CLatin1 where
  getCharSet :: (CharSet, Char -> Bool)
getCharSet = (CharSet
CLatin1, Char -> Bool
isLatin1)

-- | predicate for determining if a string is all lowercase

--

-- >>> pz @IsLowerAll "abc"

-- Val True

--

-- >>> pz @IsLowerAll "abcX"

-- Val False

--

-- >>> pz @IsLowerAll (T.pack "abcX")

-- Val False

--

-- >>> pz @IsLowerAll "abcdef213"

-- Val False

--

-- >>> pz @IsLowerAll ""

-- Val True

--

data IsLowerAll deriving Int -> IsLowerAll -> ShowS
[IsLowerAll] -> ShowS
IsLowerAll -> String
(Int -> IsLowerAll -> ShowS)
-> (IsLowerAll -> String)
-> ([IsLowerAll] -> ShowS)
-> Show IsLowerAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsLowerAll] -> ShowS
$cshowList :: [IsLowerAll] -> ShowS
show :: IsLowerAll -> String
$cshow :: IsLowerAll -> String
showsPrec :: Int -> IsLowerAll -> ShowS
$cshowsPrec :: Int -> IsLowerAll -> ShowS
Show
type IsLowerAllT = IsCharSetAll 'CLower

instance P IsLowerAllT x => P IsLowerAll x where
  type PP IsLowerAll x = PP IsLowerAllT x
  eval :: proxy IsLowerAll -> POpts -> x -> m (TT (PP IsLowerAll x))
eval proxy IsLowerAll
_ = Proxy IsLowerAllT -> POpts -> x -> m (TT (PP IsLowerAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsLowerAllT
forall k (t :: k). Proxy t
Proxy @IsLowerAllT)

-- | predicate for determining if a string is all uppercase

data IsUpperAll deriving Int -> IsUpperAll -> ShowS
[IsUpperAll] -> ShowS
IsUpperAll -> String
(Int -> IsUpperAll -> ShowS)
-> (IsUpperAll -> String)
-> ([IsUpperAll] -> ShowS)
-> Show IsUpperAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsUpperAll] -> ShowS
$cshowList :: [IsUpperAll] -> ShowS
show :: IsUpperAll -> String
$cshow :: IsUpperAll -> String
showsPrec :: Int -> IsUpperAll -> ShowS
$cshowsPrec :: Int -> IsUpperAll -> ShowS
Show
type IsUpperAllT = IsCharSetAll 'CUpper

instance P IsUpperAllT x => P IsUpperAll x where
  type PP IsUpperAll x = PP IsUpperAllT x
  eval :: proxy IsUpperAll -> POpts -> x -> m (TT (PP IsUpperAll x))
eval proxy IsUpperAll
_ = Proxy IsUpperAllT -> POpts -> x -> m (TT (PP IsUpperAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsUpperAllT
forall k (t :: k). Proxy t
Proxy @IsUpperAllT)

-- | predicate for determining if the string is all digits

--

-- >>> pz @IsDigitAll "213G"

-- Val False

--

-- >>> pz @IsDigitAll "929"

-- Val True

--

data IsDigitAll deriving Int -> IsDigitAll -> ShowS
[IsDigitAll] -> ShowS
IsDigitAll -> String
(Int -> IsDigitAll -> ShowS)
-> (IsDigitAll -> String)
-> ([IsDigitAll] -> ShowS)
-> Show IsDigitAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsDigitAll] -> ShowS
$cshowList :: [IsDigitAll] -> ShowS
show :: IsDigitAll -> String
$cshow :: IsDigitAll -> String
showsPrec :: Int -> IsDigitAll -> ShowS
$cshowsPrec :: Int -> IsDigitAll -> ShowS
Show
type IsDigitAllT = IsCharSetAll 'CNumber
instance P IsDigitAllT x => P IsDigitAll x where
  type PP IsDigitAll x = Bool
  eval :: proxy IsDigitAll -> POpts -> x -> m (TT (PP IsDigitAll x))
eval proxy IsDigitAll
_ = Proxy IsDigitAllT -> POpts -> x -> m (TT (PP IsDigitAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsDigitAllT
forall k (t :: k). Proxy t
Proxy @IsDigitAllT)

-- | predicate for determining if the string is all spaces

--

-- >>> pz @IsSpaceAll "213G"

-- Val False

--

-- >>> pz @IsSpaceAll "    "

-- Val True

--

-- >>> pz @IsSpaceAll ""

-- Val True

--

data IsSpaceAll deriving Int -> IsSpaceAll -> ShowS
[IsSpaceAll] -> ShowS
IsSpaceAll -> String
(Int -> IsSpaceAll -> ShowS)
-> (IsSpaceAll -> String)
-> ([IsSpaceAll] -> ShowS)
-> Show IsSpaceAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsSpaceAll] -> ShowS
$cshowList :: [IsSpaceAll] -> ShowS
show :: IsSpaceAll -> String
$cshow :: IsSpaceAll -> String
showsPrec :: Int -> IsSpaceAll -> ShowS
$cshowsPrec :: Int -> IsSpaceAll -> ShowS
Show
type IsSpaceAllT = IsCharSetAll 'CSpace
instance P IsSpaceAllT x => P IsSpaceAll x where
  type PP IsSpaceAll x = Bool
  eval :: proxy IsSpaceAll -> POpts -> x -> m (TT (PP IsSpaceAll x))
eval proxy IsSpaceAll
_ = Proxy IsSpaceAllT -> POpts -> x -> m (TT (PP IsSpaceAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsSpaceAllT
forall k (t :: k). Proxy t
Proxy @IsSpaceAllT)

-- | predicate for determining if a string has all punctuation

data IsPunctuationAll deriving Int -> IsPunctuationAll -> ShowS
[IsPunctuationAll] -> ShowS
IsPunctuationAll -> String
(Int -> IsPunctuationAll -> ShowS)
-> (IsPunctuationAll -> String)
-> ([IsPunctuationAll] -> ShowS)
-> Show IsPunctuationAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsPunctuationAll] -> ShowS
$cshowList :: [IsPunctuationAll] -> ShowS
show :: IsPunctuationAll -> String
$cshow :: IsPunctuationAll -> String
showsPrec :: Int -> IsPunctuationAll -> ShowS
$cshowsPrec :: Int -> IsPunctuationAll -> ShowS
Show
type IsPunctuationAllT = IsCharSetAll 'CPunctuation
instance P IsPunctuationAllT x => P IsPunctuationAll x where
  type PP IsPunctuationAll x = Bool
  eval :: proxy IsPunctuationAll
-> POpts -> x -> m (TT (PP IsPunctuationAll x))
eval proxy IsPunctuationAll
_ = Proxy IsPunctuationAllT
-> POpts -> x -> m (TT (PP IsPunctuationAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsPunctuationAllT
forall k (t :: k). Proxy t
Proxy @IsPunctuationAllT)

-- | predicate for determining if a string has all control chars

data IsControlAll deriving Int -> IsControlAll -> ShowS
[IsControlAll] -> ShowS
IsControlAll -> String
(Int -> IsControlAll -> ShowS)
-> (IsControlAll -> String)
-> ([IsControlAll] -> ShowS)
-> Show IsControlAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsControlAll] -> ShowS
$cshowList :: [IsControlAll] -> ShowS
show :: IsControlAll -> String
$cshow :: IsControlAll -> String
showsPrec :: Int -> IsControlAll -> ShowS
$cshowsPrec :: Int -> IsControlAll -> ShowS
Show
type IsControlAllT = IsCharSetAll 'CControl
instance P IsControlAllT x => P IsControlAll x where
  type PP IsControlAll x = Bool
  eval :: proxy IsControlAll -> POpts -> x -> m (TT (PP IsControlAll x))
eval proxy IsControlAll
_ = Proxy IsControlAllT -> POpts -> x -> m (TT (PP IsControlAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsControlAllT
forall k (t :: k). Proxy t
Proxy @IsControlAllT)

-- | predicate for determining if the string is all hex digits

--

-- >>> pz @IsHexDigitAll "01efA"

-- Val True

--

-- >>> pz @IsHexDigitAll "01egfA"

-- Val False

--

data IsHexDigitAll deriving Int -> IsHexDigitAll -> ShowS
[IsHexDigitAll] -> ShowS
IsHexDigitAll -> String
(Int -> IsHexDigitAll -> ShowS)
-> (IsHexDigitAll -> String)
-> ([IsHexDigitAll] -> ShowS)
-> Show IsHexDigitAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsHexDigitAll] -> ShowS
$cshowList :: [IsHexDigitAll] -> ShowS
show :: IsHexDigitAll -> String
$cshow :: IsHexDigitAll -> String
showsPrec :: Int -> IsHexDigitAll -> ShowS
$cshowsPrec :: Int -> IsHexDigitAll -> ShowS
Show
type IsHexDigitAllT = IsCharSetAll 'CHexDigit
instance P IsHexDigitAllT x => P IsHexDigitAll x where
  type PP IsHexDigitAll x = Bool
  eval :: proxy IsHexDigitAll -> POpts -> x -> m (TT (PP IsHexDigitAll x))
eval proxy IsHexDigitAll
_ = Proxy IsHexDigitAllT -> POpts -> x -> m (TT (PP IsHexDigitAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsHexDigitAllT
forall k (t :: k). Proxy t
Proxy @IsHexDigitAllT)

-- | predicate for determining if the string is all octal digits

data IsOctDigitAll deriving Int -> IsOctDigitAll -> ShowS
[IsOctDigitAll] -> ShowS
IsOctDigitAll -> String
(Int -> IsOctDigitAll -> ShowS)
-> (IsOctDigitAll -> String)
-> ([IsOctDigitAll] -> ShowS)
-> Show IsOctDigitAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsOctDigitAll] -> ShowS
$cshowList :: [IsOctDigitAll] -> ShowS
show :: IsOctDigitAll -> String
$cshow :: IsOctDigitAll -> String
showsPrec :: Int -> IsOctDigitAll -> ShowS
$cshowsPrec :: Int -> IsOctDigitAll -> ShowS
Show
type IsOctDigitAllT = IsCharSetAll 'COctDigit
instance P IsOctDigitAllT x => P IsOctDigitAll x where
  type PP IsOctDigitAll x = Bool
  eval :: proxy IsOctDigitAll -> POpts -> x -> m (TT (PP IsOctDigitAll x))
eval proxy IsOctDigitAll
_ = Proxy IsOctDigitAllT -> POpts -> x -> m (TT (PP IsOctDigitAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsOctDigitAllT
forall k (t :: k). Proxy t
Proxy @IsOctDigitAllT)

-- | predicate for determining if the string has all separators

data IsSeparatorAll deriving Int -> IsSeparatorAll -> ShowS
[IsSeparatorAll] -> ShowS
IsSeparatorAll -> String
(Int -> IsSeparatorAll -> ShowS)
-> (IsSeparatorAll -> String)
-> ([IsSeparatorAll] -> ShowS)
-> Show IsSeparatorAll
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsSeparatorAll] -> ShowS
$cshowList :: [IsSeparatorAll] -> ShowS
show :: IsSeparatorAll -> String
$cshow :: IsSeparatorAll -> String
showsPrec :: Int -> IsSeparatorAll -> ShowS
$cshowsPrec :: Int -> IsSeparatorAll -> ShowS
Show
type IsSeparatorAllT = IsCharSetAll 'CSeparator
instance P IsSeparatorAllT x => P IsSeparatorAll x where
  type PP IsSeparatorAll x = Bool
  eval :: proxy IsSeparatorAll -> POpts -> x -> m (TT (PP IsSeparatorAll x))
eval proxy IsSeparatorAll
_ = Proxy IsSeparatorAllT
-> POpts -> x -> m (TT (PP IsSeparatorAllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsSeparatorAllT
forall k (t :: k). Proxy t
Proxy @IsSeparatorAllT)

-- | predicate for determining if the string is all latin chars

data IsLatin1All deriving Int -> IsLatin1All -> ShowS
[IsLatin1All] -> ShowS
IsLatin1All -> String
(Int -> IsLatin1All -> ShowS)
-> (IsLatin1All -> String)
-> ([IsLatin1All] -> ShowS)
-> Show IsLatin1All
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsLatin1All] -> ShowS
$cshowList :: [IsLatin1All] -> ShowS
show :: IsLatin1All -> String
$cshow :: IsLatin1All -> String
showsPrec :: Int -> IsLatin1All -> ShowS
$cshowsPrec :: Int -> IsLatin1All -> ShowS
Show
type IsLatin1AllT = IsCharSetAll 'CLatin1
instance P IsLatin1AllT x => P IsLatin1All x where
  type PP IsLatin1All x = Bool
  eval :: proxy IsLatin1All -> POpts -> x -> m (TT (PP IsLatin1All x))
eval proxy IsLatin1All
_ = Proxy IsLatin1AllT -> POpts -> x -> m (TT (PP IsLatin1AllT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsLatin1AllT
forall k (t :: k). Proxy t
Proxy @IsLatin1AllT)


-- | converts a string 'Data.Text.Lens.IsText' value to lower case

--

-- >>> pz @ToLower "HeLlO wOrld!"

-- Val "hello world!"

--

data ToLower deriving Int -> ToLower -> ShowS
[ToLower] -> ShowS
ToLower -> String
(Int -> ToLower -> ShowS)
-> (ToLower -> String) -> ([ToLower] -> ShowS) -> Show ToLower
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ToLower] -> ShowS
$cshowList :: [ToLower] -> ShowS
show :: ToLower -> String
$cshow :: ToLower -> String
showsPrec :: Int -> ToLower -> ShowS
$cshowsPrec :: Int -> ToLower -> ShowS
Show

instance ( Show a
         , DTL.IsText a
         ) => P ToLower a where
  type PP ToLower a = a
  eval :: proxy ToLower -> POpts -> a -> m (TT (PP ToLower a))
eval proxy ToLower
_ POpts
opts a
as =
    let msg0 :: String
msg0 = String
"ToLower"
        xs :: a
xs = a
as a -> (a -> a) -> a
forall a b. a -> (a -> b) -> b
& (Char -> Identity Char) -> a -> Identity a
forall t. IsText t => IndexedTraversal' Int t Char
DTL.text ((Char -> Identity Char) -> a -> Identity a)
-> (Char -> Char) -> a -> a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Char -> Char
toLower
    in TT a -> m (TT a)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT a -> m (TT a)) -> TT a -> m (TT a)
forall a b. (a -> b) -> a -> b
$ POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (a -> Val a
forall a. a -> Val a
Val a
xs) (POpts -> String -> a -> a -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg0 a
xs a
as) []

-- | converts a string 'Data.Text.Lens.IsText' value to upper case

--

-- >>> pz @ToUpper "HeLlO wOrld!"

-- Val "HELLO WORLD!"

--

data ToUpper deriving Int -> ToUpper -> ShowS
[ToUpper] -> ShowS
ToUpper -> String
(Int -> ToUpper -> ShowS)
-> (ToUpper -> String) -> ([ToUpper] -> ShowS) -> Show ToUpper
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ToUpper] -> ShowS
$cshowList :: [ToUpper] -> ShowS
show :: ToUpper -> String
$cshow :: ToUpper -> String
showsPrec :: Int -> ToUpper -> ShowS
$cshowsPrec :: Int -> ToUpper -> ShowS
Show

instance ( Show a
         , DTL.IsText a
         ) => P ToUpper a where
  type PP ToUpper a = a
  eval :: proxy ToUpper -> POpts -> a -> m (TT (PP ToUpper a))
eval proxy ToUpper
_ POpts
opts a
as =
    let msg0 :: String
msg0 = String
"ToUpper"
        xs :: a
xs = a
as a -> (a -> a) -> a
forall a b. a -> (a -> b) -> b
& (Char -> Identity Char) -> a -> Identity a
forall t. IsText t => IndexedTraversal' Int t Char
DTL.text ((Char -> Identity Char) -> a -> Identity a)
-> (Char -> Char) -> a -> a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Char -> Char
toUpper
    in TT a -> m (TT a)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT a -> m (TT a)) -> TT a -> m (TT a)
forall a b. (a -> b) -> a -> b
$ POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (a -> Val a
forall a. a -> Val a
Val a
xs) (POpts -> String -> a -> a -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg0 a
xs a
as) []


-- | converts a string 'Data.Text.Lens.IsText' value to title case

--

-- >>> pz @ToTitle "HeLlO wOrld!"

-- Val "Hello world!"

--

-- >>> data Color = Red | White | Blue | Green | Black deriving (Show,Eq,Enum,Bounded,Read)

-- >>> pz @(ToTitle >> ReadP Color Id) "red"

-- Val Red

--

data ToTitle deriving Int -> ToTitle -> ShowS
[ToTitle] -> ShowS
ToTitle -> String
(Int -> ToTitle -> ShowS)
-> (ToTitle -> String) -> ([ToTitle] -> ShowS) -> Show ToTitle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ToTitle] -> ShowS
$cshowList :: [ToTitle] -> ShowS
show :: ToTitle -> String
$cshow :: ToTitle -> String
showsPrec :: Int -> ToTitle -> ShowS
$cshowsPrec :: Int -> ToTitle -> ShowS
Show

instance ( Show a
         , DTL.IsText a
         ) => P ToTitle a where
  type PP ToTitle a = a
  eval :: proxy ToTitle -> POpts -> a -> m (TT (PP ToTitle a))
eval proxy ToTitle
_ POpts
opts a
as =
    let msg0 :: String
msg0 = String
"ToTitle"
        xs :: a
xs = ShowS
toTitleAll (a
as a -> Getting String a String -> String
forall s a. s -> Getting a s a -> a
^. Getting String a String
forall t. IsText t => Iso' t String
DTL.unpacked) String -> Getting a String a -> a
forall s a. s -> Getting a s a -> a
^. Getting a String a
forall t. IsText t => Iso' String t
DTL.packed
    in TT a -> m (TT a)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT a -> m (TT a)) -> TT a -> m (TT a)
forall a b. (a -> b) -> a -> b
$ POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (a -> Val a
forall a. a -> Val a
Val a
xs) (POpts -> String -> a -> a -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg0 a
xs a
as) []


toTitleAll :: String -> String
toTitleAll :: ShowS
toTitleAll (Char
x:String
xs) = Char -> Char
toUpper Char
x Char -> ShowS
forall a. a -> [a] -> [a]
: (Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
xs
toTitleAll [] = []