module Data.Text.ICU.Spoof.Pure
(
Spoof
, SpoofParams(..)
, spoof
, spoofWithParams
, spoofFromSource
, spoofFromSerialized
, areConfusable
, getSkeleton
, spoofCheck
, getAllowedLocales
, getChecks
, getRestrictionLevel
, serialize
) where
import Data.ByteString (ByteString)
import Data.Foldable (forM_)
import Data.Text (Text)
import Data.Text.ICU.Spoof.Internal (Spoof(..))
import System.IO.Unsafe (unsafePerformIO)
import qualified Data.Text.ICU.Spoof as S
data SpoofParams
= SpoofParams {
SpoofParams -> Maybe [SpoofCheck]
spoofChecks :: Maybe [S.SpoofCheck]
, SpoofParams -> Maybe RestrictionLevel
level :: Maybe S.RestrictionLevel
, SpoofParams -> Maybe [String]
locales :: Maybe [String]
} deriving (Int -> SpoofParams -> ShowS
[SpoofParams] -> ShowS
SpoofParams -> String
(Int -> SpoofParams -> ShowS)
-> (SpoofParams -> String)
-> ([SpoofParams] -> ShowS)
-> Show SpoofParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpoofParams] -> ShowS
$cshowList :: [SpoofParams] -> ShowS
show :: SpoofParams -> String
$cshow :: SpoofParams -> String
showsPrec :: Int -> SpoofParams -> ShowS
$cshowsPrec :: Int -> SpoofParams -> ShowS
Show, SpoofParams -> SpoofParams -> Bool
(SpoofParams -> SpoofParams -> Bool)
-> (SpoofParams -> SpoofParams -> Bool) -> Eq SpoofParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpoofParams -> SpoofParams -> Bool
$c/= :: SpoofParams -> SpoofParams -> Bool
== :: SpoofParams -> SpoofParams -> Bool
$c== :: SpoofParams -> SpoofParams -> Bool
Eq)
applySpoofParams :: SpoofParams -> S.MSpoof -> S.MSpoof
applySpoofParams :: SpoofParams -> MSpoof -> MSpoof
applySpoofParams (SpoofParams Maybe [SpoofCheck]
c Maybe RestrictionLevel
lev Maybe [String]
loc) MSpoof
s = IO MSpoof -> MSpoof
forall a. IO a -> a
unsafePerformIO (IO MSpoof -> MSpoof) -> IO MSpoof -> MSpoof
forall a b. (a -> b) -> a -> b
$ do
Maybe [SpoofCheck] -> ([SpoofCheck] -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe [SpoofCheck]
c (MSpoof -> [SpoofCheck] -> IO ()
S.setChecks MSpoof
s)
Maybe RestrictionLevel -> (RestrictionLevel -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe RestrictionLevel
lev (MSpoof -> RestrictionLevel -> IO ()
S.setRestrictionLevel MSpoof
s)
Maybe [String] -> ([String] -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe [String]
loc (MSpoof -> [String] -> IO ()
S.setAllowedLocales MSpoof
s)
MSpoof -> IO MSpoof
forall (m :: * -> *) a. Monad m => a -> m a
return MSpoof
s
spoof :: Spoof
spoof :: Spoof
spoof = IO Spoof -> Spoof
forall a. IO a -> a
unsafePerformIO (IO Spoof -> Spoof) -> IO Spoof -> Spoof
forall a b. (a -> b) -> a -> b
$ MSpoof -> Spoof
S (MSpoof -> Spoof) -> IO MSpoof -> IO Spoof
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` IO MSpoof
S.open
spoofWithParams :: SpoofParams -> Spoof
spoofWithParams :: SpoofParams -> Spoof
spoofWithParams SpoofParams
p = IO Spoof -> Spoof
forall a. IO a -> a
unsafePerformIO (IO Spoof -> Spoof) -> IO Spoof -> Spoof
forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- IO MSpoof
S.open
Spoof -> IO Spoof
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S (MSpoof -> Spoof) -> MSpoof -> Spoof
forall a b. (a -> b) -> a -> b
$ SpoofParams -> MSpoof -> MSpoof
applySpoofParams SpoofParams
p MSpoof
s)
spoofFromSource :: (ByteString, ByteString) -> SpoofParams -> Spoof
spoofFromSource :: (ByteString, ByteString) -> SpoofParams -> Spoof
spoofFromSource (ByteString
confusables, ByteString
confusablesWholeScript) SpoofParams
p = IO Spoof -> Spoof
forall a. IO a -> a
unsafePerformIO (IO Spoof -> Spoof) -> IO Spoof -> Spoof
forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- (ByteString, ByteString) -> IO MSpoof
S.openFromSource (ByteString
confusables, ByteString
confusablesWholeScript)
Spoof -> IO Spoof
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S (MSpoof -> Spoof) -> MSpoof -> Spoof
forall a b. (a -> b) -> a -> b
$ SpoofParams -> MSpoof -> MSpoof
applySpoofParams SpoofParams
p MSpoof
s)
spoofFromSerialized :: ByteString -> SpoofParams -> Spoof
spoofFromSerialized :: ByteString -> SpoofParams -> Spoof
spoofFromSerialized ByteString
b SpoofParams
p = IO Spoof -> Spoof
forall a. IO a -> a
unsafePerformIO (IO Spoof -> Spoof) -> IO Spoof -> Spoof
forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- ByteString -> IO MSpoof
S.openFromSerialized ByteString
b
Spoof -> IO Spoof
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S (MSpoof -> Spoof) -> MSpoof -> Spoof
forall a b. (a -> b) -> a -> b
$ SpoofParams -> MSpoof -> MSpoof
applySpoofParams SpoofParams
p MSpoof
s)
areConfusable :: Spoof -> Text -> Text -> S.SpoofCheckResult
areConfusable :: Spoof -> Text -> Text -> SpoofCheckResult
areConfusable (S MSpoof
s) Text
t1 Text
t2 = IO SpoofCheckResult -> SpoofCheckResult
forall a. IO a -> a
unsafePerformIO (IO SpoofCheckResult -> SpoofCheckResult)
-> IO SpoofCheckResult -> SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ MSpoof -> Text -> Text -> IO SpoofCheckResult
S.areConfusable MSpoof
s Text
t1 Text
t2
spoofCheck :: Spoof -> Text -> S.SpoofCheckResult
spoofCheck :: Spoof -> Text -> SpoofCheckResult
spoofCheck (S MSpoof
s) Text
t = IO SpoofCheckResult -> SpoofCheckResult
forall a. IO a -> a
unsafePerformIO (IO SpoofCheckResult -> SpoofCheckResult)
-> IO SpoofCheckResult -> SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ MSpoof -> Text -> IO SpoofCheckResult
S.spoofCheck MSpoof
s Text
t
getSkeleton :: Spoof -> Maybe S.SkeletonTypeOverride -> Text -> Text
getSkeleton :: Spoof -> Maybe SkeletonTypeOverride -> Text -> Text
getSkeleton (S MSpoof
s) Maybe SkeletonTypeOverride
o Text
t = IO Text -> Text
forall a. IO a -> a
unsafePerformIO (IO Text -> Text) -> IO Text -> Text
forall a b. (a -> b) -> a -> b
$ MSpoof -> Maybe SkeletonTypeOverride -> Text -> IO Text
S.getSkeleton MSpoof
s Maybe SkeletonTypeOverride
o Text
t
getRestrictionLevel :: Spoof -> Maybe S.RestrictionLevel
getRestrictionLevel :: Spoof -> Maybe RestrictionLevel
getRestrictionLevel (S MSpoof
s) = IO (Maybe RestrictionLevel) -> Maybe RestrictionLevel
forall a. IO a -> a
unsafePerformIO (IO (Maybe RestrictionLevel) -> Maybe RestrictionLevel)
-> IO (Maybe RestrictionLevel) -> Maybe RestrictionLevel
forall a b. (a -> b) -> a -> b
$ MSpoof -> IO (Maybe RestrictionLevel)
S.getRestrictionLevel MSpoof
s
getChecks :: Spoof -> [S.SpoofCheck]
getChecks :: Spoof -> [SpoofCheck]
getChecks (S MSpoof
s) = IO [SpoofCheck] -> [SpoofCheck]
forall a. IO a -> a
unsafePerformIO (IO [SpoofCheck] -> [SpoofCheck])
-> IO [SpoofCheck] -> [SpoofCheck]
forall a b. (a -> b) -> a -> b
$ MSpoof -> IO [SpoofCheck]
S.getChecks MSpoof
s
getAllowedLocales :: Spoof -> [String]
getAllowedLocales :: Spoof -> [String]
getAllowedLocales (S MSpoof
s) = IO [String] -> [String]
forall a. IO a -> a
unsafePerformIO (IO [String] -> [String]) -> IO [String] -> [String]
forall a b. (a -> b) -> a -> b
$ MSpoof -> IO [String]
S.getAllowedLocales MSpoof
s
serialize :: Spoof -> ByteString
serialize :: Spoof -> ByteString
serialize (S MSpoof
s) = IO ByteString -> ByteString
forall a. IO a -> a
unsafePerformIO (IO ByteString -> ByteString) -> IO ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ MSpoof -> IO ByteString
S.serialize MSpoof
s
{-# INLINE spoofCheck #-}