{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module Htcc.CRules.Char (
isValidChar,
GenericStr (..)
) where
import Data.Char (isAlpha, isDigit)
import qualified Data.Text as T
import Htcc.Utils (lor, sop, sopText)
isValidChar :: Char -> Bool
isValidChar :: Char -> Bool
isValidChar = [Char -> Bool] -> Char -> Bool
forall a. [a -> Bool] -> a -> Bool
lor [Char -> Bool
isAlpha, (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_'), Char -> Bool
isDigit]
class GenericStr a where
isValid :: a -> Bool
instance GenericStr String where
isValid :: String -> Bool
isValid [] = Bool
False
isValid (x :: Char
x:xs :: String
xs) = [Char -> Bool
isAlpha, (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_')] [Char -> Bool] -> Char -> Bool
forall a. [a -> Bool] -> a -> Bool
`lor` Char
x Bool -> Bool -> Bool
&& [Char -> Bool
isAlpha, (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_'), Char -> Bool
isDigit] [Char -> Bool] -> String -> Bool
forall a. [a -> Bool] -> [a] -> Bool
`sop` String
xs
instance GenericStr T.Text where
isValid :: Text -> Bool
isValid xs :: Text
xs
| Text -> Bool
T.null Text
xs = Bool
False
| Bool
otherwise = [Char -> Bool
isAlpha, (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_')] [Char -> Bool] -> Char -> Bool
forall a. [a -> Bool] -> a -> Bool
`lor` Text -> Char
T.head Text
xs Bool -> Bool -> Bool
&& [Char -> Bool
isAlpha, (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_'), Char -> Bool
isDigit] [Char -> Bool] -> Text -> Bool
`sopText` Text -> Text
T.tail Text
xs