{-# LINE 1 "Data/Text/ICU/Spoof.hsc" #-}
{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable, ForeignFunctionInterface,
OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
module Data.Text.ICU.Spoof
(
MSpoof
, OpenFromSourceParseError(..)
, SpoofCheck(..)
, SpoofCheckResult(..)
, RestrictionLevel(..)
, SkeletonTypeOverride(..)
, open
, openFromSerialized
, openFromSource
, getSkeleton
, getChecks
, setChecks
, getRestrictionLevel
, setRestrictionLevel
, getAllowedLocales
, setAllowedLocales
, areConfusable
, spoofCheck
, serialize
) where
import Control.DeepSeq (NFData(..))
import Control.Exception (Exception, throwIO, catchJust)
import Data.Bits ((.&.))
import Data.ByteString (ByteString)
import Data.ByteString.Internal (create, memcpy, toForeignPtr)
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import Data.Int (Int32)
import Data.List (intercalate)
import Data.Text (Text, pack, splitOn, strip, unpack)
import Data.Text.Foreign (useAsPtr)
import Data.Text.ICU.BitMask (ToBitMask, fromBitMask, highestValueInBitMask,
toBitMask)
import Data.Text.ICU.Spoof.Internal (MSpoof, USpoof, withSpoof, wrap,
wrapWithSerialized)
import Data.Text.ICU.Error (u_PARSE_ERROR)
import Data.Text.ICU.Error.Internal (UErrorCode, UParseError,
ParseError(..), handleError,
handleOverflowError, handleParseError)
{-# LINE 70 "Data/Text/ICU/Spoof.hsc" #-}
import Data.Text.Foreign (fromPtr)
{-# LINE 75 "Data/Text/ICU/Spoof.hsc" #-}
import Data.Typeable (Typeable)
import Data.Word (Word8)
import Foreign.C.String (CString, peekCString, withCString)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr, nullPtr, plusPtr)
import Foreign.Storable (peek)
import Foreign.ForeignPtr (withForeignPtr)
data SpoofCheck
= SingleScriptConfusable
| MixedScriptConfusable
| WholeScriptConfusable
| AnyCase
| RestrictionLevel
| Invisible
| CharLimit
| MixedNumbers
| AllChecks
| AuxInfo
deriving (SpoofCheck
SpoofCheck -> SpoofCheck -> Bounded SpoofCheck
forall a. a -> a -> Bounded a
maxBound :: SpoofCheck
$cmaxBound :: SpoofCheck
minBound :: SpoofCheck
$cminBound :: SpoofCheck
Bounded, Int -> SpoofCheck
SpoofCheck -> Int
SpoofCheck -> [SpoofCheck]
SpoofCheck -> SpoofCheck
SpoofCheck -> SpoofCheck -> [SpoofCheck]
SpoofCheck -> SpoofCheck -> SpoofCheck -> [SpoofCheck]
(SpoofCheck -> SpoofCheck)
-> (SpoofCheck -> SpoofCheck)
-> (Int -> SpoofCheck)
-> (SpoofCheck -> Int)
-> (SpoofCheck -> [SpoofCheck])
-> (SpoofCheck -> SpoofCheck -> [SpoofCheck])
-> (SpoofCheck -> SpoofCheck -> [SpoofCheck])
-> (SpoofCheck -> SpoofCheck -> SpoofCheck -> [SpoofCheck])
-> Enum SpoofCheck
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 :: SpoofCheck -> SpoofCheck -> SpoofCheck -> [SpoofCheck]
$cenumFromThenTo :: SpoofCheck -> SpoofCheck -> SpoofCheck -> [SpoofCheck]
enumFromTo :: SpoofCheck -> SpoofCheck -> [SpoofCheck]
$cenumFromTo :: SpoofCheck -> SpoofCheck -> [SpoofCheck]
enumFromThen :: SpoofCheck -> SpoofCheck -> [SpoofCheck]
$cenumFromThen :: SpoofCheck -> SpoofCheck -> [SpoofCheck]
enumFrom :: SpoofCheck -> [SpoofCheck]
$cenumFrom :: SpoofCheck -> [SpoofCheck]
fromEnum :: SpoofCheck -> Int
$cfromEnum :: SpoofCheck -> Int
toEnum :: Int -> SpoofCheck
$ctoEnum :: Int -> SpoofCheck
pred :: SpoofCheck -> SpoofCheck
$cpred :: SpoofCheck -> SpoofCheck
succ :: SpoofCheck -> SpoofCheck
$csucc :: SpoofCheck -> SpoofCheck
Enum, SpoofCheck -> SpoofCheck -> Bool
(SpoofCheck -> SpoofCheck -> Bool)
-> (SpoofCheck -> SpoofCheck -> Bool) -> Eq SpoofCheck
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpoofCheck -> SpoofCheck -> Bool
$c/= :: SpoofCheck -> SpoofCheck -> Bool
== :: SpoofCheck -> SpoofCheck -> Bool
$c== :: SpoofCheck -> SpoofCheck -> Bool
Eq, Int -> SpoofCheck -> ShowS
[SpoofCheck] -> ShowS
SpoofCheck -> [Char]
(Int -> SpoofCheck -> ShowS)
-> (SpoofCheck -> [Char])
-> ([SpoofCheck] -> ShowS)
-> Show SpoofCheck
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [SpoofCheck] -> ShowS
$cshowList :: [SpoofCheck] -> ShowS
show :: SpoofCheck -> [Char]
$cshow :: SpoofCheck -> [Char]
showsPrec :: Int -> SpoofCheck -> ShowS
$cshowsPrec :: Int -> SpoofCheck -> ShowS
Show)
instance ToBitMask SpoofCheck where
toBitMask :: SpoofCheck -> Int
toBitMask SpoofCheck
SingleScriptConfusable = Int
1
{-# LINE 172 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask MixedScriptConfusable = 2
{-# LINE 173 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask WholeScriptConfusable = 4
{-# LINE 174 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask AnyCase = 8
{-# LINE 175 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask RestrictionLevel = 16
{-# LINE 176 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask Invisible = 32
{-# LINE 177 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask CharLimit = 64
{-# LINE 178 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask MixedNumbers = 128
{-# LINE 179 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask AllChecks = 65535
{-# LINE 180 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask AuxInfo = 1073741824
{-# LINE 181 "Data/Text/ICU/Spoof.hsc" #-}
type USpoofCheck = Int32
data RestrictionLevel
= ASCII
| SingleScriptRestrictive
| HighlyRestrictive
| ModeratelyRestrictive
| MinimallyRestrictive
| Unrestrictive
deriving (RestrictionLevel
RestrictionLevel -> RestrictionLevel -> Bounded RestrictionLevel
forall a. a -> a -> Bounded a
maxBound :: RestrictionLevel
$cmaxBound :: RestrictionLevel
minBound :: RestrictionLevel
$cminBound :: RestrictionLevel
Bounded, Int -> RestrictionLevel
RestrictionLevel -> Int
RestrictionLevel -> [RestrictionLevel]
RestrictionLevel -> RestrictionLevel
RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
RestrictionLevel
-> RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
(RestrictionLevel -> RestrictionLevel)
-> (RestrictionLevel -> RestrictionLevel)
-> (Int -> RestrictionLevel)
-> (RestrictionLevel -> Int)
-> (RestrictionLevel -> [RestrictionLevel])
-> (RestrictionLevel -> RestrictionLevel -> [RestrictionLevel])
-> (RestrictionLevel -> RestrictionLevel -> [RestrictionLevel])
-> (RestrictionLevel
-> RestrictionLevel -> RestrictionLevel -> [RestrictionLevel])
-> Enum RestrictionLevel
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 :: RestrictionLevel
-> RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
$cenumFromThenTo :: RestrictionLevel
-> RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
enumFromTo :: RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
$cenumFromTo :: RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
enumFromThen :: RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
$cenumFromThen :: RestrictionLevel -> RestrictionLevel -> [RestrictionLevel]
enumFrom :: RestrictionLevel -> [RestrictionLevel]
$cenumFrom :: RestrictionLevel -> [RestrictionLevel]
fromEnum :: RestrictionLevel -> Int
$cfromEnum :: RestrictionLevel -> Int
toEnum :: Int -> RestrictionLevel
$ctoEnum :: Int -> RestrictionLevel
pred :: RestrictionLevel -> RestrictionLevel
$cpred :: RestrictionLevel -> RestrictionLevel
succ :: RestrictionLevel -> RestrictionLevel
$csucc :: RestrictionLevel -> RestrictionLevel
Enum, RestrictionLevel -> RestrictionLevel -> Bool
(RestrictionLevel -> RestrictionLevel -> Bool)
-> (RestrictionLevel -> RestrictionLevel -> Bool)
-> Eq RestrictionLevel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RestrictionLevel -> RestrictionLevel -> Bool
$c/= :: RestrictionLevel -> RestrictionLevel -> Bool
== :: RestrictionLevel -> RestrictionLevel -> Bool
$c== :: RestrictionLevel -> RestrictionLevel -> Bool
Eq, Int -> RestrictionLevel -> ShowS
[RestrictionLevel] -> ShowS
RestrictionLevel -> [Char]
(Int -> RestrictionLevel -> ShowS)
-> (RestrictionLevel -> [Char])
-> ([RestrictionLevel] -> ShowS)
-> Show RestrictionLevel
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [RestrictionLevel] -> ShowS
$cshowList :: [RestrictionLevel] -> ShowS
show :: RestrictionLevel -> [Char]
$cshow :: RestrictionLevel -> [Char]
showsPrec :: Int -> RestrictionLevel -> ShowS
$cshowsPrec :: Int -> RestrictionLevel -> ShowS
Show)
instance ToBitMask RestrictionLevel where
toBitMask :: RestrictionLevel -> Int
toBitMask RestrictionLevel
ASCII = Int
268435456
{-# LINE 207 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask SingleScriptRestrictive = 536870912
{-# LINE 208 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask HighlyRestrictive = 805306368
{-# LINE 209 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask ModeratelyRestrictive = 1073741824
{-# LINE 210 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask MinimallyRestrictive = 1342177280
{-# LINE 211 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask Unrestrictive = 1610612736
{-# LINE 212 "Data/Text/ICU/Spoof.hsc" #-}
type URestrictionLevel = Int32
data SpoofCheckResult
= CheckOK
| CheckFailed [SpoofCheck]
| CheckFailedWithRestrictionLevel {
SpoofCheckResult -> [SpoofCheck]
failedChecks :: [SpoofCheck]
, SpoofCheckResult -> RestrictionLevel
failedLevel :: RestrictionLevel
}
deriving (SpoofCheckResult -> SpoofCheckResult -> Bool
(SpoofCheckResult -> SpoofCheckResult -> Bool)
-> (SpoofCheckResult -> SpoofCheckResult -> Bool)
-> Eq SpoofCheckResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpoofCheckResult -> SpoofCheckResult -> Bool
$c/= :: SpoofCheckResult -> SpoofCheckResult -> Bool
== :: SpoofCheckResult -> SpoofCheckResult -> Bool
$c== :: SpoofCheckResult -> SpoofCheckResult -> Bool
Eq, Int -> SpoofCheckResult -> ShowS
[SpoofCheckResult] -> ShowS
SpoofCheckResult -> [Char]
(Int -> SpoofCheckResult -> ShowS)
-> (SpoofCheckResult -> [Char])
-> ([SpoofCheckResult] -> ShowS)
-> Show SpoofCheckResult
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [SpoofCheckResult] -> ShowS
$cshowList :: [SpoofCheckResult] -> ShowS
show :: SpoofCheckResult -> [Char]
$cshow :: SpoofCheckResult -> [Char]
showsPrec :: Int -> SpoofCheckResult -> ShowS
$cshowsPrec :: Int -> SpoofCheckResult -> ShowS
Show)
data SkeletonTypeOverride
= SkeletonSingleScript
| SkeletonAnyCase
deriving (SkeletonTypeOverride
SkeletonTypeOverride
-> SkeletonTypeOverride -> Bounded SkeletonTypeOverride
forall a. a -> a -> Bounded a
maxBound :: SkeletonTypeOverride
$cmaxBound :: SkeletonTypeOverride
minBound :: SkeletonTypeOverride
$cminBound :: SkeletonTypeOverride
Bounded, Int -> SkeletonTypeOverride
SkeletonTypeOverride -> Int
SkeletonTypeOverride -> [SkeletonTypeOverride]
SkeletonTypeOverride -> SkeletonTypeOverride
SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride]
SkeletonTypeOverride
-> SkeletonTypeOverride
-> SkeletonTypeOverride
-> [SkeletonTypeOverride]
(SkeletonTypeOverride -> SkeletonTypeOverride)
-> (SkeletonTypeOverride -> SkeletonTypeOverride)
-> (Int -> SkeletonTypeOverride)
-> (SkeletonTypeOverride -> Int)
-> (SkeletonTypeOverride -> [SkeletonTypeOverride])
-> (SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride])
-> (SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride])
-> (SkeletonTypeOverride
-> SkeletonTypeOverride
-> SkeletonTypeOverride
-> [SkeletonTypeOverride])
-> Enum SkeletonTypeOverride
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 :: SkeletonTypeOverride
-> SkeletonTypeOverride
-> SkeletonTypeOverride
-> [SkeletonTypeOverride]
$cenumFromThenTo :: SkeletonTypeOverride
-> SkeletonTypeOverride
-> SkeletonTypeOverride
-> [SkeletonTypeOverride]
enumFromTo :: SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride]
$cenumFromTo :: SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride]
enumFromThen :: SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride]
$cenumFromThen :: SkeletonTypeOverride
-> SkeletonTypeOverride -> [SkeletonTypeOverride]
enumFrom :: SkeletonTypeOverride -> [SkeletonTypeOverride]
$cenumFrom :: SkeletonTypeOverride -> [SkeletonTypeOverride]
fromEnum :: SkeletonTypeOverride -> Int
$cfromEnum :: SkeletonTypeOverride -> Int
toEnum :: Int -> SkeletonTypeOverride
$ctoEnum :: Int -> SkeletonTypeOverride
pred :: SkeletonTypeOverride -> SkeletonTypeOverride
$cpred :: SkeletonTypeOverride -> SkeletonTypeOverride
succ :: SkeletonTypeOverride -> SkeletonTypeOverride
$csucc :: SkeletonTypeOverride -> SkeletonTypeOverride
Enum, SkeletonTypeOverride -> SkeletonTypeOverride -> Bool
(SkeletonTypeOverride -> SkeletonTypeOverride -> Bool)
-> (SkeletonTypeOverride -> SkeletonTypeOverride -> Bool)
-> Eq SkeletonTypeOverride
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SkeletonTypeOverride -> SkeletonTypeOverride -> Bool
$c/= :: SkeletonTypeOverride -> SkeletonTypeOverride -> Bool
== :: SkeletonTypeOverride -> SkeletonTypeOverride -> Bool
$c== :: SkeletonTypeOverride -> SkeletonTypeOverride -> Bool
Eq, Int -> SkeletonTypeOverride -> ShowS
[SkeletonTypeOverride] -> ShowS
SkeletonTypeOverride -> [Char]
(Int -> SkeletonTypeOverride -> ShowS)
-> (SkeletonTypeOverride -> [Char])
-> ([SkeletonTypeOverride] -> ShowS)
-> Show SkeletonTypeOverride
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [SkeletonTypeOverride] -> ShowS
$cshowList :: [SkeletonTypeOverride] -> ShowS
show :: SkeletonTypeOverride -> [Char]
$cshow :: SkeletonTypeOverride -> [Char]
showsPrec :: Int -> SkeletonTypeOverride -> ShowS
$cshowsPrec :: Int -> SkeletonTypeOverride -> ShowS
Show)
instance ToBitMask SkeletonTypeOverride where
toBitMask :: SkeletonTypeOverride -> Int
toBitMask SkeletonTypeOverride
SkeletonSingleScript = Int
1
{-# LINE 244 "Data/Text/ICU/Spoof.hsc" #-}
toBitMask SkeletonAnyCase = 8
{-# LINE 245 "Data/Text/ICU/Spoof.hsc" #-}
type USkeletonTypeOverride = Int32
makeSpoofCheckResult :: USpoofCheck -> SpoofCheckResult
makeSpoofCheckResult :: Int32 -> SpoofCheckResult
makeSpoofCheckResult Int32
c =
case Int32
c of
Int32
0 -> SpoofCheckResult
CheckOK
Int32
_ ->
case Maybe RestrictionLevel
restrictionLevel of
Maybe RestrictionLevel
Nothing -> [SpoofCheck] -> SpoofCheckResult
CheckFailed [SpoofCheck]
spoofChecks
Just RestrictionLevel
l -> [SpoofCheck] -> RestrictionLevel -> SpoofCheckResult
CheckFailedWithRestrictionLevel [SpoofCheck]
spoofChecks RestrictionLevel
l
where spoofChecks :: [SpoofCheck]
spoofChecks = Int -> [SpoofCheck]
forall a. (Enum a, Bounded a, ToBitMask a) => Int -> [a]
fromBitMask (Int -> [SpoofCheck]) -> Int -> [SpoofCheck]
forall a b. (a -> b) -> a -> b
$ Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> Int) -> Int32 -> Int
forall a b. (a -> b) -> a -> b
$
Int32
c Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
.&. Int32
65535
{-# LINE 258 "Data/Text/ICU/Spoof.hsc" #-}
restrictionValue :: Int32
restrictionValue = Int32
c Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
.&. Int32
2130706432
{-# LINE 259 "Data/Text/ICU/Spoof.hsc" #-}
restrictionLevel :: Maybe RestrictionLevel
restrictionLevel = Int -> Maybe RestrictionLevel
forall a. (Enum a, Bounded a, ToBitMask a) => Int -> Maybe a
highestValueInBitMask (Int -> Maybe RestrictionLevel) -> Int -> Maybe RestrictionLevel
forall a b. (a -> b) -> a -> b
$ Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> Int) -> Int32 -> Int
forall a b. (a -> b) -> a -> b
$
Int32
restrictionValue
data OpenFromSourceParseErrorFile =
ConfusablesTxtError | ConfusablesWholeScriptTxtError
deriving (OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool
(OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool)
-> (OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool)
-> Eq OpenFromSourceParseErrorFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool
$c/= :: OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool
== :: OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool
$c== :: OpenFromSourceParseErrorFile
-> OpenFromSourceParseErrorFile -> Bool
Eq, Int -> OpenFromSourceParseErrorFile -> ShowS
[OpenFromSourceParseErrorFile] -> ShowS
OpenFromSourceParseErrorFile -> [Char]
(Int -> OpenFromSourceParseErrorFile -> ShowS)
-> (OpenFromSourceParseErrorFile -> [Char])
-> ([OpenFromSourceParseErrorFile] -> ShowS)
-> Show OpenFromSourceParseErrorFile
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [OpenFromSourceParseErrorFile] -> ShowS
$cshowList :: [OpenFromSourceParseErrorFile] -> ShowS
show :: OpenFromSourceParseErrorFile -> [Char]
$cshow :: OpenFromSourceParseErrorFile -> [Char]
showsPrec :: Int -> OpenFromSourceParseErrorFile -> ShowS
$cshowsPrec :: Int -> OpenFromSourceParseErrorFile -> ShowS
Show)
instance NFData OpenFromSourceParseErrorFile where
rnf :: OpenFromSourceParseErrorFile -> ()
rnf !OpenFromSourceParseErrorFile
_ = ()
data OpenFromSourceParseError = OpenFromSourceParseError {
OpenFromSourceParseError -> OpenFromSourceParseErrorFile
errFile :: OpenFromSourceParseErrorFile
, OpenFromSourceParseError -> ParseError
parseError :: ParseError
} deriving (Int -> OpenFromSourceParseError -> ShowS
[OpenFromSourceParseError] -> ShowS
OpenFromSourceParseError -> [Char]
(Int -> OpenFromSourceParseError -> ShowS)
-> (OpenFromSourceParseError -> [Char])
-> ([OpenFromSourceParseError] -> ShowS)
-> Show OpenFromSourceParseError
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [OpenFromSourceParseError] -> ShowS
$cshowList :: [OpenFromSourceParseError] -> ShowS
show :: OpenFromSourceParseError -> [Char]
$cshow :: OpenFromSourceParseError -> [Char]
showsPrec :: Int -> OpenFromSourceParseError -> ShowS
$cshowsPrec :: Int -> OpenFromSourceParseError -> ShowS
Show, Typeable)
instance NFData OpenFromSourceParseError where
rnf :: OpenFromSourceParseError -> ()
rnf OpenFromSourceParseError{ParseError
OpenFromSourceParseErrorFile
parseError :: ParseError
errFile :: OpenFromSourceParseErrorFile
parseError :: OpenFromSourceParseError -> ParseError
errFile :: OpenFromSourceParseError -> OpenFromSourceParseErrorFile
..} = ParseError -> ()
forall a. NFData a => a -> ()
rnf ParseError
parseError () -> () -> ()
`seq` OpenFromSourceParseErrorFile -> ()
forall a. NFData a => a -> ()
rnf OpenFromSourceParseErrorFile
errFile
instance Exception OpenFromSourceParseError
open :: IO MSpoof
open :: IO MSpoof
open = IO (Ptr USpoof) -> IO MSpoof
wrap (IO (Ptr USpoof) -> IO MSpoof) -> IO (Ptr USpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ (Ptr UErrorCode -> IO (Ptr USpoof)) -> IO (Ptr USpoof)
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError Ptr UErrorCode -> IO (Ptr USpoof)
uspoof_open
isParseError :: ParseError -> Maybe ParseError
isParseError :: ParseError -> Maybe ParseError
isParseError = ParseError -> Maybe ParseError
forall a. a -> Maybe a
Just
openFromSource :: (ByteString, ByteString) -> IO MSpoof
openFromSource :: (ByteString, ByteString) -> IO MSpoof
openFromSource (ByteString
confusables, ByteString
confusablesWholeScript) =
ByteString -> (CStringLen -> IO MSpoof) -> IO MSpoof
forall a. ByteString -> (CStringLen -> IO a) -> IO a
unsafeUseAsCStringLen ByteString
confusables ((CStringLen -> IO MSpoof) -> IO MSpoof)
-> (CStringLen -> IO MSpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
cptr, Int
clen) ->
ByteString -> (CStringLen -> IO MSpoof) -> IO MSpoof
forall a. ByteString -> (CStringLen -> IO a) -> IO a
unsafeUseAsCStringLen ByteString
confusablesWholeScript ((CStringLen -> IO MSpoof) -> IO MSpoof)
-> (CStringLen -> IO MSpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
wptr, Int
wlen) ->
Int32 -> (Ptr Int32 -> IO MSpoof) -> IO MSpoof
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Int32
0 ((Ptr Int32 -> IO MSpoof) -> IO MSpoof)
-> (Ptr Int32 -> IO MSpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ \Ptr Int32
errTypePtr ->
(ParseError -> Maybe ParseError)
-> IO MSpoof -> (ParseError -> IO MSpoof) -> IO MSpoof
forall e b a.
Exception e =>
(e -> Maybe b) -> IO a -> (b -> IO a) -> IO a
catchJust
ParseError -> Maybe ParseError
isParseError
(IO (Ptr USpoof) -> IO MSpoof
wrap (IO (Ptr USpoof) -> IO MSpoof) -> IO (Ptr USpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ (ICUError -> Bool)
-> (Ptr ParseError -> Ptr UErrorCode -> IO (Ptr USpoof))
-> IO (Ptr USpoof)
forall a.
(ICUError -> Bool)
-> (Ptr ParseError -> Ptr UErrorCode -> IO a) -> IO a
handleParseError
(ICUError -> ICUError -> Bool
forall a. Eq a => a -> a -> Bool
== ICUError
u_PARSE_ERROR)
(Ptr CChar
-> Int32
-> Ptr CChar
-> Int32
-> Ptr Int32
-> Ptr ParseError
-> Ptr UErrorCode
-> IO (Ptr USpoof)
uspoof_openFromSource Ptr CChar
cptr (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
clen) Ptr CChar
wptr
(Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
wlen) Ptr Int32
errTypePtr))
(Ptr Int32 -> ParseError -> IO MSpoof
forall a. Ptr Int32 -> ParseError -> IO a
throwOpenFromSourceParseError Ptr Int32
errTypePtr)
throwOpenFromSourceParseError :: Ptr Int32 -> ParseError -> IO a
throwOpenFromSourceParseError :: forall a. Ptr Int32 -> ParseError -> IO a
throwOpenFromSourceParseError Ptr Int32
errTypePtr ParseError
parseErr = do
Int32
errType <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek Ptr Int32
errTypePtr
let errFile :: OpenFromSourceParseErrorFile
errFile =
if Int32
errType Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
1
{-# LINE 313 "Data/Text/ICU/Spoof.hsc" #-}
then OpenFromSourceParseErrorFile
ConfusablesTxtError
else OpenFromSourceParseErrorFile
ConfusablesWholeScriptTxtError
OpenFromSourceParseError -> IO a
forall e a. Exception e => e -> IO a
throwIO (OpenFromSourceParseError -> IO a)
-> OpenFromSourceParseError -> IO a
forall a b. (a -> b) -> a -> b
$! OpenFromSourceParseErrorFile
-> ParseError -> OpenFromSourceParseError
OpenFromSourceParseError OpenFromSourceParseErrorFile
errFile ParseError
parseErr
openFromSerialized :: ByteString -> IO MSpoof
openFromSerialized :: ByteString -> IO MSpoof
openFromSerialized ByteString
b =
case ByteString -> (ForeignPtr Word8, Int, Int)
toForeignPtr ByteString
b of
(ForeignPtr Word8
ptr, Int
off, Int
len) -> ForeignPtr Word8 -> (Ptr Word8 -> IO MSpoof) -> IO MSpoof
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
ptr ((Ptr Word8 -> IO MSpoof) -> IO MSpoof)
-> (Ptr Word8 -> IO MSpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
p ->
ForeignPtr Word8 -> IO (Ptr USpoof) -> IO MSpoof
wrapWithSerialized ForeignPtr Word8
ptr (IO (Ptr USpoof) -> IO MSpoof) -> IO (Ptr USpoof) -> IO MSpoof
forall a b. (a -> b) -> a -> b
$ (Ptr UErrorCode -> IO (Ptr USpoof)) -> IO (Ptr USpoof)
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError
(Ptr Word8
-> Int32 -> Ptr Int32 -> Ptr UErrorCode -> IO (Ptr USpoof)
uspoof_openFromSerialized (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off) (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len) Ptr Int32
forall a. Ptr a
nullPtr)
getChecks :: MSpoof -> IO [SpoofCheck]
getChecks :: MSpoof -> IO [SpoofCheck]
getChecks MSpoof
s = MSpoof -> (Ptr USpoof -> IO [SpoofCheck]) -> IO [SpoofCheck]
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO [SpoofCheck]) -> IO [SpoofCheck])
-> (Ptr USpoof -> IO [SpoofCheck]) -> IO [SpoofCheck]
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
(Int -> [SpoofCheck]
forall a. (Enum a, Bounded a, ToBitMask a) => Int -> [a]
fromBitMask (Int -> [SpoofCheck]) -> (Int32 -> Int) -> Int32 -> [SpoofCheck]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> Int) -> (Int32 -> Int32) -> Int32 -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
(.&.) Int32
65535) (Int32 -> [SpoofCheck]) -> IO Int32 -> IO [SpoofCheck]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
{-# LINE 333 "Data/Text/ICU/Spoof.hsc" #-}
handleError (uspoof_getChecks sptr)
setChecks :: MSpoof -> [SpoofCheck] -> IO ()
setChecks :: MSpoof -> [SpoofCheck] -> IO ()
setChecks MSpoof
s [SpoofCheck]
c = MSpoof -> (Ptr USpoof -> IO ()) -> IO ()
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO ()) -> IO ()) -> (Ptr USpoof -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
(Ptr UErrorCode -> IO ()) -> IO ()
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError ((Ptr UErrorCode -> IO ()) -> IO ())
-> (Ptr UErrorCode -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr USpoof -> Int32 -> Ptr UErrorCode -> IO ()
uspoof_setChecks Ptr USpoof
sptr (Int32 -> Ptr UErrorCode -> IO ())
-> (Int -> Int32) -> Int -> Ptr UErrorCode -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Ptr UErrorCode -> IO ()) -> Int -> Ptr UErrorCode -> IO ()
forall a b. (a -> b) -> a -> b
$ [SpoofCheck] -> Int
forall a. ToBitMask a => a -> Int
toBitMask [SpoofCheck]
c
getRestrictionLevel :: MSpoof -> IO (Maybe RestrictionLevel)
getRestrictionLevel :: MSpoof -> IO (Maybe RestrictionLevel)
getRestrictionLevel MSpoof
s = MSpoof
-> (Ptr USpoof -> IO (Maybe RestrictionLevel))
-> IO (Maybe RestrictionLevel)
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO (Maybe RestrictionLevel))
-> IO (Maybe RestrictionLevel))
-> (Ptr USpoof -> IO (Maybe RestrictionLevel))
-> IO (Maybe RestrictionLevel)
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
(Int -> Maybe RestrictionLevel
forall a. (Enum a, Bounded a, ToBitMask a) => Int -> Maybe a
highestValueInBitMask (Int -> Maybe RestrictionLevel)
-> (Int32 -> Int) -> Int32 -> Maybe RestrictionLevel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (Int32 -> Maybe RestrictionLevel)
-> IO Int32 -> IO (Maybe RestrictionLevel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr USpoof -> IO Int32
uspoof_getRestrictionLevel Ptr USpoof
sptr
setRestrictionLevel :: MSpoof -> RestrictionLevel -> IO ()
setRestrictionLevel :: MSpoof -> RestrictionLevel -> IO ()
setRestrictionLevel MSpoof
s RestrictionLevel
l = MSpoof -> (Ptr USpoof -> IO ()) -> IO ()
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO ()) -> IO ()) -> (Ptr USpoof -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
Ptr USpoof -> Int32 -> IO ()
uspoof_setRestrictionLevel Ptr USpoof
sptr (Int32 -> IO ()) -> (Int -> Int32) -> Int -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ RestrictionLevel -> Int
forall a. ToBitMask a => a -> Int
toBitMask RestrictionLevel
l
getAllowedLocales :: MSpoof -> IO [String]
getAllowedLocales :: MSpoof -> IO [[Char]]
getAllowedLocales MSpoof
s = MSpoof -> (Ptr USpoof -> IO [[Char]]) -> IO [[Char]]
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO [[Char]]) -> IO [[Char]])
-> (Ptr USpoof -> IO [[Char]]) -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
[Char] -> [[Char]]
splitLocales ([Char] -> [[Char]]) -> IO [Char] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr CChar -> IO [Char]
peekCString (Ptr CChar -> IO [Char]) -> IO (Ptr CChar) -> IO [Char]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Ptr UErrorCode -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError (Ptr USpoof -> Ptr UErrorCode -> IO (Ptr CChar)
uspoof_getAllowedLocales Ptr USpoof
sptr))
where splitLocales :: [Char] -> [[Char]]
splitLocales = (Text -> [Char]) -> [Text] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> [Char]
unpack (Text -> [Char]) -> (Text -> Text) -> Text -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
strip) ([Text] -> [[Char]]) -> ([Char] -> [Text]) -> [Char] -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
splitOn Text
"," (Text -> [Text]) -> ([Char] -> Text) -> [Char] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
pack
setAllowedLocales :: MSpoof -> [String] -> IO ()
setAllowedLocales :: MSpoof -> [[Char]] -> IO ()
setAllowedLocales MSpoof
s [[Char]]
locs = MSpoof -> (Ptr USpoof -> IO ()) -> IO ()
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO ()) -> IO ()) -> (Ptr USpoof -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
[Char] -> (Ptr CChar -> IO ()) -> IO ()
forall a. [Char] -> (Ptr CChar -> IO a) -> IO a
withCString ([Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," [[Char]]
locs) ((Ptr CChar -> IO ()) -> IO ()) -> (Ptr CChar -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
lptr ->
(Ptr UErrorCode -> IO ()) -> IO ()
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError (Ptr USpoof -> Ptr CChar -> Ptr UErrorCode -> IO ()
uspoof_setAllowedLocales Ptr USpoof
sptr Ptr CChar
lptr)
areConfusable :: MSpoof -> Text -> Text -> IO SpoofCheckResult
areConfusable :: MSpoof -> Text -> Text -> IO SpoofCheckResult
areConfusable MSpoof
s Text
t1 Text
t2 = MSpoof
-> (Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult)
-> (Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
Text
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a. Text -> (Ptr Word8 -> I8 -> IO a) -> IO a
useAsPtr Text
t1 ((Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult)
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
t1ptr I8
t1len ->
Text
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a. Text -> (Ptr Word8 -> I8 -> IO a) -> IO a
useAsPtr Text
t2 ((Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult)
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
t2ptr I8
t2len ->
Int32 -> SpoofCheckResult
makeSpoofCheckResult (Int32 -> SpoofCheckResult) -> IO Int32 -> IO SpoofCheckResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Ptr UErrorCode -> IO Int32) -> IO Int32
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError (
{-# LINE 374 "Data/Text/ICU/Spoof.hsc" #-}
Ptr USpoof
-> Ptr Word8
-> Int32
-> Ptr Word8
-> Int32
-> Ptr UErrorCode
-> IO Int32
uspoof_areConfusableUTF8
{-# LINE 378 "Data/Text/ICU/Spoof.hsc" #-}
Ptr USpoof
sptr Ptr Word8
t1ptr (I8 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral I8
t1len) Ptr Word8
t2ptr (I8 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral I8
t2len))
getSkeleton :: MSpoof -> Maybe SkeletonTypeOverride -> Text -> IO Text
getSkeleton :: MSpoof -> Maybe SkeletonTypeOverride -> Text -> IO Text
getSkeleton MSpoof
s Maybe SkeletonTypeOverride
o Text
t = MSpoof -> (Ptr USpoof -> IO Text) -> IO Text
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO Text) -> IO Text)
-> (Ptr USpoof -> IO Text) -> IO Text
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
Text -> (Ptr Word8 -> I8 -> IO Text) -> IO Text
forall a. Text -> (Ptr Word8 -> I8 -> IO a) -> IO a
useAsPtr Text
t ((Ptr Word8 -> I8 -> IO Text) -> IO Text)
-> (Ptr Word8 -> I8 -> IO Text) -> IO Text
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
tptr I8
tlen ->
Int
-> (Ptr Word8 -> Int32 -> Ptr UErrorCode -> IO Int32)
-> (Ptr Word8 -> Int -> IO Text)
-> IO Text
forall a b.
Storable a =>
Int
-> (Ptr a -> Int32 -> Ptr UErrorCode -> IO Int32)
-> (Ptr a -> Int -> IO b)
-> IO b
handleOverflowError (I8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral I8
tlen)
(\Ptr Word8
dptr Int32
dlen ->
Ptr USpoof
-> Int32
-> Ptr Word8
-> Int32
-> Ptr Word8
-> Int32
-> Ptr UErrorCode
-> IO Int32
getS Ptr USpoof
sptr Int32
oflags Ptr Word8
tptr (I8 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral I8
tlen) Ptr Word8
dptr (Int32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
dlen))
(\Ptr Word8
dptr Int
dlen -> Ptr Word8 -> I8 -> IO Text
from Ptr Word8
dptr (Int -> I8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
dlen))
where oflags :: Int32
oflags = Int32
-> (SkeletonTypeOverride -> Int32)
-> Maybe SkeletonTypeOverride
-> Int32
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int32
0 (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int32)
-> (SkeletonTypeOverride -> Int) -> SkeletonTypeOverride -> Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SkeletonTypeOverride -> Int
forall a. ToBitMask a => a -> Int
toBitMask) Maybe SkeletonTypeOverride
o
(Ptr USpoof
-> Int32
-> Ptr Word8
-> Int32
-> Ptr Word8
-> Int32
-> Ptr UErrorCode
-> IO Int32
getS, Ptr Word8 -> I8 -> IO Text
from) =
{-# LINE 406 "Data/Text/ICU/Spoof.hsc" #-}
(Ptr USpoof
-> Int32
-> Ptr Word8
-> Int32
-> Ptr Word8
-> Int32
-> Ptr UErrorCode
-> IO Int32
uspoof_getSkeletonUTF8, Ptr Word8 -> I8 -> IO Text
fromPtr)
{-# LINE 410 "Data/Text/ICU/Spoof.hsc" #-}
spoofCheck :: MSpoof -> Text -> IO SpoofCheckResult
spoofCheck :: MSpoof -> Text -> IO SpoofCheckResult
spoofCheck MSpoof
s Text
t = MSpoof
-> (Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult)
-> (Ptr USpoof -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
Text
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a. Text -> (Ptr Word8 -> I8 -> IO a) -> IO a
useAsPtr Text
t ((Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult)
-> (Ptr Word8 -> I8 -> IO SpoofCheckResult) -> IO SpoofCheckResult
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
tptr I8
tlen ->
Int32 -> SpoofCheckResult
makeSpoofCheckResult (Int32 -> SpoofCheckResult) -> IO Int32 -> IO SpoofCheckResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr UErrorCode -> IO Int32) -> IO Int32
forall a. (Ptr UErrorCode -> IO a) -> IO a
handleError
(
{-# LINE 417 "Data/Text/ICU/Spoof.hsc" #-}
uspoof_checkUTF8
{-# LINE 421 "Data/Text/ICU/Spoof.hsc" #-}
sptr tptr (fromIntegral tlen) nullPtr)
serialize :: MSpoof -> IO ByteString
serialize :: MSpoof -> IO ByteString
serialize MSpoof
s = MSpoof -> (Ptr USpoof -> IO ByteString) -> IO ByteString
forall a. MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof MSpoof
s ((Ptr USpoof -> IO ByteString) -> IO ByteString)
-> (Ptr USpoof -> IO ByteString) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ \Ptr USpoof
sptr ->
Int
-> (Ptr Word8 -> Int32 -> Ptr UErrorCode -> IO Int32)
-> (Ptr Word8 -> Int -> IO ByteString)
-> IO ByteString
forall a b.
Storable a =>
Int
-> (Ptr a -> Int32 -> Ptr UErrorCode -> IO Int32)
-> (Ptr a -> Int -> IO b)
-> IO b
handleOverflowError Int
0
(\Ptr Word8
dptr Int32
dlen -> (Ptr USpoof -> Ptr Word8 -> Int32 -> Ptr UErrorCode -> IO Int32
uspoof_serialize Ptr USpoof
sptr Ptr Word8
dptr (Int32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
dlen)))
(\Ptr Word8
dptr Int
dlen -> Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
dlen) ((Ptr Word8 -> IO ()) -> IO ByteString)
-> (Ptr Word8 -> IO ()) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
bptr ->
Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
dptr Ptr Word8
bptr (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
dlen))
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_open" uspoof_open
:: Ptr UErrorCode -> IO (Ptr USpoof)
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_openFromSerialized"
uspoof_openFromSerialized
:: Ptr Word8 -> Int32 -> Ptr Int32 -> Ptr UErrorCode -> IO (Ptr USpoof)
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_openFromSource"
uspoof_openFromSource
:: CString -> Int32 -> CString -> Int32 -> Ptr Int32 -> Ptr UParseError ->
Ptr UErrorCode -> IO (Ptr USpoof)
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_getChecks"
uspoof_getChecks
:: Ptr USpoof -> Ptr UErrorCode -> IO USpoofCheck
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_setChecks"
uspoof_setChecks
:: Ptr USpoof -> USpoofCheck -> Ptr UErrorCode -> IO ()
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_getRestrictionLevel"
uspoof_getRestrictionLevel
:: Ptr USpoof -> IO URestrictionLevel
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_setRestrictionLevel"
uspoof_setRestrictionLevel
:: Ptr USpoof -> URestrictionLevel -> IO ()
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_getAllowedLocales"
uspoof_getAllowedLocales
:: Ptr USpoof -> Ptr UErrorCode -> IO CString
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_setAllowedLocales"
uspoof_setAllowedLocales
:: Ptr USpoof -> CString -> Ptr UErrorCode -> IO ()
{-# LINE 472 "Data/Text/ICU/Spoof.hsc" #-}
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_areConfusableUTF8"
uspoof_areConfusableUTF8
:: Ptr USpoof -> Ptr Word8 -> Int32 -> Ptr Word8 -> Int32 -> Ptr UErrorCode
-> IO USpoofCheck
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_checkUTF8" uspoof_checkUTF8
:: Ptr USpoof -> Ptr Word8 -> Int32 -> Ptr Int32 -> Ptr UErrorCode
-> IO USpoofCheck
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_getSkeletonUTF8"
uspoof_getSkeletonUTF8
:: Ptr USpoof -> USkeletonTypeOverride -> Ptr Word8 -> Int32 -> Ptr Word8 ->
Int32 -> Ptr UErrorCode -> IO Int32
{-# LINE 504 "Data/Text/ICU/Spoof.hsc" #-}
foreign import ccall unsafe "hs_text_icu.h __hs_uspoof_serialize"
uspoof_serialize
:: Ptr USpoof -> Ptr Word8 -> Int32 -> Ptr UErrorCode -> IO Int32