aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes/Text.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Pipes/Text.hs')
-rw-r--r--Pipes/Text.hs30
1 files changed, 29 insertions, 1 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs
index bdd706a..04c509f 100644
--- a/Pipes/Text.hs
+++ b/Pipes/Text.hs
@@ -81,6 +81,10 @@ module Pipes.Text (
81 filter, 81 filter,
82 scan, 82 scan,
83 encodeUtf8, 83 encodeUtf8,
84#if MIN_VERSION_text(0,11,4)
85 pipeDecodeUtf8,
86 pipeDecodeUtf8With,
87#endif
84 pack, 88 pack,
85 unpack, 89 unpack,
86 toCaseFold, 90 toCaseFold,
@@ -318,7 +322,8 @@ concatMap f = P.map (T.concatMap f)
318 322
319 323
320-- | Transform a Pipe of 'Text' into a Pipe of 'ByteString's using UTF-8 324-- | Transform a Pipe of 'Text' into a Pipe of 'ByteString's using UTF-8
321-- encoding 325-- encoding; @encodeUtf8 = Pipes.Prelude.map TE.encodeUtf8@ so more complex
326-- encoding pipes can easily be constructed with the functions in @Data.Text.Encoding@
322encodeUtf8 :: Monad m => Pipe Text ByteString m r 327encodeUtf8 :: Monad m => Pipe Text ByteString m r
323encodeUtf8 = P.map TE.encodeUtf8 328encodeUtf8 = P.map TE.encodeUtf8
324{-# INLINEABLE encodeUtf8 #-} 329{-# INLINEABLE encodeUtf8 #-}
@@ -594,6 +599,29 @@ decodeUtf8With onErr = go (TE.streamDecodeUtf8With onErr)
594 yield l 599 yield l
595 p' 600 p'
596{-# INLINEABLE decodeUtf8With #-} 601{-# INLINEABLE decodeUtf8With #-}
602
603-- | A simple pipe from 'ByteString' to 'Text'; a decoding error will arise
604-- with any chunk that contains a sequence of bytes that is unreadable. Otherwise
605-- only few bytes will only be moved from one chunk to the next before decoding.
606pipeDecodeUtf8 :: Monad m => Pipe ByteString Text m r
607pipeDecodeUtf8 = go TE.streamDecodeUtf8
608 where go dec = do chunk <- await
609 case dec chunk of
610 TE.Some text l dec' -> do yield text
611 go dec'
612{-# INLINEABLE pipeDecodeUtf8 #-}
613
614-- | A simple pipe from 'ByteString' to 'Text' using a replacement function.
615pipeDecodeUtf8With
616 :: Monad m
617 => TE.OnDecodeError
618 -> Pipe ByteString Text m r
619pipeDecodeUtf8With onErr = go (TE.streamDecodeUtf8With onErr)
620 where go dec = do chunk <- await
621 case dec chunk of
622 TE.Some text l dec' -> do yield text
623 go dec'
624{-# INLINEABLE pipeDecodeUtf8With #-}
597#endif 625#endif
598 626
599-- | Splits a 'Producer' after the given number of characters 627-- | Splits a 'Producer' after the given number of characters