From e2009c7eab85feede8018dc210c24e54d00f4efb Mon Sep 17 00:00:00 2001 From: Bryan O'Sullivan <bos@serpentine.com> Date: Tue, 15 Dec 2009 01:24:07 +0000 Subject: [PATCH] A few small tidyups. --HG-- extra : convert_revision : 2e07a3efa60dc4ab8f0e990fdc5ff2ab570a499a --- Data/Text/IO/Internal.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Data/Text/IO/Internal.hs b/Data/Text/IO/Internal.hs index cbad5980..a4c928cc 100644 --- a/Data/Text/IO/Internal.hs +++ b/Data/Text/IO/Internal.hs @@ -35,18 +35,18 @@ import System.IO (Handle) import System.IO.Error (isEOFError) import qualified Data.Text as T +-- | Read a single line of input from a handle, constructing a list of +-- decoded chunks as we go. When we're done, transform them into the +-- destination type. hGetLineWith :: ([Text] -> t) -> Handle -> IO t hGetLineWith f h = wantReadableHandle_ "hGetLine" h go - where go hh@Handle__{..} = do - buf <- readIORef haCharBuffer - ts <- hGetLineLoop hh [] buf - return (f ts) + where + go hh@Handle__{..} = readIORef haCharBuffer >>= fmap f . hGetLineLoop hh [] hGetLineLoop :: Handle__ -> [Text] -> CharBuffer -> IO [Text] hGetLineLoop hh@Handle__{..} ts buf@Buffer{ bufL=r0, bufR=w, bufRaw=raw0 } = do - let findEOL raw r - | r == w = return (False, w) - | otherwise = do + let findEOL raw r | r == w = return (False, w) + | otherwise = do (c,r') <- readCharBuf raw r if c == '\n' then return (True, r) @@ -147,6 +147,8 @@ getSomeCharacters handle_@Handle__{..} buf@Buffer{..} = -- buffer has some chars in it already: just return it _otherwise -> return buf +-- | Read a single chunk of strict text from a buffer. Used by both +-- the strict and lazy implementations of hGetContents. readChunk :: Handle__ -> CharBuffer -> IO Text readChunk hh@Handle__{..} buf = do buf'@Buffer{..} <- getSomeCharacters hh buf -- GitLab