@@ -22,14 +22,12 @@ module Data.Text.Encoding
22 -- * Decoding ByteStrings to Text
22 -- * Decoding ByteStrings to Text
23 decodeASCII
23 decodeASCII
24 , decodeUtf8
24 , decodeUtf8
26 , decodeUtf16LE
25 , decodeUtf16LE
27 , decodeUtf16BE
26 , decodeUtf16BE
28 , decodeUtf32LE
27 , decodeUtf32LE
29 , decodeUtf32BE
28 , decodeUtf32BE
30 -- ** Controllable error handling
29 -- ** Controllable error handling
31 , decodeUtf8With
30 , decodeUtf8With
33 , decodeUtf16LEWith
31 , decodeUtf16LEWith
34 , decodeUtf16BEWith
32 , decodeUtf16BEWith
35 , decodeUtf32LEWith
33 , decodeUtf32LEWith
@@ -67,18 +65,8 @@ decodeASCII :: ByteString -> Text
67decodeASCII bs = F.unstream (E.streamASCII bs)
65decodeASCII bs = F.unstream (E.streamASCII bs)
68{-# INLINE decodeASCII #-}
66{-# INLINE decodeASCII #-}
70−-- | Decode a 'ByteString' containing UTF-8 encoded text.
71decodeUtf8With :: OnDecodeError -> ByteString -> Text
68decodeUtf8With :: OnDecodeError -> ByteString -> Text
72−decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
69+decodeUtf8With onErr bs = textP (fst a) 0 (snd a)
73−{-# INLINE decodeUtf8With #-}
75−-- | Decode a 'ByteString' containing UTF-8 encoded text.
76−decodeUtf8 :: ByteString -> Text
77−decodeUtf8 = decodeUtf8With strictDecode
78−{-# INLINE decodeUtf8 #-}
80−decodeUtf8With' :: OnDecodeError -> ByteString -> Text
81−decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
83 a = A.run2 (A.new len >>= outer 0 0)
71 a = A.run2 (A.new len >>= outer 0 0)
84 len = B.length bs
72 len = B.length bs
@@ -109,16 +97,16 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
109 Just c -> do
97 Just c -> do
110 w <- unsafeWrite arr n c
98 w <- unsafeWrite arr n c
111 go (n+w) (m+1)
99 go (n+w) (m+1)
112− desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
100+ desc = "Data.Text.Encoding.decodeUtf8: Invalid UTF-8 stream"
113−{-# INLINE[0] decodeUtf8With' #-}
101+{-# INLINE[0] decodeUtf8With #-}
115-- | Decode a 'ByteString' containing UTF-8 encoded text.
103-- | Decode a 'ByteString' containing UTF-8 encoded text.
116−decodeUtf8' :: ByteString -> Text
104+decodeUtf8 :: ByteString -> Text
117−decodeUtf8' = decodeUtf8With' strictDecode
105+decodeUtf8 = decodeUtf8With strictDecode
118−{-# INLINE[0] decodeUtf8' #-}
106+{-# INLINE[0] decodeUtf8 #-}
120−{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
108+{-# RULES "STREAM stream/decodeUtf8 fusion" [1]
121− forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
109+ forall bs. F.stream (decodeUtf8 bs) = E.streamUtf8 strictDecode bs #-}
123-- | Encode text using UTF-8 encoding.
111-- | Encode text using UTF-8 encoding.
124encodeUtf8 :: Text -> ByteString
112encodeUtf8 :: Text -> ByteString