module Data.Text.ICU.Collate.Internal
(
MCollator(..)
, Collator(..)
, UCollator
, equals
, withCollator
, wrap
) where
import Data.Text.ICU.Internal (UBool, asBool)
import Data.Typeable (Typeable)
import Foreign.ForeignPtr (ForeignPtr, newForeignPtr, withForeignPtr)
import Foreign.Ptr (FunPtr, Ptr)
import System.IO.Unsafe (unsafePerformIO)
data UCollator
data MCollator = MCollator !(ForeignPtr UCollator)
deriving (Typeable)
newtype Collator = C MCollator
deriving (Typeable)
instance Eq Collator where
(C a) == (C b) = unsafePerformIO $ equals a b
withCollator :: MCollator -> (Ptr UCollator -> IO a) -> IO a
withCollator (MCollator col) action = withForeignPtr col action
wrap :: Ptr UCollator -> IO MCollator
wrap = fmap MCollator . newForeignPtr ucol_close
equals :: MCollator -> MCollator -> IO Bool
equals a b = fmap asBool .
withCollator a $ \aptr ->
withCollator b $ ucol_equals aptr
foreign import ccall unsafe "hs_text_icu.h &__hs_ucol_close" ucol_close
:: FunPtr (Ptr UCollator -> IO ())
foreign import ccall unsafe "hs_text_icu.h __hs_ucol_equals" ucol_equals
:: Ptr UCollator -> Ptr UCollator -> IO UBool