packages feed

pipes-break 0.2.0.1 → 0.2.0.3

raw patch · 4 files changed

+18/−24 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

pipes-break.cabal view
@@ -1,6 +1,6 @@ name:                pipes-break-version:             0.2.0.1-synopsis:            Pipes for grouping by input by any delimiter (such as lines with carriage returns)+version:             0.2.0.3+synopsis:            Pipes to group by any delimiter (such as lines with carriage returns) description:   `pipes-break` contains utility functions for splitting bytestring or text with any delimiter you like.   .
src/Pipes/Break/ByteString/Lens.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE RankNTypes #-}  {- | For those who like lenses, here are Lens library versions of the functions from Pipes.Break.Text- -+      To learn more about using lenses to manipulate pipes, check out the in depth tutorial at      <http://hackage.haskell.org/package/pipes-group/docs/Pipes-Group-Tutorial.html> @@ -22,7 +22,6 @@   --   -- $breakbyoverview   breaksBy, unBreaksBy,- ) where  import Pipes as P
src/Pipes/Break/Internal.hs view
@@ -28,7 +28,7 @@ unDrawP :: Monad m => a -> ParserP a m () unDrawP = hoist lift . unDraw -class (Show a, Monoid a, Eq a, IsString a) => TextLike a where+class (Eq a, IsString a) => TextLike a where   tlNull :: a -> Bool   tlBreakSubstring :: a -> a -> (a, a)   tlLength :: a -> Int@@ -57,15 +57,14 @@ _endsBy = toFreeT . _breakBy  _unBreaksBy, _unEndsBy :: (TextLike a, Monad m) => a -> FreeT (Producer a m) m r -> Producer a m r+ _unBreaksBy = intercalates . yield _unEndsBy del = concats . maps (<* yield del)  _breakBy :: (TextLike a, Monad m) => a -> Producer a m r -> Producer a m (Producer a m r)-_breakBy delim p = lift (next p) >>= \case-    Left r -> return (return r)-    -- If the user supplied an empty delimiter, breakByP will infinitely loop.-    Right (bs, p') | tlNull delim -> yield bs >> _breakBy delim p'-    Right (bs, p') -> execStateT (breakByP delim) (yield bs >> p')+-- If the user supplied an empty delimiter, breakByP would infinitely loop.+_breakBy delim | tlNull delim = \p -> for p yield >>= return . return+_breakBy delim = execStateT (breakByP delim)   _unEndBy :: (TextLike a, Monad m) => a -> Producer a m (Producer a m r) -> Producer a m r@@ -85,12 +84,7 @@         Left r       -> return (Pure r)         Right (bs, p') -> return $ Free (go1 (yield bs >> p')) -    go1 p = do-      p' <- f p-      return $ FreeT $ do-        next p' >>= \case-          Left r -> return (Pure r)-          Right (bs, p'') -> go0 (yield bs >> p'')+    go1 p = f p >>= return . FreeT . go0  -- Yield data from underlying producer before the delimiter, while stripping the delimeter out. breakByP :: (TextLike a, Monad m) => a -> ParserP a m ()@@ -103,35 +97,36 @@         Just bs | tlNull bs -> go         Just bs -> case tlBreakSubstring str bs of  -           -- null suff means pref has no delimeter or partial delimiter and we need to fetch more chunks to be sure+           -- null suff means non null pref has no delimeter or partial delimiter so we need to fetch more chunks to+           -- know whether rest of delimiter is incoming.            (_, suff) | tlNull suff -> if (tlLength str <= 1)+               -- If the delimiter is only one character, we know it can't be in this chunk.               then yieldP bs >> go                -- Starting with one less than the length of delimiter, test the end of this chunk.-              else hoist lift (chunkEndsWith str bs (max(tlLength bs - (tlLength str - 1)) 0)) >>= \case+              else hoist lift (chunkEndsWith str bs (max (tlLength bs - (tlLength str - 1)) 0)) >>= \case                  -- The end of this chunk does begin with the delimiter, get more chunks, keep going.                 Nothing -> yieldP bs >> go -                -- This chunk has a delimiter at index n, yield it, and undraw beginning of delimiter+                -- This chunk has a delimiter at index n, yield up to it, drop remainder of delimiter from rest of stream.                 Just n -> do                   yieldP (tlTake n bs)                   hoist lift (dropChars (tlLength str - (tlLength bs - n))) -            -- non null suff means suff has delimiter.            -- pref must be yielded if it is non null            (pref, suff) -> do               yieldP pref               unDrawP (tlDrop (tlLength str) suff) -+-- Drop n characters from the stream. dropChars :: (TextLike a, Monad m) => Int -> P.Parser a m () dropChars 0 = return () dropChars n = draw >>= \case   Nothing -> return ()-  Just bs | n > tlLength bs -> dropChars (n - tlLength bs)+  Just bs | n > tlLength bs -> dropChars $! (n - tlLength bs)   Just bs -> unDraw (tlDrop n bs)  -- See if Producer with initial chunk ends with the delimiter anywhere after first n characters,@@ -143,7 +138,7 @@           True -> return (Just n)           False -> go bs $! (n + 1) --- if Producer starts with a, return True.  Never advances the stream.+-- if first chunk and rest of Producer with rest starts with a, return True.  Never advances the stream. startsWith :: (TextLike a, Monad m) => a -> a -> P.Parser a m Bool startsWith = go1   where
src/Pipes/Break/Text/Lens.hs view
@@ -12,7 +12,7 @@ > > fmap mconcat <$> P.toListM $ >     over (endsBy "\n\n" . individually) (over (endsBy "\n" . individually) id) >        (yield "A\nB\n\nA\nB\nC\n\n")->  "A\nB\n\n\nA\nB\nC\n\n\n\n\n"+> "A\nB\n\n\nA\nB\nC\n\n\n\n\n"    As you can see, this would result in the wrong number of newlines being appended when reforming. -}