@@ -82,7 +82,7 @@ streamUtf8 bs = Stream next 0 l
82 | i+1 < l && U8.validate2 x1 x2 = Yield (U8.chr2 x1 x2) (i+2)
82 | i+1 < l && U8.validate2 x1 x2 = Yield (U8.chr2 x1 x2) (i+2)
83 | i+2 < l && U8.validate3 x1 x2 x3 = Yield (U8.chr3 x1 x2 x3) (i+3)
83 | i+2 < l && U8.validate3 x1 x2 x3 = Yield (U8.chr3 x1 x2 x3) (i+3)
84 | i+3 < l && U8.validate4 x1 x2 x3 x4 = Yield (U8.chr4 x1 x2 x3 x4) (i+4)
84 | i+3 < l && U8.validate4 x1 x2 x3 x4 = Yield (U8.chr4 x1 x2 x3 x4) (i+4)
85− | otherwise = error "bsStream: bad UTF-8 stream"
85+ | otherwise = encodingError "UTF-8"
87 x1 = idx i
87 x1 = idx i
88 x2 = idx (i + 1)
88 x2 = idx (i + 1)
@@ -100,7 +100,7 @@ streamUtf16LE bs = Stream next 0 l
100 | i >= l = Done
100 | i >= l = Done
101 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
101 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
102 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
102 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
103− | otherwise = error $ "bsStream: bad UTF-16LE stream"
103+ | otherwise = encodingError "UTF-16LE"
105 x1 = (shiftL (idx (i + 1)) 8) + (idx i)
105 x1 = (shiftL (idx (i + 1)) 8) + (idx i)
106 x2 = (shiftL (idx (i + 3)) 8) + (idx (i + 2))
106 x2 = (shiftL (idx (i + 3)) 8) + (idx (i + 2))
@@ -116,7 +116,7 @@ streamUtf16BE bs = Stream next 0 l
116 | i >= l = Done
116 | i >= l = Done
117 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
117 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
118 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
118 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
119− | otherwise = error $ "bsStream: bad UTF16-BE stream "
119+ | otherwise = encodingError "UTF16-BE"
121 x1 = (shiftL (idx i) 8) + (idx (i + 1))
121 x1 = (shiftL (idx i) 8) + (idx (i + 1))
122 x2 = (shiftL (idx (i + 2)) 8) + (idx (i + 3))
122 x2 = (shiftL (idx (i + 2)) 8) + (idx (i + 3))
@@ -131,7 +131,7 @@ streamUtf32BE bs = Stream next 0 l
132 | i >= l = Done
132 | i >= l = Done
133 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
133 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
134− | otherwise = error "bsStream: bad UTF-32BE stream"
134+ | otherwise = encodingError "UTF-32BE"
136 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
136 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
137 x1 = idx i
137 x1 = idx i
@@ -149,7 +149,7 @@ streamUtf32LE bs = Stream next 0 l
150 | i >= l = Done
150 | i >= l = Done
151 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
151 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
152− | otherwise = error "bsStream: bad UTF-32LE stream"
152+ | otherwise = encodingError "UTF-32LE"
154 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
154 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
155 x1 = idx i
155 x1 = idx i
@@ -324,3 +324,7 @@ unstream (Stream next s0 len) = unsafePerformIO $ do
324internalError :: String -> a
324internalError :: String -> a
325internalError func =
325internalError func =
326 error $ "Data.Text.Encoding.Fusion." ++ func ++ ": internal error"
326 error $ "Data.Text.Encoding.Fusion." ++ func ++ ": internal error"
328+encodingError :: String -> a
329+encodingError encoding =
330+ error $ "Data.Text.Encoding.Fusion: Bad " ++ encoding ++ " stream"