Commits

Anonymous committed 73dd8cc

Clean up whitespace

  • Participants
  • Parent commits c93668a

Comments (0)

Files changed (4)

     mempty  = empty
     mappend = append
     mconcat = concat
-                  
 
-  
+
+
 -- -----------------------------------------------------------------------------
 -- * Conversion to/from 'Text'
 
 -- | /O(n)/ Convert a String into a Text.
 --
--- This function is subject to array fusion, so calling other fusible 
--- function(s) on a packed string will only cause one 'Text' to be written 
+-- This function is subject to array fusion, so calling other fusible
+-- function(s) on a packed string will only cause one 'Text' to be written
 -- out at the end of the pipeline, instead of one before and one after.
 pack :: String -> Text
 pack str = (unstream (stream_list str))
             next []     = S.Done
             next (x:xs) = S.Yield x xs
 {-# INLINE [1] pack #-}
--- TODO: Has to do validation! -- No, it doesn't, the 
+-- TODO: Has to do validation! -- No, it doesn't, the
 
 -- | /O(n)/ Convert a Text into a String.
 -- Subject to array fusion.
 {-# INLINE decode #-}
 
 encode         :: Encoding -> Text -> ByteString
-encode enc txt = unstream_bs (restream enc (stream txt)) 
+encode enc txt = unstream_bs (restream enc (stream txt))
 {-# INLINE encode #-}
 
 -- -----------------------------------------------------------------------------
 -- * Basic functions
 
--- | /O(n)/ Adds a character to the front of a 'Text'.  This function is more 
+-- | /O(n)/ Adds a character to the front of a 'Text'.  This function is more
 -- costly than its 'List' counterpart because it requires copying a new array.
 -- Subject to array fusion.
 cons :: Char -> Text -> Text
 cons c t = unstream (S.cons c (stream t))
 {-# INLINE cons #-}
 
--- | /O(n)/ Adds a character to the end of a 'Text'.  This copies the entire 
+-- | /O(n)/ Adds a character to the end of a 'Text'.  This copies the entire
 -- array in the process.
 -- Subject to array fusion.
 snoc :: Text -> Char -> Text
 snoc t c = unstream (S.snoc (stream t) c)
 {-# INLINE snoc #-}
 
--- | /O(n)/ Appends one Text to the other by copying both of them into a new 
--- Text.  
+-- | /O(n)/ Appends one Text to the other by copying both of them into a new
+-- Text.
 -- Subject to array fusion
 append :: Text -> Text -> Text
 append (Text arr1 off1 len1) (Text arr2 off2 len2) = Text (runSTUArray x) 0 len
-    where 
+    where
       len = len1+len2
       x = do
         arr <- unsafeNewArray_ (0,len-1) :: ST s (STUArray s Int Word16)
         return arr
             where
               copy arr i max arr' j
-                  | i >= max  = return () 
-                  | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)  
+                  | i >= max  = return ()
+                  | otherwise = do unsafeWrite arr' j (arr `unsafeAt` i)
                                    copy arr (i+1) max arr' (j+1)
 {-# INLINE append #-}
 
 {-# RULES
-"TEXT append -> fused" [~1] forall t1 t2. 
+"TEXT append -> fused" [~1] forall t1 t2.
     append t1 t2 = unstream (S.append (stream t1) (stream t2))
 "TEXT append -> unfused" [1] forall t1 t2.
     unstream (S.append (stream t1) (stream t2)) = append t1 t2
 -- | /O(n)/ Returns the last character of a Text, which must be non-empty.
 -- Subject to array fusion.
 last :: Text -> Char
-last (Text arr off len) 
+last (Text arr off len)
     | len <= 0                   = errorEmptyList "last"
     | n < 0xDC00 || n > 0xDFFF = unsafeChr n
     | otherwise                  = U16.chr2 n0 n
       n0 = unsafeAt arr (off+len-2)
 {-# INLINE [1] last #-}
 
-{-# RULES 
+{-# RULES
 "TEXT last -> fused" [~1] forall t.
     last t = S.last (stream t)
 "TEXT last -> unfused" [1] forall t.
 
 -- | /O(1)/ Returns all characters after the head of a Text, which must
 -- be non-empty.
--- Subject to array fusion. 
+-- Subject to array fusion.
 tail :: Text -> Text
 tail (Text arr off len)
     | len <= 0                   = errorEmptyList "tail"
 
 
 
--- | /O(1)/ Returns all but the last character of a Text, which 
+-- | /O(1)/ Returns all but the last character of a Text, which
 -- must be non-empty.
 -- Subject to array fusion.
-init :: Text -> Text 
+init :: Text -> Text
 init (Text arr off len) | len <= 0                   = errorEmptyList "init"
                         | n >= 0xDC00 && n <= 0xDFFF = Text arr off (len-2)
                         | otherwise                  = Text arr off (len-1)
 -- -----------------------------------------------------------------------------
 -- * Transformations
 -- | /O(n)/ 'map' @f @xs is the Text obtained by applying @f@ to each
--- element of @xs@.  
+-- element of @xs@.
 -- Subject to array fusion.
 map :: (Char -> Char) -> Text -> Text
 map f t = unstream (S.map f (stream t))
 {-# INLINE [1] map #-}
 
--- | /O(n)/ The 'intersperse' function takes a character and places it between 
+-- | /O(n)/ The 'intersperse' function takes a character and places it between
 -- the characters of a Text.
 -- Subject to array fusion.
 intersperse     :: Char -> Text -> Text
 intersperse c t = unstream (S.intersperse c (stream t))
 {-# INLINE intersperse #-}
 
--- | /O(n)/ The 'transpose' function transposes the rows and columns of its 
--- Text argument.  Note that this function uses pack, unpack, and the 'List' 
+-- | /O(n)/ The 'transpose' function transposes the rows and columns of its
+-- Text argument.  Note that this function uses pack, unpack, and the 'List'
 -- version of transpose and is thus not very efficient.
 transpose :: [Text] -> [Text]
 transpose ts = P.map pack (L.transpose (P.map unpack ts))
 -- -----------------------------------------------------------------------------
 -- * Reducing 'Text's (folds)
 
--- | 'foldl', applied to a binary operator, a starting value (typically the 
+-- | 'foldl', applied to a binary operator, a starting value (typically the
 -- left-identity of the operator), and a Text, reduces the Text using the
 -- binary operator, from left to right.
 -- Subject to array fusion.
 foldl' f z t = S.foldl' f z (stream t)
 {-# INLINE foldl' #-}
 
--- | 'foldl1' is a variant of 'foldl' that has no starting value argument, 
+-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,
 -- and thus must be applied to non-empty 'Text's.
 -- Subject to array fusion.
 foldl1 :: (Char -> Char -> Char) -> Text -> Char
 foldl1' f t = S.foldl1' f (stream t)
 {-# INLINE foldl1' #-}
 
--- | 'foldr', applied to a binary operator, a starting value (typically the 
+-- | 'foldr', applied to a binary operator, a starting value (typically the
 -- right-identity of the operator), and a Text, reduces the Text using the
 -- binary operator, from right to left.
 -- Subject to array fusion.
 foldr f z t = S.foldr f z (stream t)
 {-# INLINE foldr #-}
 
--- | 'foldr1' is a variant of 'foldr' that has no starting value argument, 
+-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
 -- and thust must be applied to non-empty 'Text's.
 -- Subject to array fusion.
 foldr1 :: (Char -> Char -> Char) -> Text -> Char
 concat ts = unstream (S.concat (L.map stream ts))
 {-# INLINE concat #-}
 
--- | Map a function over a Text that results in a Text and concatenate the 
--- results.  This function is subject to array fusion, and note that if in 
--- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will 
--- also be fusible. 
+-- | Map a function over a Text that results in a Text and concatenate the
+-- results.  This function is subject to array fusion, and note that if in
+-- 'concatMap' @f @xs, @f@ is defined in terms of fusible functions it will
+-- also be fusible.
 concatMap :: (Char -> Text) -> Text -> Text
 concatMap f t = unstream (S.concatMap (stream . f) (stream t))
 {-# INLINE concatMap #-}
 all p t = S.all p (stream t)
 {-# INLINE all #-}
 
--- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be 
+-- | /O(n)/ 'maximum' returns the maximum value from a 'Text', which must be
 -- non-empty. Subject to array fusion.
 maximum :: Text -> Char
 maximum t = S.maximum (stream t)
 {-# INLINE maximum #-}
 
--- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be 
+-- | /O(n)/ 'minimum' returns the minimum value from a 'Text', which must be
 -- non-empty. Subject to array fusion.
 minimum :: Text -> Char
 minimum t = S.minimum (stream t)
 take n (Text arr off len) = Text arr off (loop off 0)
     where
       end = off+len
-      loop !i !count 
+      loop !i !count
            | i >= end || count >= n   = i - off
-           | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1) 
+           | c < 0xD800 || c > 0xDBFF = loop (i+1) (count+1)
            | otherwise                = loop (i+2) (count+1)
            where
              c = arr `unsafeAt` i
 {-# INLINE [1] take #-}
 
-{-# RULES 
+{-# RULES
 "TEXT take -> fused" [~1] forall n t.
     take n t = unstream (S.take n (stream t))
 "TEXT take -> unfused" [1] forall n t.
             c = arr `unsafeAt` i
 {-# INLINE [1] drop #-}
 
-{-# RULES 
+{-# RULES
 "TEXT drop -> fused" [~1] forall n t.
     drop n t = unstream (S.drop n (stream t))
 "TEXT drop -> unfused" [1] forall n t.
 dropWhile p t = unstream (S.dropWhile p (stream t))
 
 -- ----------------------------------------------------------------------------
--- * Searching 
+-- * Searching
 
 -------------------------------------------------------------------------------
 -- ** Searching by equality
 zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
 zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
 
--- File I/O 
+-- File I/O
 
 readFile :: Encoding -> FilePath -> IO Text
-readFile enc f = B.readFile f >>= return . unstream . stream_bs enc 
+readFile enc f = B.readFile f >>= return . unstream . stream_bs enc
 {-# INLINE [1] readFile #-}
 
 words :: Text -> [Text]
 words (Text arr off len) = loop0 off off
     where
-      loop0 start n 
+      loop0 start n
             | isSpace (unsafeChr c) = if start == n
-                                      then loop0 (start+1) (start+1) 
+                                      then loop0 (start+1) (start+1)
                                       else (Text arr start (n-start)):loop0 (n+1) (n+1)
             | n < (off+len) = loop0 start (n+1)
             | otherwise = if start == n
-                          then [] 
+                          then []
                           else [(Text arr start (n-start))]
             where
               c = arr `unsafeAt` n

File Text/Fusion.hs

 unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
     where
       x :: ((UArray Int Word16),Int)
-      x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16)) 
+      x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
                  >>= (\arr -> loop arr 0 (len+1) s0))
       loop arr !i !max !s
           | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
                    | otherwise   -> do
                         unsafeWrite arr i       l
                         unsafeWrite arr (i + 1) r
-                        loop arr (i+2) max s' 
+                        loop arr (i+2) max s'
                    where
                      n :: Int
                      n = ord x
 {-# INLINE [0] unstream #-}
 
 
-copy src dest = (do 
+copy src dest = (do
                    (_,max) <- getBounds src
                    copy_loop 0 max)
     where
-      copy_loop !i !max 
+      copy_loop !i !max
           | i > max    = return ()
-          | otherwise = do v <- unsafeRead src i 
+          | otherwise = do v <- unsafeRead src i
                            unsafeWrite dest i v
                            copy_loop (i+1) max
 
       compare (Skip s1')     (Skip s2')     = compare (next1 s1') (next2 s2')
       compare (Skip s1')     x2             = compare (next1 s1') x2
       compare x1             (Skip s2')     = compare x1          (next2 s2')
-      compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 && 
+      compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
                                               compare (next1 s1') (next2 s2')
 {-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
 
 stream_bs ASCII bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
-      next i 
+      next i
           | i >= l    = Done
           | otherwise = Yield (unsafeChr8 x1) (i+1)
           where
             l  = B.length bs
-            x1 = B.index bs i 
+            x1 = B.index bs i
 stream_bs Utf8 bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
             x2 = index (i + 1)
             x3 = index (i + 2)
             x4 = index (i + 3)
-            index = B.index bs           
+            index = B.index bs
 stream_bs Utf16LE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
-      next i 
+      next i
           | i >= l                         = Done
           | i+1 < l && U16.validate1 x1    = Yield (unsafeChr x1) (i+2)
           | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
             x1    = (shiftL (index (i + 1)) 8) + (index i)
             x2    :: Word16
             x2    = (shiftL (index (i + 3)) 8) + (index (i + 2))
-            l     = B.length bs   
+            l     = B.length bs
             index = fromIntegral . B.index bs :: Int -> Word16
 stream_bs Utf16BE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
-      next i 
+      next i
           | i >= l                         = Done
           | i+1 < l && U16.validate1 x1    = Yield (unsafeChr x1) (i+2)
           | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
 stream_bs Utf32BE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
-      next i 
+      next i
           | i >= l                    = Done
           | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
           | otherwise                 = error "bsStream: bad UTF-32BE stream"
 stream_bs Utf32LE bs = Stream next 0 (B.length bs)
     where
       {-# INLINE next #-}
-      next i 
+      next i
           | i >= l                    = Done
           | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
           | otherwise                 = error "bsStream: bad UTF-32LE stream"
                   Skip s' -> Skip s'
                   Yield x xs -> Yield x' xs
                       where x' = fromIntegral (ord x) :: Word8
-restream Utf8 (Stream next0 s0 len) = 
+restream Utf8 (Stream next0 s0 len) =
     Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
     where
       {-# INLINE next #-}
-      next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of 
+      next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
                   Done              -> Done
                   Skip s'           -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
-                  Yield x xs 
+                  Yield x xs
                       | n <= 0x7F   -> Yield c         ((Just xs) :!: Nothing   :!: Nothing   :!: Nothing)
                       | n <= 0x07FF -> Yield (fst c2)  ((Just xs) :!: (Just $ snd c2)  :!: Nothing   :!: Nothing)
                       | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
                         c  = fromIntegral n
                         c2 = U8.ord2 x
                         c3 = U8.ord3 x
-                        c4 = U8.ord4 x          
+                        c4 = U8.ord4 x
       next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: Nothing)      = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: x4)           = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
     Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
     where
       {-# INLINE next #-}
-      next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of 
+      next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
           Done -> Done
           Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
           Yield x xs
               | otherwise   -> Yield c1                          (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
               where
                 n  = ord x
-                n1 = n - 0x10000 
+                n1 = n - 0x10000
                 c1 = fromIntegral (shiftR n1 18 + 0xD8)
-                c2 = fromIntegral (shiftR n1 10)       
+                c2 = fromIntegral (shiftR n1 10)
                 n2 = n1 .&. 0x3FF
-                c3 = fromIntegral (shiftR n2 8 + 0xDC) 
-                c4 = fromIntegral n2     
+                c3 = fromIntegral (shiftR n2 8 + 0xDC)
+                c4 = fromIntegral n2
       next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: Nothing)      = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: x4)           = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
     Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
     where
       {-# INLINE next #-}
-      next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of 
+      next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
           Done -> Done
           Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
           Yield x xs
               | otherwise   -> Yield c1                          (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
               where
                 n  = ord x
-                n1 = n - 0x10000 
+                n1 = n - 0x10000
                 c2 = fromIntegral (shiftR n1 18 + 0xD8)
-                c1 = fromIntegral (shiftR n1 10)       
+                c1 = fromIntegral (shiftR n1 10)
                 n2 = n1 .&. 0x3FF
-                c4 = fromIntegral (shiftR n2 8 + 0xDC) 
-                c3 = fromIntegral n2     
+                c4 = fromIntegral (shiftR n2 8 + 0xDC)
+                c3 = fromIntegral n2
       next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: Nothing)      = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
       next ((Just s) :!: (Just x2) :!: x3 :!: x4)           = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
-restream Utf32BE (Stream next0 s0 len) = 
+restream Utf32BE (Stream next0 s0 len) =
     Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
     where
     {-# INLINE next #-}
-    next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of 
+    next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
         Done       -> Done
         Skip s'    -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
         Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
     next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
     next ((Just s) :!: (Just x2) :!: x3 :!: Nothing)      = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
     next ((Just s) :!: (Just x2) :!: x3 :!: x4)           = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
-restream Utf32LE (Stream next0 s0 len) = 
+restream Utf32LE (Stream next0 s0 len) =
     Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
     where
     {-# INLINE next #-}
-    next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of 
+    next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
         Done       -> Done
         Skip s'    -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
         Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
     next ((Just s) :!: (Just x2) :!: x3 :!: Nothing)      = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
     next ((Just s) :!: (Just x2) :!: x3 :!: x4)           = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
 {-# INLINE restream #-}
-      
+
 
 fst3 (x1,_,_)   = x1
 snd3 (_,x2,_)   = x2
 trd3 (_,_,x3)   = x3
-fst4 (x1,_,_,_) = x1   
+fst4 (x1,_,_,_) = x1
 snd4 (_,x2,_,_) = x2
 trd4 (_,_,x3,_) = x3
-fth4 (_,_,_,x4) = x4 
+fth4 (_,_,_,x4) = x4
 
 -- | /O(n)/ Convert a Stream Word8 to a ByteString
 unstream_bs :: Stream Word8 -> ByteString
 -- ----------------------------------------------------------------------------
 -- * Basic stream functions
 
--- | /O(n)/ Adds a character to the front of a Stream Char. 
+-- | /O(n)/ Adds a character to the front of a Stream Char.
 cons :: Char -> Stream Char -> Stream Char
 cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
     where
       {-# INLINE next #-}
       next (S2 :!: s) = Yield w (S1 :!: s)
-      next (S1 :!: s) = case next0 s of 
+      next (S1 :!: s) = case next0 s of
                           Done -> Done
                           Skip s' -> Skip (S1 :!: s')
                           Yield x s' -> Yield x (S1 :!: s')
 
 -- | /O(n)/ Appends one Stream to the other.
 append :: Stream Char -> Stream Char -> Stream Char
-append (Stream next0 s01 len1) (Stream next1 s02 len2) = 
+append (Stream next0 s01 len1) (Stream next1 s02 len2) =
     Stream next (Left s01) (len1 + len2)
     where
       {-# INLINE next #-}
-      next (Left s1) = case next0 s1 of 
+      next (Left s1) = case next0 s1 of
                          Done        -> Skip    (Right s02)
                          Skip s1'    -> Skip    (Left s1')
                          Yield x s1' -> Yield x (Left s1')
 -- Subject to array fusion.
 head :: Stream Char -> Char
 head (Stream next s0 len) = loop_head s0
-    where 
-      loop_head !s = case next s of 
+    where
+      loop_head !s = case next s of
                       Yield x _ -> x
                       Skip s' -> loop_head s'
                       Done -> error "head: Empty list"
       next (False :!: s) = case next0 s of
                           Done -> error "tail"
                           Skip s' -> Skip (False :!: s')
-                          Yield _ s' -> Skip (True :!: s') 
+                          Yield _ s' -> Skip (True :!: s')
       next (True :!: s) = case next0 s of
                           Done -> Done
                           Skip s' -> Skip (True :!: s')
 {-# INLINE [0] tail #-}
 
 
--- | /O(1)/ Returns all but the last character of a Stream Char, which 
+-- | /O(1)/ Returns all but the last character of a Stream Char, which
 -- must be non-empty.
 init :: Stream Char -> Stream Char
 init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
 length (Stream next s0 len) = loop_length 0# s0
     where
 
-      loop_length z# !s  = case next s of 
+      loop_length z# !s  = case next s of
                             Done       -> (I# z#)
-                            Skip    s' -> loop_length z# s' 
-                            Yield _ s' -> loop_length (z# +# 1#) s' 
+                            Skip    s' -> loop_length z# s'
+                            Yield _ s' -> loop_length (z# +# 1#) s'
 {-# INLINE[0] length #-}
 
 -- ----------------------------------------------------------------------------
 -- * Stream transformations
 
--- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of 
--- @xs@. 
+-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
+-- @xs@.
 map :: (Char -> Char) -> Stream Char -> Stream Char
 map f (Stream next0 s0 len) = Stream next s0 len
     where
       {-# INLINE next #-}
-      next !s = case next0 s of 
+      next !s = case next0 s of
                   Done       -> Done
                   Skip s'    -> Skip s'
-                  Yield x s' -> Yield (f x) s'          
+                  Yield x s' -> Yield (f x) s'
 {-# INLINE [0] map #-}
 
-{-# 
+{-#
   RULES "STREAM map/map fusion" forall f g s.
      map f (map g s) = map (\x -> f (g x)) s
  #-}
 -- ----------------------------------------------------------------------------
 -- * Reducing Streams (folds)
 
--- | foldl, applied to a binary operator, a starting value (typically the 
+-- | foldl, applied to a binary operator, a starting value (typically the
 -- left-identity of the operator), and a Stream, reduces the Stream using the
 -- binary operator, from left to right.
 foldl :: (b -> Char -> b) -> b -> Stream Char -> b
                             Yield x s' -> loop_foldl' (f z x) s'
 {-# INLINE [0] foldl' #-}
 
--- | foldl1 is a variant of foldl that has no starting value argument, 
+-- | foldl1 is a variant of foldl that has no starting value argument,
 -- and thus must be applied to non-empty Streams.
 foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
 foldl1 f (Stream next s0 len) = loop0_foldl1 s0
                              Yield x s' -> loop_foldl1' (f z x) s'
 {-# INLINE [0] foldl1' #-}
 
--- | 'foldr', applied to a binary operator, a starting value (typically the 
+-- | 'foldr', applied to a binary operator, a starting value (typically the
 -- right-identity of the operator), and a stream, reduces the stream using the
 -- binary operator, from right to left.
 foldr :: (Char -> b -> b) -> b -> Stream Char -> b
                         Yield x s' -> f x (loop_foldr s')
 {-# INLINE [0] foldr #-}
 
--- | foldr1 is a variant of 'foldr' that has no starting value argument, 
+-- | foldr1 is a variant of 'foldr' that has no starting value argument,
 -- and thust must be applied to non-empty streams.
 -- Subject to array fusion.
 foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
       Skip     s' -> loop_foldr1 x s'
       Yield x' s' -> f x (loop_foldr1 x' s')
 {-# INLINE [0] foldr1 #-}
-    
+
 -- ----------------------------------------------------------------------------
 -- ** Special folds
 
     where
       next Done = Done
 
--- | Map a function over a stream that results in a steram and concatenate the 
+-- | Map a function over a stream that results in a steram and concatenate the
 -- results.
 concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
 concatMap f = foldr (append . f) (stream empty)
 all :: (Char -> Bool) -> Stream Char -> Bool
 all p (Stream next0 s0 len) = loop_all s0
     where
-      loop_all !s = case next0 s of 
+      loop_all !s = case next0 s of
                       Done                   -> True
                       Skip s'                -> seq s' $ loop_all s'
                       Yield x s' | p x       -> seq s' $ loop_all s'
                                  | otherwise -> False
 
--- | /O(n)/ maximum returns the maximum value from a stream, which must be 
--- non-empty. 
+-- | /O(n)/ maximum returns the maximum value from a stream, which must be
+-- non-empty.
 maximum :: Stream Char -> Char
 maximum (Stream next0 s0 len) = loop0_maximum s0
     where
                              Yield x s'
                                  | x > z     -> seq s' $ loop_maximum x s'
                                  | otherwise -> seq s' $ loop_maximum z s'
-                             
--- | /O(n)/ minimum returns the minimum value from a 'Text', which must be 
+
+-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
 -- non-empty.
 minimum :: Stream Char -> Char
 minimum (Stream next0 s0 len) = loop0_minimum s0
                                  | otherwise -> seq s' $ loop_minimum z s'
 
 
-                      
-                  
+
+
 -- -----------------------------------------------------------------------------
 -- * Building streams
 
 -- first argument to unfoldrN. This function is more efficient than
 -- unfoldr when the maximum length of the result and correct,
 -- otherwise its complexity performance is similar to 'unfoldr'
-unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char 
-unfoldrN n f s0 = Stream next (0 :!: s0) (n*2) 
+unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
+unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
     where
       {-# INLINE next #-}
       next (z :!: s) = case f s of
                                      Skip s' -> Skip (n :!: s')
                                      Yield x s' -> Yield x ((n-1) :!: s')
 {-# INLINE [0] take #-}
- 
+
 -- | /O(n)/ drop n, applied to a stream, returns the suffix of the
 -- stream of length @n@, or the empty stream if @n@ is greater than the
 -- length of the stream.
 {-# INLINE [0] dropWhile #-}
 
 -- ----------------------------------------------------------------------------
--- * Searching 
+-- * Searching
 
 -------------------------------------------------------------------------------
 -- ** Searching by equality
 find :: (Char -> Bool) -> Stream Char -> Maybe Char
 find p (Stream next s0 len) = loop_find s0
     where
-      loop_find !s = case next s of 
+      loop_find !s = case next s of
                        Done -> Nothing
                        Skip s' -> loop_find s'
                        Yield x s' | p x -> Just x
 
 -- | /O(n)/ The 'elemIndex' function returns the index of the first
 -- element in the given stream which is equal to the query
--- element, or 'Nothing' if there is no such element. 
+-- element, or 'Nothing' if there is no such element.
 elemIndex :: Char -> Stream Char -> Maybe Int
 elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
   where
                                        Done -> Done
                                        Skip sa' -> Skip (sa' :!: sb :!: Nothing)
                                        Yield a sa' -> Skip (sa' :!: sb :!: Just a)
-      
+
       next (sa' :!: sb :!: Just a) = case next1 sb of
                                        Done -> Done
                                        Skip sb' -> Skip (sa' :!: sb' :!: Just a)
 
 errorEmptyList :: String -> a
 errorEmptyList fun =
-  error ("Prelude." ++ fun ++ ": empty list")
+  error ("Prelude." ++ fun ++ ": empty list")

File Text/Internal.hs

 import Data.Array.Unboxed(UArray(..))
 import Data.Word(Word16(..))
 
-data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int 
+data Text = Text !(UArray Int Word16) {-# UNPACK #-}!Int {-# UNPACK #-}!Int
 
 empty :: Text
-empty = Text (runSTUArray (newArray_ (0,0))) 0 0 
-{-# INLINE [1] empty #-}
+empty = Text (runSTUArray (newArray_ (0,0))) 0 0
+{-# INLINE [1] empty #-}

File Text/Utf8.hs

 import GHC.Prim
 import GHC.Word
 
-between       :: Word8 -> Word8 -> Word8 -> Bool 
+between       :: Word8 -> Word8 -> Word8 -> Bool
 between x y z = x >= y && x <= z
 {-# INLINE between #-}
 
 ord4   :: Char -> (Word8,Word8,Word8,Word8)
 ord4 c = (x1,x2,x3,x4)
     where
-      n  = ord c 
+      n  = ord c
       x1 = fromIntegral $ (shiftR n 18) + (0xF0::Int) :: Word8
       x2 = fromIntegral $ ((shiftR n 12) .&. (0x3F::Int)) + (0x80::Int) :: Word8
       x3 = fromIntegral $ ((shiftR n 6) .&. (0x3F::Int)) + (0x80::Int) :: Word8
 {-# INLINE chr2 #-}
 
 chr3          :: Word8 -> Word8 -> Word8 -> Char
-chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#)) 
+chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
     where
       y1# = word2Int# x1#
       y2# = word2Int# x2#
 {-# INLINE chr3 #-}
 
 chr4             :: Word8 -> Word8 -> Word8 -> Word8 -> Char
-chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) = 
+chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
     C# (chr# (z1# +# z2# +# z3# +# z4#))
     where
       y1# = word2Int# x1#
 
 
 
-validate3_1 x1 x2 x3 = (x1 == 0xE0) && 
-                       between x2 0xA0 0xBF && 
+validate3_1 x1 x2 x3 = (x1 == 0xE0) &&
+                       between x2 0xA0 0xBF &&
                        between x3 0x80 0xBF
 {-# INLINE validate3_1 #-}
 
 validate3_2 x1 x2 x3 = between x1 0xE1 0xEC &&
                        between x2 0x80 0xBF &&
                        between x3 0x80 0xBF
-{-# INLINE validate3_2 #-} 
+{-# INLINE validate3_2 #-}
 
 validate3_3 x1 x2 x3 = x1 == 0xED &&
                        between x2 0x80 0x9F &&
 validate4_1 x1 x2 x3 x4 = x1 == 0xF0 &&
                           between x2 0x90 0xBF &&
                           between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF 
+                          between x4 0x80 0xBF
 {-# INLINE validate4_1 #-}
 
 validate4_2 x1 x2 x3 x4 = between x1 0xF1 0xF3 &&
                           between x2 0x80 0xBF &&
                           between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF 
+                          between x4 0x80 0xBF
 {-# INLINE validate4_2 #-}
 
 validate4_3 x1 x2 x3 x4 = x1 == 0xF4 &&
                           between x2 0x80 0x8F &&
                           between x3 0x80 0xBF &&
-                          between x4 0x80 0xBF 
-{-# INLINE validate4_3 #-}     
+                          between x4 0x80 0xBF
+{-# INLINE validate4_3 #-}