11{-# OPTIONS_GHC -funbox-strict-fields #-}
22{-# LANGUAGE BangPatterns #-}
3+ {-# LANGUAGE CPP #-}
34{-# LANGUAGE LambdaCase #-}
45{-# LANGUAGE TupleSections #-}
56-- |
@@ -22,21 +23,28 @@ module Data.Unicode.Internal.NormalizeStream
2223 )
2324 where
2425
25- import Data.Bits (shiftR )
2626import Data.Char (chr , ord )
2727import GHC.ST (ST (.. ))
2828import GHC.Types (SPEC (.. ))
2929
3030import qualified Data.Text.Array as A
3131import qualified Unicode.Char as UC
3232
33+ #if MIN_VERSION_text(2,0,0)
34+ import Data.Text.Internal.Fusion (stream )
35+ #else
36+ import Data.Bits (shiftR )
37+ import Data.Text.Internal.Unsafe.Char (unsafeChr )
38+ import Data.Text.Internal.Fusion.Size (betweenSize )
39+ import Data.Text.Internal.Encoding.Utf16 (chr2 )
40+ #endif
41+
3342-- Internal modules
3443import Data.Text.Internal (Text (.. ))
35- import Data.Text.Internal.Fusion.Size (betweenSize , upperBound )
44+ import Data.Text.Internal.Fusion.Size (upperBound )
3645import Data.Text.Internal.Fusion.Types (Step (.. ), Stream (.. ))
3746import Data.Text.Internal.Private (runText )
38- import Data.Text.Internal.Unsafe.Char (unsafeChr , unsafeWrite )
39- import Data.Text.Internal.Encoding.Utf16 (chr2 )
47+ import Data.Text.Internal.Unsafe.Char (unsafeWrite )
4048
4149-------------------------------------------------------------------------------
4250-- Reorder buffer to hold characters till the next starter boundary
@@ -142,6 +150,7 @@ decomposeChar mode marr index reBuf ch
142150 n <- unsafeWrite arr j c
143151 return (j + n, Empty )
144152
153+ #if !MIN_VERSION_text(2,0,0)
145154-- | /O(n)/ Convert a 'Text' into a 'Stream Char'.
146155stream :: Text -> Stream Char
147156stream (Text arr off len) = Stream next off (betweenSize (len `shiftR` 1 ) len)
@@ -158,6 +167,7 @@ stream (Text arr off len) = Stream next off (betweenSize (len `shiftR` 1) len)
158167 n = A. unsafeIndex arr i
159168 n2 = A. unsafeIndex arr (i + 1 )
160169{-# INLINE [0] stream #-}
170+ #endif
161171
162172-- | /O(n)/ Convert a 'Stream Char' into a decompose-normalized 'Text'.
163173unstream :: UC. DecomposeMode -> Stream Char -> Text
0 commit comments