{-# LANGUAGE ForeignFunctionInterface #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Text.ICU.Iterator
(
CharIterator
, fromString
, fromText
, fromUtf8
) where
import Data.ByteString (ByteString)
import Data.Int (Int32)
import Data.Text (Text, pack)
import Data.Text.ICU.Internal (CharIterator(..), UCharIterator, asOrdering,
withCharIterator)
import Foreign.Ptr (Ptr)
import System.IO.Unsafe (unsafePerformIO)
instance Eq CharIterator where
a == b = compareIter a b == EQ
instance Ord CharIterator where
compare = compareIter
compareIter :: CharIterator -> CharIterator -> Ordering
compareIter a b = unsafePerformIO . fmap asOrdering .
withCharIterator a $ withCharIterator b . u_strCompareIter
fromString :: String -> CharIterator
fromString = CIText . pack
{-# INLINE fromString #-}
fromText :: Text -> CharIterator
fromText = CIText
{-# INLINE fromText #-}
fromUtf8 :: ByteString -> CharIterator
fromUtf8 = CIUTF8
{-# INLINE fromUtf8 #-}
foreign import ccall unsafe "hs_text_icu.h __hs_u_strCompareIter" u_strCompareIter
:: Ptr UCharIterator -> Ptr UCharIterator -> IO Int32