module Unicode.Char.Identifiers.Security
(
isAllowedInIdentifier
, T.IdentifierType(..)
, identifierTypes
, isIdentifierTypeAllowed
, confusablePrototype
, intentionalConfusables
, isIntentionallyConfusable
)
where
import Data.List.NonEmpty (NonEmpty)
import Data.Maybe (isJust)
import qualified GHC.Foreign as Foreign
import qualified GHC.IO.Encoding as Encoding
import System.IO.Unsafe (unsafePerformIO)
import qualified Unicode.Internal.Char.Security.Confusables as C
import qualified Unicode.Internal.Char.Security.IdentifierStatus as S
import qualified Unicode.Internal.Char.Security.IdentifierType as T
import qualified Unicode.Internal.Char.Security.IntentionalConfusables as IC
{-# INLINE isAllowedInIdentifier #-}
isAllowedInIdentifier :: Char -> Bool
isAllowedInIdentifier :: Char -> Bool
isAllowedInIdentifier = Char -> Bool
S.isAllowedInIdentifier
{-# INLINE isIdentifierTypeAllowed #-}
isIdentifierTypeAllowed :: T.IdentifierType -> Bool
isIdentifierTypeAllowed :: IdentifierType -> Bool
isIdentifierTypeAllowed = \case
IdentifierType
T.Inclusion -> Bool
True
IdentifierType
T.Recommended -> Bool
True
IdentifierType
_ -> Bool
False
{-# INLINE identifierTypes #-}
identifierTypes :: Char -> NonEmpty T.IdentifierType
identifierTypes :: Char -> NonEmpty IdentifierType
identifierTypes = Int -> NonEmpty IdentifierType
T.decodeIdentifierTypes forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
T.identifierTypes
{-# INLINE confusablePrototype #-}
confusablePrototype :: Char -> Maybe String
confusablePrototype :: Char -> Maybe String
confusablePrototype = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CString -> String
decode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Maybe CString
C.confusablePrototype
where
decode :: CString -> String
decode = forall a. IO a -> a
unsafePerformIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextEncoding -> CString -> IO String
Foreign.peekCString TextEncoding
Encoding.utf8
{-# INLINE intentionalConfusables #-}
intentionalConfusables :: Char -> String
intentionalConfusables :: Char -> String
intentionalConfusables = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty CString -> String
decode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Maybe CString
IC.intentionalConfusables
where
decode :: CString -> String
decode = forall a. IO a -> a
unsafePerformIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextEncoding -> CString -> IO String
Foreign.peekCString TextEncoding
Encoding.utf8
{-# INLINE isIntentionallyConfusable #-}
isIntentionallyConfusable :: Char -> Bool
isIntentionallyConfusable :: Char -> Bool
isIntentionallyConfusable = forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Maybe CString
IC.intentionalConfusables