on master help sign in
Fix the extract function of parseCharUtf8WithD
7da8c79Adithya Kumar
src/Streamly/Internal/Unicode/Stream.hs+11−3
@@ -81,7 +81,7 @@ where
81
81
82#include "inline.hs"
82#include "inline.hs"
83
83
84−import Control.Monad.Catch (MonadThrow, MonadCatch)
84+import Control.Monad.Catch (MonadThrow(..), MonadCatch)
85import Control.Monad.IO.Class (MonadIO, liftIO)
85import Control.Monad.IO.Class (MonadIO, liftIO)
86import Data.Bits (shiftR, shiftL, (.|.), (.&.))
86import Data.Bits (shiftR, shiftL, (.|.), (.&.))
87import Data.Char (chr, ord)
87import Data.Char (chr, ord)
@@ -435,7 +435,7 @@ data UTF8CharDecodeState a
435
435
436{-# INLINE parseCharUtf8WithD #-}
436{-# INLINE parseCharUtf8WithD #-}
437parseCharUtf8WithD ::
437parseCharUtf8WithD ::
438− Monad m => CodingFailureMode -> ParserD.Parser m Word8 Char
438+ MonadThrow m => CodingFailureMode -> ParserD.Parser m Word8 Char
439parseCharUtf8WithD cfm =
439parseCharUtf8WithD cfm =
440 let A.Array _ ptr _ = utf8d
440 let A.Array _ ptr _ = utf8d
441 in ParserD.Parser (step' ptr) initial extract
441 in ParserD.Parser (step' ptr) initial extract
@@ -494,7 +494,15 @@ parseCharUtf8WithD cfm =
494 _ -> ParserD.Continue 0 (UTF8CharDecoding sv cp)
494 _ -> ParserD.Continue 0 (UTF8CharDecoding sv cp)
495
495
496 {-# INLINE extract #-}
496 {-# INLINE extract #-}
497+ extract UTF8CharDecodeInit = error $ prefix ++ "Not enough input"
498+ extract (UTF8CharDecoding _ _) =
499+ case cfm of
500+ ErrorOnCodingFailure ->
501+ throwM $ ParserD.ParseError $ prefix ++ "Not enough input"
502+ TransliterateCodingFailure -> return replacementChar
503+ -- XXX We shouldn't error out here. There is no way to represent an
504+ -- empty parser result unless we return a "Maybe" type.
497− extract _ = error $ prefix ++ "Not enough input"
505+ DropOnCodingFailure -> error $ prefix ++ "Not enough input"
498
506
499-- XXX This should ideally accept a "CodingFailureMode" and perform appropriate
507-- XXX This should ideally accept a "CodingFailureMode" and perform appropriate
500-- error handling. This isn't possible now as "TransliterateCodingFailure"'s
508-- error handling. This isn't possible now as "TransliterateCodingFailure"'s