on master help sign in
Clean up whitespace

--HG-- extra : convert_revision : 22d5179424b6584165db6bf43806aa3ab40b911d

commitc237bb7cd1954375ebdb268d3396f019c748c4e5 authorDuncan Coutts <duncan@haskell.org> dateSun 18 Jan 2009, 17:06 (18 years ago) parent25e38d8
4 files changed+129−129
Text.hs+43−43 Text/Fusion.hs+72−72 Text/Internal.hs+3−3 Text/Utf8.hs+11−11
Text.hs+43−43
@@ -43,16 +43,16 @@ instance Monoid Text where
4343 mempty = empty
4444 mappend = append
4545 mconcat = concat
46−
4746
48−
47+
48+
4949-- -----------------------------------------------------------------------------
5050-- * Conversion to/from 'Text'
5151
5252-- | /O(n)/ Convert a String into a Text.
5353--
54−-- This function is subject to array fusion, so calling other fusible
55−-- function(s) on a packed string will only cause one 'Text' to be written
54+-- This function is subject to array fusion, so calling other fusible
55+-- function(s) on a packed string will only cause one 'Text' to be written
5656-- out at the end of the pipeline, instead of one before and one after.
5757pack :: String -> Text
5858pack str = (unstream (stream_list str))
@@ -62,7 +62,7 @@ pack str = (unstream (stream_list str))
6262 next [] = S.Done
6363 next (x:xs) = S.Yield x xs
6464{-# INLINE [1] pack #-}
65−-- TODO: Has to do validation! -- No, it doesn't, the
65+-- TODO: Has to do validation! -- No, it doesn't, the
6666
6767-- | /O(n)/ Convert a Text into a String.
6868-- Subject to array fusion.
@@ -92,32 +92,32 @@ decode enc bs = unstream (stream_bs enc bs)
9292{-# INLINE decode #-}
9393
9494encode :: Encoding -> Text -> ByteString
95−encode enc txt = unstream_bs (restream enc (stream txt))
95+encode enc txt = unstream_bs (restream enc (stream txt))
9696{-# INLINE encode #-}
9797
9898-- -----------------------------------------------------------------------------
9999-- * Basic functions
100100
101−-- | /O(n)/ Adds a character to the front of a 'Text'. This function is more
101+-- | /O(n)/ Adds a character to the front of a 'Text'. This function is more
102102-- costly than its 'List' counterpart because it requires copying a new array.
103103-- Subject to array fusion.
104104cons :: Char -> Text -> Text
105105cons c t = unstream (S.cons c (stream t))
106106{-# INLINE cons #-}
107107
108−-- | /O(n)/ Adds a character to the end of a 'Text'. This copies the entire
108+-- | /O(n)/ Adds a character to the end of a 'Text'. This copies the entire
109109-- array in the process.
110110-- Subject to array fusion.
111111snoc :: Text -> Char -> Text
112112snoc t c = unstream (S.snoc (stream t) c)
113113{-# INLINE snoc #-}
114114
115−-- | /O(n)/ Appends one Text to the other by copying both of them into a new
116−-- Text.
115+-- | /O(n)/ Appends one Text to the other by copying both of them into a new
116+-- Text.
117117-- Subject to array fusion
118118append :: Text -> Text -> Text
119119append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
120− where
120+ where
121121 len = len1+len2
122122 x = do
123123 arr <- unsafeNewArray_ (0,len-1) :: ST s (STUArray s Int Word16)
@@ -126,13 +126,13 @@ append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
126126 return arr
127127 where
128128 copy arr i max arr' j
129− | i >= max = return ()
130− | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)
129+ | i >= max = return ()
130+ | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)
131131 copy arr (i+1) max arr' (j+1)
132132{-# INLINE append #-}
133133
134134{-# RULES
135−"TEXT append -> fused" [~1] forall t1 t2.
135+"TEXT append -> fused" [~1] forall t1 t2.
136136 append t1 t2 = unstream (S.append (stream t1) (stream t2))
137137"TEXT append -> unfused" [1] forall t1 t2.
138138 unstream (S.append (stream t1) (stream t2)) = append t1 t2
@@ -147,7 +147,7 @@ head t = S.head (stream t)
147147-- | /O(n)/ Returns the last character of a Text, which must be non-empty.
148148-- Subject to array fusion.
149149last :: Text -> Char
150−last (Text arr off len)
150+last (Text arr off len)
151151 | len <= 0 = errorEmptyList "last"
152152 | n < 0xDC00 || n > 0xDFFF = unsafeChr n
153153 | otherwise = U16.chr2 n0 n
@@ -156,7 +156,7 @@ last (Text arr off len)
156156 n0 = unsafeAt arr (off+len-2)
157157{-# INLINE [1] last #-}
158158
159−{-# RULES
159+{-# RULES
160160"TEXT last -> fused" [~1] forall t.
161161 last t = S.last (stream t)
162162"TEXT last -> unfused" [1] forall t.
@@ -166,7 +166,7 @@ last (Text arr off len)
166166
167167-- | /O(1)/ Returns all characters after the head of a Text, which must
168168-- be non-empty.
169−-- Subject to array fusion.
169+-- Subject to array fusion.
170170tail :: Text -> Text
171171tail (Text arr off len)
172172 | len <= 0 = errorEmptyList "tail"
@@ -178,10 +178,10 @@ tail (Text arr off len)
178178
179179
180180
181−-- | /O(1)/ Returns all but the last character of a Text, which
181+-- | /O(1)/ Returns all but the last character of a Text, which
182182-- must be non-empty.
183183-- Subject to array fusion.
184−init :: Text -> Text
184+init :: Text -> Text
185185init (Text arr off len) | len <= 0 = errorEmptyList "init"
186186 | n >= 0xDC00 && n <= 0xDFFF = Text arr off (len-2)
187187 | otherwise = Text arr off (len-1)
@@ -211,21 +211,21 @@ length t = S.length (stream t)
211211-- -----------------------------------------------------------------------------
212212-- * Transformations
213213-- | /O(n)/ 'map' @f @xs is the Text obtained by applying @f@ to each
214−-- element of @xs@.
214+-- element of @xs@.
215215-- Subject to array fusion.
216216map :: (Char -> Char) -> Text -> Text
217217map f t = unstream (S.map f (stream t))
218218{-# INLINE [1] map #-}
219219
220−-- | /O(n)/ The 'intersperse' function takes a character and places it between
220+-- | /O(n)/ The 'intersperse' function takes a character and places it between
221221-- the characters of a Text.
222222-- Subject to array fusion.
223223intersperse :: Char -> Text -> Text
224224intersperse c t = unstream (S.intersperse c (stream t))
225225{-# INLINE intersperse #-}
226226
227−-- | /O(n)/ The 'transpose' function transposes the rows and columns of its
228−-- Text argument. Note that this function uses pack, unpack, and the 'List'
227+-- | /O(n)/ The 'transpose' function transposes the rows and columns of its
228+-- Text argument. Note that this function uses pack, unpack, and the 'List'
229229-- version of transpose and is thus not very efficient.
230230transpose :: [Text] -> [Text]
231231transpose ts = P.map pack (L.transpose (P.map unpack ts))
@@ -233,7 +233,7 @@ transpose ts = P.map pack (L.transpose (P.map unpack ts))
233233-- -----------------------------------------------------------------------------
234234-- * Reducing 'Text's (folds)
235235
236−-- | 'foldl', applied to a binary operator, a starting value (typically the
236+-- | 'foldl', applied to a binary operator, a starting value (typically the
237237-- left-identity of the operator), and a Text, reduces the Text using the
238238-- binary operator, from left to right.
239239-- Subject to array fusion.
@@ -247,7 +247,7 @@ foldl' :: (b -> Char -> b) -> b -> Text -> b
247247foldl' f z t = S.foldl' f z (stream t)
248248{-# INLINE foldl' #-}
249249
250−-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,
250+-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,
251251-- and thus must be applied to non-empty 'Text's.
252252-- Subject to array fusion.
253253foldl1 :: (Char -> Char -> Char) -> Text -> Char
@@ -260,7 +260,7 @@ foldl1' :: (Char -> Char -> Char) -> Text -> Char
260260foldl1' f t = S.foldl1' f (stream t)
261261{-# INLINE foldl1' #-}
262262
263−-- | 'foldr', applied to a binary operator, a starting value (typically the
263+-- | 'foldr', applied to a binary operator, a starting value (typically the
264264-- right-identity of the operator), and a Text, reduces the Text using the
265265-- binary operator, from right to left.
266266-- Subject to array fusion.
@@ -268,7 +268,7 @@ foldr :: (Char -> b -> b) -> b -> Text -> b
268268foldr f z t = S.foldr f z (stream t)
269269{-# INLINE foldr #-}
270270
271−-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
271+-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
272272-- and thust must be applied to non-empty 'Text's.
273273-- Subject to array fusion.
274274foldr1 :: (Char -> Char -> Char) -> Text -> Char
@@ -283,10 +283,10 @@ concat :: [Text] -> Text
283283concat ts = unstream (S.concat (L.map stream ts))
284284{-# INLINE concat #-}
285285
286−-- | Map a function over a Text that results in a Text and concatenate the
287−-- results. This function is subject to array fusion, and note that if in
288−-- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will
289−-- also be fusible.
286+-- | Map a function over a Text that results in a Text and concatenate the
287+-- results. This function is subject to array fusion, and note that if in
288+-- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will
289+-- also be fusible.
290290concatMap :: (Char -> Text) -> Text -> Text
291291concatMap f t = unstream (S.concatMap (stream . f) (stream t))
292292{-# INLINE concatMap #-}
@@ -303,13 +303,13 @@ all :: (Char -> Bool) -> Text -> Bool
303303all p t = S.all p (stream t)
304304{-# INLINE all #-}
305305
306−-- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be
306+-- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be
307307-- non-empty. Subject to array fusion.
308308maximum :: Text -> Char
309309maximum t = S.maximum (stream t)
310310{-# INLINE maximum #-}
311311
312−-- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be
312+-- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be
313313-- non-empty. Subject to array fusion.
314314minimum :: Text -> Char
315315minimum t = S.minimum (stream t)
@@ -350,15 +350,15 @@ take :: Int -> Text -> Text
350350take n (Text arr off len) = Text arr off (loop off 0)
351351 where
352352 end = off+len
353− loop !i !count
353+ loop !i !count
354354 | i >= end || count >= n = i - off
355− | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1)
355+ | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1)
356356 | otherwise = loop (i+2) (count+1)
357357 where
358358 c = arr `unsafeAt` i
359359{-# INLINE [1] take #-}
360360
361−{-# RULES
361+{-# RULES
362362"TEXT take -> fused" [~1] forall n t.
363363 take n t = unstream (S.take n (stream t))
364364"TEXT take -> unfused" [1] forall n t.
@@ -381,7 +381,7 @@ drop n (Text arr off len) = (Text arr newOff newLen)
381381 c = arr `unsafeAt` i
382382{-# INLINE [1] drop #-}
383383
384−{-# RULES
384+{-# RULES
385385"TEXT drop -> fused" [~1] forall n t.
386386 drop n t = unstream (S.drop n (stream t))
387387"TEXT drop -> unfused" [1] forall n t.
@@ -398,7 +398,7 @@ dropWhile :: (Char -> Bool) -> Text -> Text
398398dropWhile p t = unstream (S.dropWhile p (stream t))
399399
400400-- ----------------------------------------------------------------------------
401−-- * Searching
401+-- * Searching
402402
403403-------------------------------------------------------------------------------
404404-- ** Searching by equality
@@ -455,22 +455,22 @@ elemIndex c t = S.elemIndex c (stream t)
455455zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
456456zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
457457
458−-- File I/O
458+-- File I/O
459459
460460readFile :: Encoding -> FilePath -> IO Text
461−readFile enc f = B.readFile f >>= return . unstream . stream_bs enc
461+readFile enc f = B.readFile f >>= return . unstream . stream_bs enc
462462{-# INLINE [1] readFile #-}
463463
464464words :: Text -> [Text]
465465words (Text arr off len) = loop0 off off
466466 where
467− loop0 start n
467+ loop0 start n
468468 | isSpace (unsafeChr c) = if start == n
469− then loop0 (start+1) (start+1)
469+ then loop0 (start+1) (start+1)
470470 else (Text arr start (n-start)):loop0 (n+1) (n+1)
471471 | n < (off+len) = loop0 start (n+1)
472472 | otherwise = if start == n
473− then []
473+ then []
474474 else [(Text arr start (n-start))]
475475 where
476476 c = arr `unsafeAt` n
Text/Fusion.hs+72−72
@@ -63,7 +63,7 @@ unstream :: Stream Char -> Text
6363unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
6464 where
6565 x :: ((UArray Int Word16),Int)
66− x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
66+ x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
6767 >>= (\arr -> loop arr 0 (len+1) s0))
6868 loop arr !i !max !s
6969 | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
@@ -80,7 +80,7 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
8080 | otherwise -> do
8181 unsafeWrite arr i l
8282 unsafeWrite arr (i + 1) r
83− loop arr (i+2) max s'
83+ loop arr (i+2) max s'
8484 where
8585 n :: Int
8686 n = ord x
@@ -93,13 +93,13 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
9393{-# INLINE [0] unstream #-}
9494
9595
96−copy src dest = (do
96+copy src dest = (do
9797 (_,max) <- getBounds src
9898 copy_loop 0 max)
9999 where
100− copy_loop !i !max
100+ copy_loop !i !max
101101 | i > max = return ()
102− | otherwise = do v <- unsafeRead src i
102+ | otherwise = do v <- unsafeRead src i
103103 unsafeWrite dest i v
104104 copy_loop (i+1) max
105105
@@ -113,7 +113,7 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = compare (next1 s1) (next2 s2)
113113 compare (Skip s1') (Skip s2') = compare (next1 s1') (next2 s2')
114114 compare (Skip s1') x2 = compare (next1 s1') x2
115115 compare x1 (Skip s2') = compare x1 (next2 s2')
116− compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
116+ compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
117117 compare (next1 s1') (next2 s2')
118118{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
119119
@@ -123,12 +123,12 @@ stream_bs :: Encoding -> ByteString -> Stream Char
123123stream_bs ASCII bs = Stream next 0 (B.length bs)
124124 where
125125 {-# INLINE next #-}
126− next i
126+ next i
127127 | i >= l = Done
128128 | otherwise = Yield (unsafeChr8 x1) (i+1)
129129 where
130130 l = B.length bs
131− x1 = B.index bs i
131+ x1 = B.index bs i
132132stream_bs Utf8 bs = Stream next 0 (B.length bs)
133133 where
134134 {-# INLINE next #-}
@@ -145,11 +145,11 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
145145 x2 = index (i + 1)
146146 x3 = index (i + 2)
147147 x4 = index (i + 3)
148− index = B.index bs
148+ index = B.index bs
149149stream_bs Utf16LE bs = Stream next 0 (B.length bs)
150150 where
151151 {-# INLINE next #-}
152− next i
152+ next i
153153 | i >= l = Done
154154 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
155155 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -159,12 +159,12 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
159159 x1 = (shiftL (index (i + 1)) 8) + (index i)
160160 x2 :: Word16
161161 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
162− l = B.length bs
162+ l = B.length bs
163163 index = fromIntegral . B.index bs :: Int -> Word16
164164stream_bs Utf16BE bs = Stream next 0 (B.length bs)
165165 where
166166 {-# INLINE next #-}
167− next i
167+ next i
168168 | i >= l = Done
169169 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
170170 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -179,7 +179,7 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
179179stream_bs Utf32BE bs = Stream next 0 (B.length bs)
180180 where
181181 {-# INLINE next #-}
182− next i
182+ next i
183183 | i >= l = Done
184184 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
185185 | otherwise = error "bsStream: bad UTF-32BE stream"
@@ -194,7 +194,7 @@ stream_bs Utf32BE bs = Stream next 0 (B.length bs)
194194stream_bs Utf32LE bs = Stream next 0 (B.length bs)
195195 where
196196 {-# INLINE next #-}
197− next i
197+ next i
198198 | i >= l = Done
199199 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
200200 | otherwise = error "bsStream: bad UTF-32LE stream"
@@ -217,14 +217,14 @@ restream ASCII (Stream next0 s0 len) = Stream next s0 (len*2)
217217 Skip s' -> Skip s'
218218 Yield x xs -> Yield x' xs
219219 where x' = fromIntegral (ord x) :: Word8
220−restream Utf8 (Stream next0 s0 len) =
220+restream Utf8 (Stream next0 s0 len) =
221221 Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
222222 where
223223 {-# INLINE next #-}
224− next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
224+ next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
225225 Done -> Done
226226 Skip s' -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
227− Yield x xs
227+ Yield x xs
228228 | n <= 0x7F -> Yield c ((Just xs) :!: Nothing :!: Nothing :!: Nothing)
229229 | n <= 0x07FF -> Yield (fst c2) ((Just xs) :!: (Just $ snd c2) :!: Nothing :!: Nothing)
230230 | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
@@ -234,7 +234,7 @@ restream Utf8 (Stream next0 s0 len) =
234234 c = fromIntegral n
235235 c2 = U8.ord2 x
236236 c3 = U8.ord3 x
237− c4 = U8.ord4 x
237+ c4 = U8.ord4 x
238238 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
239239 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
240240 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -242,7 +242,7 @@ restream Utf16BE (Stream next0 s0 len) =
242242 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
243243 where
244244 {-# INLINE next #-}
245− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
245+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
246246 Done -> Done
247247 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
248248 Yield x xs
@@ -250,12 +250,12 @@ restream Utf16BE (Stream next0 s0 len) =
250250 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
251251 where
252252 n = ord x
253− n1 = n - 0x10000
253+ n1 = n - 0x10000
254254 c1 = fromIntegral (shiftR n1 18 + 0xD8)
255− c2 = fromIntegral (shiftR n1 10)
255+ c2 = fromIntegral (shiftR n1 10)
256256 n2 = n1 .&. 0x3FF
257− c3 = fromIntegral (shiftR n2 8 + 0xDC)
258− c4 = fromIntegral n2
257+ c3 = fromIntegral (shiftR n2 8 + 0xDC)
258+ c4 = fromIntegral n2
259259 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
260260 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
261261 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -263,7 +263,7 @@ restream Utf16LE (Stream next0 s0 len) =
263263 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
264264 where
265265 {-# INLINE next #-}
266− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
266+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
267267 Done -> Done
268268 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
269269 Yield x xs
@@ -271,20 +271,20 @@ restream Utf16LE (Stream next0 s0 len) =
271271 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
272272 where
273273 n = ord x
274− n1 = n - 0x10000
274+ n1 = n - 0x10000
275275 c2 = fromIntegral (shiftR n1 18 + 0xD8)
276− c1 = fromIntegral (shiftR n1 10)
276+ c1 = fromIntegral (shiftR n1 10)
277277 n2 = n1 .&. 0x3FF
278− c4 = fromIntegral (shiftR n2 8 + 0xDC)
279− c3 = fromIntegral n2
278+ c4 = fromIntegral (shiftR n2 8 + 0xDC)
279+ c3 = fromIntegral n2
280280 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
281281 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
282282 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
283−restream Utf32BE (Stream next0 s0 len) =
283+restream Utf32BE (Stream next0 s0 len) =
284284 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
285285 where
286286 {-# INLINE next #-}
287− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
287+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
288288 Done -> Done
289289 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
290290 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -297,11 +297,11 @@ restream Utf32BE (Stream next0 s0 len) =
297297 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
298298 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
299299 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
300−restream Utf32LE (Stream next0 s0 len) =
300+restream Utf32LE (Stream next0 s0 len) =
301301 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
302302 where
303303 {-# INLINE next #-}
304− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
304+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
305305 Done -> Done
306306 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
307307 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -315,15 +315,15 @@ restream Utf32LE (Stream next0 s0 len) =
315315 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
316316 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
317317{-# INLINE restream #-}
318−
318+
319319
320320fst3 (x1,_,_) = x1
321321snd3 (_,x2,_) = x2
322322trd3 (_,_,x3) = x3
323−fst4 (x1,_,_,_) = x1
323+fst4 (x1,_,_,_) = x1
324324snd4 (_,x2,_,_) = x2
325325trd4 (_,_,x3,_) = x3
326−fth4 (_,_,_,x4) = x4
326+fth4 (_,_,_,x4) = x4
327327
328328-- | /O(n)/ Convert a Stream Word8 to a ByteString
329329unstream_bs :: Stream Word8 -> ByteString
@@ -359,13 +359,13 @@ unstream_bs (Stream next s0 len) = unsafePerformIO $ do
359359-- ----------------------------------------------------------------------------
360360-- * Basic stream functions
361361
362−-- | /O(n)/ Adds a character to the front of a Stream Char.
362+-- | /O(n)/ Adds a character to the front of a Stream Char.
363363cons :: Char -> Stream Char -> Stream Char
364364cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
365365 where
366366 {-# INLINE next #-}
367367 next (S2 :!: s) = Yield w (S1 :!: s)
368− next (S1 :!: s) = case next0 s of
368+ next (S1 :!: s) = case next0 s of
369369 Done -> Done
370370 Skip s' -> Skip (S1 :!: s')
371371 Yield x s' -> Yield x (S1 :!: s')
@@ -385,11 +385,11 @@ snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2)
385385
386386-- | /O(n)/ Appends one Stream to the other.
387387append :: Stream Char -> Stream Char -> Stream Char
388−append (Stream next0 s01 len1) (Stream next1 s02 len2) =
388+append (Stream next0 s01 len1) (Stream next1 s02 len2) =
389389 Stream next (Left s01) (len1 + len2)
390390 where
391391 {-# INLINE next #-}
392− next (Left s1) = case next0 s1 of
392+ next (Left s1) = case next0 s1 of
393393 Done -> Skip (Right s02)
394394 Skip s1' -> Skip (Left s1')
395395 Yield x s1' -> Yield x (Left s1')
@@ -403,8 +403,8 @@ append (Stream next0 s01 len1) (Stream next1 s02 len2) =
403403-- Subject to array fusion.
404404head :: Stream Char -> Char
405405head (Stream next s0 len) = loop_head s0
406− where
407− loop_head !s = case next s of
406+ where
407+ loop_head !s = case next s of
408408 Yield x _ -> x
409409 Skip s' -> loop_head s'
410410 Done -> error "head: Empty list"
@@ -433,7 +433,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
433433 next (False :!: s) = case next0 s of
434434 Done -> error "tail"
435435 Skip s' -> Skip (False :!: s')
436− Yield _ s' -> Skip (True :!: s')
436+ Yield _ s' -> Skip (True :!: s')
437437 next (True :!: s) = case next0 s of
438438 Done -> Done
439439 Skip s' -> Skip (True :!: s')
@@ -441,7 +441,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
441441{-# INLINE [0] tail #-}
442442
443443
444−-- | /O(1)/ Returns all but the last character of a Stream Char, which
444+-- | /O(1)/ Returns all but the last character of a Stream Char, which
445445-- must be non-empty.
446446init :: Stream Char -> Stream Char
447447init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
@@ -472,28 +472,28 @@ length :: Stream Char -> Int
472472length (Stream next s0 len) = loop_length 0# s0
473473 where
474474
475− loop_length z# !s = case next s of
475+ loop_length z# !s = case next s of
476476 Done -> (I# z#)
477− Skip s' -> loop_length z# s'
478− Yield _ s' -> loop_length (z# +# 1#) s'
477+ Skip s' -> loop_length z# s'
478+ Yield _ s' -> loop_length (z# +# 1#) s'
479479{-# INLINE[0] length #-}
480480
481481-- ----------------------------------------------------------------------------
482482-- * Stream transformations
483483
484−-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
485−-- @xs@.
484+-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
485+-- @xs@.
486486map :: (Char -> Char) -> Stream Char -> Stream Char
487487map f (Stream next0 s0 len) = Stream next s0 len
488488 where
489489 {-# INLINE next #-}
490− next !s = case next0 s of
490+ next !s = case next0 s of
491491 Done -> Done
492492 Skip s' -> Skip s'
493− Yield x s' -> Yield (f x) s'
493+ Yield x s' -> Yield (f x) s'
494494{-# INLINE [0] map #-}
495495
496−{-#
496+{-#
497497 RULES "STREAM map/map fusion" forall f g s.
498498 map f (map g s) = map (\x -> f (g x)) s
499499 #-}
@@ -517,7 +517,7 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
517517-- ----------------------------------------------------------------------------
518518-- * Reducing Streams (folds)
519519
520−-- | foldl, applied to a binary operator, a starting value (typically the
520+-- | foldl, applied to a binary operator, a starting value (typically the
521521-- left-identity of the operator), and a Stream, reduces the Stream using the
522522-- binary operator, from left to right.
523523foldl :: (b -> Char -> b) -> b -> Stream Char -> b
@@ -539,7 +539,7 @@ foldl' f z0 (Stream next s0 len) = loop_foldl' z0 s0
539539 Yield x s' -> loop_foldl' (f z x) s'
540540{-# INLINE [0] foldl' #-}
541541
542−-- | foldl1 is a variant of foldl that has no starting value argument,
542+-- | foldl1 is a variant of foldl that has no starting value argument,
543543-- and thus must be applied to non-empty Streams.
544544foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
545545foldl1 f (Stream next s0 len) = loop0_foldl1 s0
@@ -568,7 +568,7 @@ foldl1' f (Stream next s0 len) = loop0_foldl1' s0
568568 Yield x s' -> loop_foldl1' (f z x) s'
569569{-# INLINE [0] foldl1' #-}
570570
571−-- | 'foldr', applied to a binary operator, a starting value (typically the
571+-- | 'foldr', applied to a binary operator, a starting value (typically the
572572-- right-identity of the operator), and a stream, reduces the stream using the
573573-- binary operator, from right to left.
574574foldr :: (Char -> b -> b) -> b -> Stream Char -> b
@@ -580,7 +580,7 @@ foldr f z (Stream next s0 len) = loop_foldr s0
580580 Yield x s' -> f x (loop_foldr s')
581581{-# INLINE [0] foldr #-}
582582
583−-- | foldr1 is a variant of 'foldr' that has no starting value argument,
583+-- | foldr1 is a variant of 'foldr' that has no starting value argument,
584584-- and thust must be applied to non-empty streams.
585585-- Subject to array fusion.
586586foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
@@ -596,7 +596,7 @@ foldr1 f (Stream next s0 len) = loop0_foldr1 s0
596596 Skip s' -> loop_foldr1 x s'
597597 Yield x' s' -> f x (loop_foldr1 x' s')
598598{-# INLINE [0] foldr1 #-}
599−
599+
600600-- ----------------------------------------------------------------------------
601601-- ** Special folds
602602
@@ -606,7 +606,7 @@ concat = L.foldr append (Stream next Done 0)
606606 where
607607 next Done = Done
608608
609−-- | Map a function over a stream that results in a steram and concatenate the
609+-- | Map a function over a stream that results in a steram and concatenate the
610610-- results.
611611concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
612612concatMap f = foldr (append . f) (stream empty)
@@ -627,14 +627,14 @@ any p (Stream next0 s0 len) = loop_any s0
627627all :: (Char -> Bool) -> Stream Char -> Bool
628628all p (Stream next0 s0 len) = loop_all s0
629629 where
630− loop_all !s = case next0 s of
630+ loop_all !s = case next0 s of
631631 Done -> True
632632 Skip s' -> seq s' $ loop_all s'
633633 Yield x s' | p x -> seq s' $ loop_all s'
634634 | otherwise -> False
635635
636−-- | /O(n)/ maximum returns the maximum value from a stream, which must be
637−-- non-empty.
636+-- | /O(n)/ maximum returns the maximum value from a stream, which must be
637+-- non-empty.
638638maximum :: Stream Char -> Char
639639maximum (Stream next0 s0 len) = loop0_maximum s0
640640 where
@@ -648,8 +648,8 @@ maximum (Stream next0 s0 len) = loop0_maximum s0
648648 Yield x s'
649649 | x > z -> seq s' $ loop_maximum x s'
650650 | otherwise -> seq s' $ loop_maximum z s'
651−
652−-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
651+
652+-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
653653-- non-empty.
654654minimum :: Stream Char -> Char
655655minimum (Stream next0 s0 len) = loop0_minimum s0
@@ -666,8 +666,8 @@ minimum (Stream next0 s0 len) = loop0_minimum s0
666666 | otherwise -> seq s' $ loop_minimum z s'
667667
668668
669−
670−
669+
670+
671671-- -----------------------------------------------------------------------------
672672-- * Building streams
673673
@@ -694,8 +694,8 @@ unfoldr f s0 = Stream next s0 1
694694-- first argument to unfoldrN. This function is more efficient than
695695-- unfoldr when the maximum length of the result and correct,
696696-- otherwise its complexity performance is similar to 'unfoldr'
697−unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
698−unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
697+unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
698+unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
699699 where
700700 {-# INLINE next #-}
701701 next (z :!: s) = case f s of
@@ -718,7 +718,7 @@ take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
718718 Skip s' -> Skip (n :!: s')
719719 Yield x s' -> Yield x ((n-1) :!: s')
720720{-# INLINE [0] take #-}
721−
721+
722722-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
723723-- stream of length @n@, or the empty stream if @n@ is greater than the
724724-- length of the stream.
@@ -768,7 +768,7 @@ dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
768768{-# INLINE [0] dropWhile #-}
769769
770770-- ----------------------------------------------------------------------------
771−-- * Searching
771+-- * Searching
772772
773773-------------------------------------------------------------------------------
774774-- ** Searching by equality
@@ -794,7 +794,7 @@ elem w (Stream next s0 len) = loop_elem s0
794794find :: (Char -> Bool) -> Stream Char -> Maybe Char
795795find p (Stream next s0 len) = loop_find s0
796796 where
797− loop_find !s = case next s of
797+ loop_find !s = case next s of
798798 Done -> Nothing
799799 Skip s' -> loop_find s'
800800 Yield x s' | p x -> Just x
@@ -851,7 +851,7 @@ findIndex p (Stream next s0 len) = loop_findIndex 0 s0
851851
852852-- | /O(n)/ The 'elemIndex' function returns the index of the first
853853-- element in the given stream which is equal to the query
854−-- element, or 'Nothing' if there is no such element.
854+-- element, or 'Nothing' if there is no such element.
855855elemIndex :: Char -> Stream Char -> Maybe Int
856856elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
857857 where
@@ -875,7 +875,7 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
875875 Done -> Done
876876 Skip sa' -> Skip (sa' :!: sb :!: Nothing)
877877 Yield a sa' -> Skip (sa' :!: sb :!: Just a)
878−
878+
879879 next (sa' :!: sb :!: Just a) = case next1 sb of
880880 Done -> Done
881881 Skip sb' -> Skip (sa' :!: sb' :!: Just a)
@@ -884,4 +884,4 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
884884
885885errorEmptyList :: String -> a
886886errorEmptyList fun =
887− error ("Prelude." ++ fun ++ ": empty list")
887+ error ("Prelude." ++ fun ++ ": empty list")
Text/Internal.hs+3−3
@@ -4,8 +4,8 @@ import Data.Array.ST(newArray_,runSTUArray)
44import Data.Array.Unboxed(UArray(..))
55import Data.Word(Word16(..))
66
7−data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int
7+data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int
88
99empty :: Text
10−empty = Text (runSTUArray (newArray_ (0,0))) 0 0
11−{-# INLINE [1] empty #-}
10+empty = Text (runSTUArray (newArray_ (0,0))) 0 0
11+{-# INLINE [1] empty #-}
Text/Utf8.hs+11−11
@@ -9,7 +9,7 @@ import GHC.Exts
99import GHC.Prim
1010import GHC.Word
1111
12−between :: Word8 -> Word8 -> Word8 -> Bool
12+between :: Word8 -> Word8 -> Word8 -> Bool
1313between x y z = x >= y && x <= z
1414{-# INLINE between #-}
1515
@@ -31,7 +31,7 @@ ord3 c = (x1,x2,x3)
3131ord4 :: Char -> (Word8,Word8,Word8,Word8)
3232ord4 c = (x1,x2,x3,x4)
3333 where
34− n = ord c
34+ n = ord c
3535 x1 = fromIntegral $ (shiftR n 18) + (0xF0::Int) :: Word8
3636 x2 = fromIntegral $ ((shiftR n 12) .&. (0x3F::Int)) + (0x80::Int) :: Word8
3737 x3 = fromIntegral $ ((shiftR n 6) .&. (0x3F::Int)) + (0x80::Int) :: Word8
@@ -47,7 +47,7 @@ chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
4747{-# INLINE chr2 #-}
4848
4949chr3 :: Word8 -> Word8 -> Word8 -> Char
50−chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
50+chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
5151 where
5252 y1# = word2Int# x1#
5353 y2# = word2Int# x2#
@@ -58,7 +58,7 @@ chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
5858{-# INLINE chr3 #-}
5959
6060chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char
61−chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
61+chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
6262 C# (chr# (z1# +# z2# +# z3# +# z4#))
6363 where
6464 y1# = word2Int# x1#
@@ -94,15 +94,15 @@ validate4 x1 x2 x3 x4 = validate4_1 x1 x2 x3 x4 ||
9494
9595
9696
97−validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
98− between x2 0xA0 0xBF &&
97+validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
98+ between x2 0xA0 0xBF &&
9999 between x3 0x80 0xBF
100100{-# INLINE validate3_1 #-}
101101
102102validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
103103 between x2 0x80 0xBF &&
104104 between x3 0x80 0xBF
105−{-# INLINE validate3_2 #-}
105+{-# INLINE validate3_2 #-}
106106
107107validate3_3 x1 x2 x3 = x1 == 0xED &&
108108 between x2 0x80 0x9F &&
@@ -118,17 +118,17 @@ validate3_4 x1 x2 x3 = between x1 0xEE 0xEF &&
118118validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
119119 between x2 0x90 0xBF &&
120120 between x3 0x80 0xBF &&
121− between x4 0x80 0xBF
121+ between x4 0x80 0xBF
122122{-# INLINE validate4_1 #-}
123123
124124validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
125125 between x2 0x80 0xBF &&
126126 between x3 0x80 0xBF &&
127− between x4 0x80 0xBF
127+ between x4 0x80 0xBF
128128{-# INLINE validate4_2 #-}
129129
130130validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
131131 between x2 0x80 0x8F &&
132132 between x3 0x80 0xBF &&
133− between x4 0x80 0xBF
134−{-# INLINE validate4_3 #-}
133+ between x4 0x80 0xBF
134+{-# INLINE validate4_3 #-}