aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes
diff options
context:
space:
mode:
Diffstat (limited to 'Pipes')
-rw-r--r--Pipes/Text.hs81
1 files changed, 19 insertions, 62 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs
index 68ede1a..9bdacf9 100644
--- a/Pipes/Text.hs
+++ b/Pipes/Text.hs
@@ -62,15 +62,7 @@ To stream from files, the following is perhaps more Prelude-like (note that it u
62 62
63module Pipes.Text ( 63module Pipes.Text (
64 -- * Producers 64 -- * Producers
65 fromLazy 65 fromLazy
66 -- , stdin
67 -- , fromHandle
68 -- , readFile
69
70 -- * Consumers
71 -- , stdout
72 -- , toHandle
73 -- , writeFile
74 66
75 -- * Pipes 67 -- * Pipes
76 , map 68 , map
@@ -81,7 +73,6 @@ module Pipes.Text (
81 , dropWhile 73 , dropWhile
82 , filter 74 , filter
83 , scan 75 , scan
84-- , encodeUtf8
85 , pack 76 , pack
86 , unpack 77 , unpack
87 , toCaseFold 78 , toCaseFold
@@ -121,30 +112,13 @@ module Pipes.Text (
121 , group 112 , group
122 , word 113 , word
123 , line 114 , line
124
125 -- -- * Decoding Lenses
126 -- , decodeUtf8
127 -- , codec
128 --
129 -- -- * Codecs
130 -- , utf8
131 -- , utf16_le
132 -- , utf16_be
133 -- , utf32_le
134 -- , utf32_be
135 --
136 -- -- * Other Decoding/Encoding Functions
137 -- , decodeIso8859_1
138 -- , decodeAscii
139 -- , encodeIso8859_1
140 -- , encodeAscii
141 115
142 -- * FreeT Splitters 116 -- * FreeT Splitters
143 , chunksOf 117 , chunksOf
144 , splitsWith 118 , splitsWith
145 , splits 119 , splits
146-- , groupsBy 120 , groupsBy
147-- , groups 121 , groups
148 , lines 122 , lines
149 , words 123 , words
150 124
@@ -157,11 +131,8 @@ module Pipes.Text (
157 , unlines 131 , unlines
158 , unwords 132 , unwords
159 133
160 -- * Re-exports 134 -- * Re-exports
161 -- $reexports 135 -- $reexports
162 -- , DecodeResult(..)
163 -- , Codec
164 -- , TextException(..)
165 , module Data.ByteString 136 , module Data.ByteString
166 , module Data.Text 137 , module Data.Text
167 , module Data.Profunctor 138 , module Data.Profunctor
@@ -188,6 +159,7 @@ import qualified Pipes.Parse as PP
188import Pipes.Parse (Parser) 159import Pipes.Parse (Parser)
189import qualified Pipes.Prelude as P 160import qualified Pipes.Prelude as P
190import Data.Char (isSpace) 161import Data.Char (isSpace)
162import Data.Word (Word8)
191 163
192import Prelude hiding ( 164import Prelude hiding (
193 all, 165 all,
@@ -251,16 +223,6 @@ concatMap f = P.map (T.concatMap f)
251 p >-> concatMap f = for p (\txt -> yield (T.concatMap f txt)) 223 p >-> concatMap f = for p (\txt -> yield (T.concatMap f txt))
252 #-} 224 #-}
253 225
254-- | Transform a Pipe of 'Text' into a Pipe of 'ByteString's using UTF-8
255-- encoding; @encodeUtf8 = Pipes.Prelude.map TE.encodeUtf8@ so more complex
256-- encoding pipes can easily be constructed with the functions in @Data.Text.Encoding@
257-- encodeUtf8 :: Monad m => Pipe Text ByteString m r
258-- encodeUtf8 = P.map TE.encodeUtf8
259-- {-# INLINEABLE encodeUtf8 #-}
260--
261-- {-# RULES "p >-> encodeUtf8" forall p .
262-- p >-> encodeUtf8 = for p (\txt -> yield (TE.encodeUtf8 txt))
263-- #-}
264 226
265-- | Transform a Pipe of 'String's into one of 'Text' chunks 227-- | Transform a Pipe of 'String's into one of 'Text' chunks
266pack :: Monad m => Pipe String Text m r 228pack :: Monad m => Pipe String Text m r
@@ -496,7 +458,6 @@ minimum = P.fold step Nothing id
496 Just c -> Just (min c (T.minimum txt)) 458 Just c -> Just (min c (T.minimum txt))
497{-# INLINABLE minimum #-} 459{-# INLINABLE minimum #-}
498 460
499
500-- | Find the first element in the stream that matches the predicate 461-- | Find the first element in the stream that matches the predicate
501find 462find
502 :: (Monad m) 463 :: (Monad m)
@@ -518,12 +479,12 @@ count c p = P.fold (+) 0 id (p >-> P.map (fromIntegral . T.count c))
518{-# INLINABLE count #-} 479{-# INLINABLE count #-}
519 480
520 481
521{-| Consume the first character from a stream of 'Text' 482-- | Consume the first character from a stream of 'Text'
483--
484-- 'next' either fails with a 'Left' if the 'Producer' has no more characters or
485-- succeeds with a 'Right' providing the next character and the remainder of the
486-- 'Producer'.
522 487
523 'next' either fails with a 'Left' if the 'Producer' has no more characters or
524 succeeds with a 'Right' providing the next character and the remainder of the
525 'Producer'.
526-}
527nextChar 488nextChar
528 :: (Monad m) 489 :: (Monad m)
529 => Producer Text m r 490 => Producer Text m r
@@ -539,9 +500,8 @@ nextChar = go
539 Just (c, txt') -> return (Right (c, yield txt' >> p')) 500 Just (c, txt') -> return (Right (c, yield txt' >> p'))
540{-# INLINABLE nextChar #-} 501{-# INLINABLE nextChar #-}
541 502
542{-| Draw one 'Char' from a stream of 'Text', returning 'Left' if the 503-- | Draw one 'Char' from a stream of 'Text', returning 'Left' if the 'Producer' is empty
543 'Producer' is empty 504
544-}
545drawChar :: (Monad m) => Parser Text m (Maybe Char) 505drawChar :: (Monad m) => Parser Text m (Maybe Char)
546drawChar = do 506drawChar = do
547 x <- PP.draw 507 x <- PP.draw
@@ -568,7 +528,9 @@ unDrawChar c = modify (yield (T.singleton c) >>)
568> Left _ -> return () 528> Left _ -> return ()
569> Right c -> unDrawChar c 529> Right c -> unDrawChar c
570> return x 530> return x
531
571-} 532-}
533
572peekChar :: (Monad m) => Parser Text m (Maybe Char) 534peekChar :: (Monad m) => Parser Text m (Maybe Char)
573peekChar = do 535peekChar = do
574 x <- drawChar 536 x <- drawChar
@@ -595,8 +557,6 @@ isEndOfChars = do
595{-# INLINABLE isEndOfChars #-} 557{-# INLINABLE isEndOfChars #-}
596 558
597 559
598
599
600-- | Splits a 'Producer' after the given number of characters 560-- | Splits a 'Producer' after the given number of characters
601splitAt 561splitAt
602 :: (Monad m, Integral n) 562 :: (Monad m, Integral n)
@@ -623,9 +583,10 @@ splitAt n0 k p0 = fmap join (k (go n0 p0))
623{-# INLINABLE splitAt #-} 583{-# INLINABLE splitAt #-}
624 584
625 585
626{-| Split a text stream in two, where the first text stream is the longest 586-- | Split a text stream in two, producing the longest
627 consecutive group of text that satisfy the predicate 587-- consecutive group of characters that satisfies the predicate
628-} 588-- and returning the rest
589
629span 590span
630 :: (Monad m) 591 :: (Monad m)
631 => (Char -> Bool) 592 => (Char -> Bool)
@@ -648,7 +609,7 @@ span predicate k p0 = fmap join (k (go p0))
648 return (yield suffix >> p') 609 return (yield suffix >> p')
649{-# INLINABLE span #-} 610{-# INLINABLE span #-}
650 611
651{-| Split a text stream in two, where the first text stream is the longest 612{-| Split a text stream in two, producing the longest
652 consecutive group of characters that don't satisfy the predicate 613 consecutive group of characters that don't satisfy the predicate
653-} 614-}
654break 615break
@@ -928,10 +889,6 @@ unwords
928unwords = intercalate (yield $ T.singleton ' ') 889unwords = intercalate (yield $ T.singleton ' ')
929{-# INLINABLE unwords #-} 890{-# INLINABLE unwords #-}
930 891
931{- $parse
932 The following parsing utilities are single-character analogs of the ones found
933 @pipes-parse@.
934-}
935 892
936{- $reexports 893{- $reexports
937 894