on master help sign in
Make encoding error messages more uniform

--HG-- extra : convert_revision : dbb68722f57fa7d680e3616841a6ffad3681145b

commit8b0a14be1694eecdba7a74e6e1c8126d929c4cce authorBryan O'Sullivan <bos@serpentine.com> dateMon 23 Feb 2009, 03:31 (18 years ago) parentfd39f6f
1 file changed+9−5
Data/Text/Encoding/Fusion.hs+9−5
Data/Text/Encoding/Fusion.hs+9−5
@@ -82,7 +82,7 @@ streamUtf8 bs = Stream next 0 l
8282 | i+1 < l && U8.validate2 x1 x2 = Yield (U8.chr2 x1 x2) (i+2)
8383 | i+2 < l && U8.validate3 x1 x2 x3 = Yield (U8.chr3 x1 x2 x3) (i+3)
8484 | 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"
8686 where
8787 x1 = idx i
8888 x2 = idx (i + 1)
@@ -100,7 +100,7 @@ streamUtf16LE bs = Stream next 0 l
100100 | i >= l = Done
101101 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
102102 | 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"
104104 where
105105 x1 = (shiftL (idx (i + 1)) 8) + (idx i)
106106 x2 = (shiftL (idx (i + 3)) 8) + (idx (i + 2))
@@ -116,7 +116,7 @@ streamUtf16BE bs = Stream next 0 l
116116 | i >= l = Done
117117 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
118118 | 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"
120120 where
121121 x1 = (shiftL (idx i) 8) + (idx (i + 1))
122122 x2 = (shiftL (idx (i + 2)) 8) + (idx (i + 3))
@@ -131,7 +131,7 @@ streamUtf32BE bs = Stream next 0 l
131131 next i
132132 | i >= l = Done
133133 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
134− | otherwise = error "bsStream: bad UTF-32BE stream"
134+ | otherwise = encodingError "UTF-32BE"
135135 where
136136 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
137137 x1 = idx i
@@ -149,7 +149,7 @@ streamUtf32LE bs = Stream next 0 l
149149 next i
150150 | i >= l = Done
151151 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
152− | otherwise = error "bsStream: bad UTF-32LE stream"
152+ | otherwise = encodingError "UTF-32LE"
153153 where
154154 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
155155 x1 = idx i
@@ -324,3 +324,7 @@ unstream (Stream next s0 len) = unsafePerformIO $ do
324324internalError :: String -> a
325325internalError func =
326326 error $ "Data.Text.Encoding.Fusion." ++ func ++ ": internal error"
327+
328+encodingError :: String -> a
329+encodingError encoding =
330+ error $ "Data.Text.Encoding.Fusion: Bad " ++ encoding ++ " stream"