@@ -123,17 +123,18 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = compare (next1 s1) (next2 s2)
124-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
124-- | /O(n) Convert a ByteString into a Stream Char, using the specified encoding standard.
125stream_bs :: Encoding -> ByteString -> Stream Char
125stream_bs :: Encoding -> ByteString -> Stream Char
126−stream_bs ASCII bs = Stream next 0 (B.length bs)
126+stream_bs ASCII bs = Stream next 0 l
128 {-# INLINE next #-}
129 {-# INLINE next #-}
130 | i >= l = Done
131 | i >= l = Done
131 | otherwise = Yield (unsafeChr8 x1) (i+1)
132 | otherwise = Yield (unsafeChr8 x1) (i+1)
134 x1 = B.unsafeIndex bs i
134 x1 = B.unsafeIndex bs i
135−stream_bs Utf8 bs = Stream next 0 (B.length bs)
135+stream_bs Utf8 bs = Stream next 0 l
137 {-# INLINE next #-}
138 {-# INLINE next #-}
139 | i >= l = Done
140 | i >= l = Done
@@ -143,14 +144,14 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
143 | i+3 < l && U8.validate4 x1 x2 x3 x4 = Yield (U8.chr4 x1 x2 x3 x4) (i+4)
144 | i+3 < l && U8.validate4 x1 x2 x3 x4 = Yield (U8.chr4 x1 x2 x3 x4) (i+4)
144 | otherwise = error "bsStream: bad UTF-8 stream"
145 | otherwise = error "bsStream: bad UTF-8 stream"
147 x1 = index i
147 x1 = index i
148 x2 = index (i + 1)
148 x2 = index (i + 1)
149 x3 = index (i + 2)
149 x3 = index (i + 2)
150 x4 = index (i + 3)
150 x4 = index (i + 3)
151 index = B.unsafeIndex bs
151 index = B.unsafeIndex bs
152−stream_bs Utf16LE bs = Stream next 0 (B.length bs)
152+stream_bs Utf16LE bs = Stream next 0 l
154 {-# INLINE next #-}
155 {-# INLINE next #-}
156 | i >= l = Done
157 | i >= l = Done
@@ -162,10 +163,10 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
162 x1 = (shiftL (index (i + 1)) 8) + (index i)
163 x1 = (shiftL (index (i + 1)) 8) + (index i)
163 x2 :: Word16
164 x2 :: Word16
164 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
165 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
166 index = fromIntegral . B.unsafeIndex bs :: Int -> Word16
166 index = fromIntegral . B.unsafeIndex bs :: Int -> Word16
167−stream_bs Utf16BE bs = Stream next 0 (B.length bs)
167+stream_bs Utf16BE bs = Stream next 0 l
169 {-# INLINE next #-}
170 {-# INLINE next #-}
171 | i >= l = Done
172 | i >= l = Done
@@ -177,32 +178,31 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
177 x1 = (shiftL (index i) 8) + (index (i + 1))
178 x1 = (shiftL (index i) 8) + (index (i + 1))
178 x2 :: Word16
179 x2 :: Word16
179 x2 = (shiftL (index (i + 2)) 8) + (index (i + 3))
180 x2 = (shiftL (index (i + 2)) 8) + (index (i + 3))
181 index = fromIntegral . B.unsafeIndex bs
181 index = fromIntegral . B.unsafeIndex bs
182−stream_bs Utf32BE bs = Stream next 0 (B.length bs)
182+stream_bs Utf32BE bs = Stream next 0 l
184 {-# INLINE next #-}
185 {-# INLINE next #-}
186 | i >= l = Done
187 | i >= l = Done
187 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
188 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
188 | otherwise = error "bsStream: bad UTF-32BE stream"
189 | otherwise = error "bsStream: bad UTF-32BE stream"
191 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
191 x = shiftL x1 24 + shiftL x2 16 + shiftL x3 8 + x4
192 x1 = index i
192 x1 = index i
193 x2 = index (i+1)
193 x2 = index (i+1)
194 x3 = index (i+2)
194 x3 = index (i+2)
195 x4 = index (i+3)
195 x4 = index (i+3)
196 index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
196 index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
197−stream_bs Utf32LE bs = Stream next 0 (B.length bs)
197+stream_bs Utf32LE bs = Stream next 0 l
199 {-# INLINE next #-}
200 {-# INLINE next #-}
201 | i >= l = Done
202 | i >= l = Done
202 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
203 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
203 | otherwise = error "bsStream: bad UTF-32LE stream"
204 | otherwise = error "bsStream: bad UTF-32LE stream"
206 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
206 x = shiftL x4 24 + shiftL x3 16 + shiftL x2 8 + x1
207 x1 = index i
207 x1 = index i
208 x2 = index $ i+1
208 x2 = index $ i+1