@@ -273,6 +273,25 @@ head :: Text -> Char
273273head t = S.head (stream t)
274274{-# INLINE head #-}
275275
276+-- | Iterate one step through a UTF-16 array, returning the current
277+-- character and the step to add to give the next offset to iterate
278+-- at.
279+iter :: A.Array Word16 -> Int -> (Char,Int)
280+iter arr i | m < 0xD800 || m > 0xDBFF = (unsafeChr m, 1)
281+ | otherwise = (U16.chr2 m n, 2)
282+ where m = A.unsafeIndex arr i
283+ n = A.unsafeIndex arr j
284+ j = i + 1
285+{-# INLINE iter #-}
286+
287+-- | Iterate one step through a UTF-16 array, returning the next
288+-- offset to iterate at.
289+iter_ :: A.Array Word16 -> Int -> Int
290+iter_ arr i | m < 0xD800 || m > 0xDBFF = 1
291+ | otherwise = 2
292+ where m = A.unsafeIndex arr i
293+{-# INLINE iter_ #-}
294+
276295-- | /O(1)/ Returns the first character and rest of a 'Text', or
277296-- 'Nothing' if empty. Subject to array fusion.
278297uncons :: Text -> Maybe (Char, Text)