netlines 0.2.0 → 0.2.1
raw patch · 2 files changed
+27/−25 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- Network/NetLines.hs +12/−16
- netlines.cabal +15/−9
Network/NetLines.hs view
@@ -24,7 +24,7 @@ where import qualified Data.ByteString as B-import Control.ContStuff+import Control.ContStuff as Monad import Data.ByteString (ByteString) import Data.Enumerator as E import Data.Enumerator.Binary as EB@@ -95,21 +95,17 @@ -- | Variant of 'netLine', which supports empty lines, useful for -- protocols like HTTP, in which empty lines have a special meaning.--- This function splits the input stream by LF characters while simply--- ignoring CR characters.--netLineEmpty :: forall m. Monad m => Int -> Iteratee ByteString m (Maybe ByteString)-netLineEmpty maxLine =- joinI $ E.map (B.filter (/= 13)) $$ evalMaybeT (netLineEmpty' maxLine)+-- This function splits the input stream by LF characters while ignoring+-- CR characters. - where- netLineEmpty' :: forall r. Int -> MaybeT r (Iteratee ByteString m) ByteString- netLineEmpty' 0 = B.empty <$ lift (EB.dropWhile (/= 10) >> EB.drop 1)- netLineEmpty' n = do- c <- liftF EB.head- if c /= 10- then B.cons c <$> netLineEmpty' (n-1)- else return B.empty+netLineEmpty :: Monad m => Int -> MaybeT r (Iteratee ByteString m) ByteString+netLineEmpty 0 = B.empty <$ lift (EB.dropWhile (/= 10) >> EB.head)+netLineEmpty n = do+ c <- liftF EB.head+ case c of+ 10 -> return B.empty+ 13 -> netLineEmpty (n-1)+ _ -> B.cons c <$> netLineEmpty (n-1) -- | Convert a stream of bytes to a stream of lines with the given@@ -136,7 +132,7 @@ where loop :: Enumeratee ByteString ByteString m b loop (Continue k) = do- mLine <- netLineEmpty maxLen+ mLine <- evalMaybeT (netLineEmpty maxLen) case mLine of Just line -> k (Chunks [line]) >>== loop Nothing -> k EOF >>== loop
netlines.cabal view
@@ -1,5 +1,5 @@ Name: netlines-Version: 0.2.0+Version: 0.2.1 Category: Network Synopsis: Enumerator tools for text-based network protocols Maintainer: Ertugrul Söylemez <es@ertes.de>@@ -18,11 +18,17 @@ constant space). Library- Build-depends:- base >= 4 && <= 5,- bytestring >= 0.9.1.7,- contstuff >= 1.2.4,- enumerator >= 0.4.7- GHC-Options: -W- Exposed-modules:- Network.NetLines+ Build-depends:+ base >= 4 && < 5,+ bytestring >= 0.9.1.7,+ contstuff >= 1.2.4,+ enumerator >= 0.4.7+ GHC-Options: -W+ Exposed-modules:+ Network.NetLines++-- Executable netlines-test+-- Build-depends:+-- base >= 4 && < 5+-- GHC-Options: -W+-- Main-is: Test.hs