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
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
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 = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ do
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)
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)
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)
forall (m :: * -> *) a. Monad m => a -> m a
return MSpoof
s
spoof :: Spoof
spoof :: Spoof
spoof = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ MSpoof -> Spoof
S forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` IO MSpoof
S.open
{-# NOINLINE spoof #-}
spoofWithParams :: SpoofParams -> Spoof
spoofWithParams :: SpoofParams -> Spoof
spoofWithParams SpoofParams
p = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- IO MSpoof
S.open
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S 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 = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- (ByteString, ByteString) -> IO MSpoof
S.openFromSource (ByteString
confusables, ByteString
confusablesWholeScript)
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S 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 = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ do
MSpoof
s <- ByteString -> IO MSpoof
S.openFromSerialized ByteString
b
forall (m :: * -> *) a. Monad m => a -> m a
return (MSpoof -> Spoof
S 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 = forall a. IO a -> a
unsafePerformIO 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 = forall a. IO a -> a
unsafePerformIO 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 = forall a. IO a -> a
unsafePerformIO 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) = forall a. IO a -> a
unsafePerformIO 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) = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ MSpoof -> IO [SpoofCheck]
S.getChecks MSpoof
s
getAllowedLocales :: Spoof -> [String]
getAllowedLocales :: Spoof -> [String]
getAllowedLocales (S MSpoof
s) = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ MSpoof -> IO [String]
S.getAllowedLocales MSpoof
s
serialize :: Spoof -> ByteString
serialize :: Spoof -> ByteString
serialize (S MSpoof
s) = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ MSpoof -> IO ByteString
S.serialize MSpoof
s
{-# INLINE spoofCheck #-}