@@ -34,10 +34,7 @@ module Data.Text.Encoding.Fusion
3434#if defined(ASSERTS)
3535import Control.Exception (assert)
3636#endif
37−import Data.Bits ((.&.), (.|.))
3837import Data.ByteString.Internal (ByteString(..), mallocByteString, memcpy)
39−import Control.Monad.ST
40−import Data.Text.Array
4138import Data.Text.Fusion (Step(..), Stream(..))
4239import Data.Text.Fusion.Size
4340import Data.Text.Encoding.Error
@@ -68,8 +65,8 @@ streamASCII bs = Stream next 0 (maxSize l)
6865
6966-- | /O(n)/ Convert a 'ByteString' into a 'Stream Char', using UTF-8
7067-- encoding.
71−streamUtf8' :: OnDecodeError -> ByteString -> Stream Char
72−streamUtf8' onErr bs = Stream next 0 (maxSize l)
68+streamUtf8 :: OnDecodeError -> ByteString -> Stream Char
69+streamUtf8 onErr bs = Stream next 0 (maxSize l)
7370 where
7471 l = B.length bs
7572 next i
@@ -87,33 +84,6 @@ streamUtf8' onErr bs = Stream next 0 (maxSize l)
8784 idx = B.unsafeIndex bs
8885{-# INLINE [0] streamUtf8 #-}
8986
90−accept, reject :: Word32
91−accept = 0
92−reject = 12
93−
94−data S8 = S8 {-# UNPACK #-} !Word32 {-# UNPACK #-} !Int {-# UNPACK #-} !Word32
95−
96−streamUtf8 :: OnDecodeError -> ByteString -> Stream Char
97−streamUtf8 onErr bs = Stream next (S8 accept 0 0) (maxSize l)
98− where
99− l = B.length bs
100− next (S8 state i code)
101− | i >= l = Done
102− | state' == accept = Yield (unsafeChr32 code') (s' accept)
103− | state' /= reject = Skip (s' state')
104− | otherwise = decodeError "streamUtf8" "UTF-8" onErr
105− (Just byte) (s' accept)
106− where s' s = S8 s (i+1) code'
107− byte = B.unsafeIndex bs i
108− word = fromIntegral byte
109− peeku :: Int -> Word32
110− peeku n = fromIntegral (unsafeIndexWord8 utf8d n)
111− !kind = peeku (fromIntegral word)
112− !code' | state /= accept = (word .&. 0x3f) .|. (code `shiftL` 6)
113− | otherwise = (0xff `shiftR` fromIntegral kind) .&. word
114− !state' = peeku (256 + fromIntegral (state + kind))
115−
116−
11787-- | /O(n)/ Convert a 'ByteString' into a 'Stream Char', using little
11888-- endian UTF-16 encoding.
11989streamUtf16LE :: OnDecodeError -> ByteString -> Stream Char
@@ -232,18 +202,3 @@ decodeError func kind onErr mb i =
232202 Just c -> Yield c i
233203 where desc = "Data.Text.Encoding.Fusion." ++ func ++ ": Invalid " ++
234204 kind ++ " stream"
235−
236−utf8d :: Array
237−{-# NOINLINE utf8d #-}
238−utf8d = runST fill where
239− fill = do
240− ary <- unsafeNew . (`div` 2) . sum . map fst $ xs
241− mapM_ (uncurry (unsafeWriteWord8 ary))
242− (zip [0..] (concatMap (uncurry replicate) xs))
243− unsafeFreeze ary
244− xs = [(128,0),(16,1),(16,9),(32,7),(2,8),(30,2),(1,10),(12,3),(1,4),(2,3),
245− (1,11),(3,6),(1,5),(11,8),(1,0),(1,12),(1,24),(1,36),(1,60),(1,96),
246− (1,84),(3,12),(1,48),(1,72),(13,12),(1,0),(5,12),(1,0),(1,12),(1,0),
247− (3,12),(1,24),(5,12),(1,24),(1,12),(1,24),(9,12),(1,24),(5,12),(1,24),
248− (7,12),(1,24),(9,12),(1,36),(1,12),(1,36),(3,12),(1,36),(5,12),(1,36),
249− (1,12),(1,36),(3,12),(1,36),(10,12)]