{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
module DeferredFolds.Util.TextArray where
import Data.Text.Array
import qualified Data.Text.Internal.Encoding.Utf16 as TextUtf16
import qualified Data.Text.Internal.Unsafe.Char as TextChar
import qualified Data.Text.Unsafe as TextUnsafe
import DeferredFolds.Prelude hiding (Array)
#if MIN_VERSION_text(2,0,0)
{-# INLINE iter #-}
iter :: Array -> Int -> (Char -> Int -> a) -> a
iter arr offset cont =
let TextUnsafe.Iter c d = TextUnsafe.iterArray arr offset in cont c (offset + d)
#else
{-# INLINE iter #-}
iter :: Array -> Int -> (Char -> Int -> a) -> a
iter :: forall a. Array -> Int -> (Char -> Int -> a) -> a
iter Array
arr Int
offset Char -> Int -> a
cont =
let b1 :: Word16
b1 =
Array -> Int -> Word16
unsafeIndex Array
arr Int
offset
in if Word16
b1 forall a. Ord a => a -> a -> Bool
>= Word16
0xd800 Bool -> Bool -> Bool
&& Word16
b1 forall a. Ord a => a -> a -> Bool
<= Word16
0xdbff
then
let b2 :: Word16
b2 =
Array -> Int -> Word16
unsafeIndex Array
arr (forall a. Enum a => a -> a
succ Int
offset)
char :: Char
char =
Word16 -> Word16 -> Char
TextUtf16.chr2 Word16
b1 Word16
b2
in Char -> Int -> a
cont Char
char (Int
offset forall a. Num a => a -> a -> a
+ Int
2)
else Char -> Int -> a
cont (Word16 -> Char
TextChar.unsafeChr Word16
b1) (Int
offset forall a. Num a => a -> a -> a
+ Int
1)
#endif