@@ -36,6 +36,9 @@ import Data.Word (Word8)
36import GHC.Conc (numCapabilities)
36import GHC.Conc (numCapabilities)
37import System.Environment (getArgs)
37import System.Environment (getArgs)
38import System.IO (Handle, openFile, IOMode(..))
38import System.IO (Handle, openFile, IOMode(..))
39+import Streamly.Internal.Data.Unicode.Stream
40+ (DecodeState, DecodeError(..), CodePoint, decodeUtf8Either,
41+ resumeDecodeUtf8Either)
40import qualified Streamly as S
43import qualified Streamly as S
41import qualified Streamly.Data.Unicode.Stream as S
44import qualified Streamly.Data.Unicode.Stream as S
@@ -239,7 +242,7 @@ resetHeaderOnNewChar counts = do
239-- Manipulating the trailer
242-- Manipulating the trailer
240-------------------------------------------------------------------------------
243-------------------------------------------------------------------------------
242−setTrailer :: V.IOVector Int -> S.DecodeState -> S.CodePoint -> IO ()
245+setTrailer :: V.IOVector Int -> DecodeState -> CodePoint -> IO ()
243setTrailer counts st cp = do
246setTrailer counts st cp = do
244 writeField counts TrailerState (fromIntegral st)
247 writeField counts TrailerState (fromIntegral st)
245 writeField counts TrailerCodePoint cp
248 writeField counts TrailerCodePoint cp
@@ -257,7 +260,7 @@ resetTrailerOnNewChar counts = do
257-------------------------------------------------------------------------------
260-------------------------------------------------------------------------------
259{-# INLINE countChar #-}
262{-# INLINE countChar #-}
260−countChar :: V.IOVector Int -> Either S.DecodeError Char -> IO ()
263+countChar :: V.IOVector Int -> Either DecodeError Char -> IO ()
261countChar counts inp =
264countChar counts inp =
262 case inp of
265 case inp of
263 Right ch -> do
266 Right ch -> do
@@ -272,7 +275,7 @@ countChar counts inp =
272 wasSpace <- readField counts WasSpace
275 wasSpace <- readField counts WasSpace
273 when (wasSpace /= 0) $ modifyField counts WordCount (+ 1)
276 when (wasSpace /= 0) $ modifyField counts WordCount (+ 1)
274 accountChar counts False
277 accountChar counts False
275− Left (S.DecodeError st cp) -> do
278+ Left (DecodeError st cp) -> do
276 hdone <- readField counts HeaderDone
279 hdone <- readField counts HeaderDone
277 if hdone == 0
280 if hdone == 0
@@ -309,7 +312,7 @@ _wc_mwl_parserial :: Handle -> IO (V.IOVector Int)
309_wc_mwl_parserial src = do
312_wc_mwl_parserial src = do
310 counts <- newCounts
313 counts <- newCounts
311 S.mapM_ (countChar counts)
314 S.mapM_ (countChar counts)
312− $ S.decodeUtf8Either
315+ $ decodeUtf8Either
313 $ S.unfold FH.read src
316 $ S.unfold FH.read src
314 return counts
317 return counts
@@ -348,7 +351,7 @@ _wc_mwl_serial src = print =<< (
348reconstructChar :: Int
351reconstructChar :: Int
349 -> V.IOVector Int
352 -> V.IOVector Int
350 -> V.IOVector Int
353 -> V.IOVector Int
351− -> IO (S.SerialT IO (Either S.DecodeError Char))
354+ -> IO (S.SerialT IO (Either DecodeError Char))
352reconstructChar hdrCnt v1 v2 = do
355reconstructChar hdrCnt v1 v2 = do
353 when (hdrCnt > 3 || hdrCnt < 0) $ error "reconstructChar: hdrCnt > 3"
356 when (hdrCnt > 3 || hdrCnt < 0) $ error "reconstructChar: hdrCnt > 3"
354 stream1 <-
357 stream1 <-
@@ -372,7 +375,7 @@ reconstructChar hdrCnt v1 v2 = do
373 state <- readField v1 TrailerState
376 state <- readField v1 TrailerState
374 cp <- readField v1 TrailerCodePoint
377 cp <- readField v1 TrailerCodePoint
375− return $ S.resumeDecodeUtf8Either (fromIntegral state) cp stream3
378+ return $ resumeDecodeUtf8Either (fromIntegral state) cp stream3
377getHdrChar :: V.IOVector Int -> IO (Maybe Int)
380getHdrChar :: V.IOVector Int -> IO (Maybe Int)
378getHdrChar v = do
381getHdrChar v = do
@@ -543,7 +546,7 @@ addCounts v1 v2 = do
543 writeField v1 TrailerState trailerState2
546 writeField v1 TrailerState trailerState2
544 writeField v1 TrailerCodePoint trailerCodePoint2
547 writeField v1 TrailerCodePoint trailerCodePoint2
545 return v1
548 return v1
546− Left (S.DecodeError st cp) -> do
549+ Left (DecodeError st cp) -> do
547 -- if header was incomplete it may result
550 -- if header was incomplete it may result
548 -- in partially decoded char to be written
551 -- in partially decoded char to be written
549 -- as trailer. Check if the last error is
552 -- as trailer. Check if the last error is
@@ -554,7 +557,7 @@ addCounts v1 v2 = do
554 Nothing -> (st, cp)
557 Nothing -> (st, cp)
555 Just lst -> case lst of
558 Just lst -> case lst of
556 Right _ -> error "addCounts: Bug"
559 Right _ -> error "addCounts: Bug"
557− Left (S.DecodeError st1 cp1) -> (st1, cp1)
560+ Left (DecodeError st1 cp1) -> (st1, cp1)
558 if hdone2 == 0 && st' /= 12
561 if hdone2 == 0 && st' /= 12
560 -- all elements before the last one must be errors
563 -- all elements before the last one must be errors
@@ -593,7 +596,7 @@ countArray :: A.Array Word8 -> IO (V.IOVector Int)
593countArray src = do
596countArray src = do
594 counts <- newCounts
597 counts <- newCounts
595 S.mapM_ (countChar counts)
598 S.mapM_ (countChar counts)
596− $ S.decodeUtf8Either
599+ $ decodeUtf8Either
597 $ S.unfold A.read src
600 $ S.unfold A.read src
598 return counts
601 return counts