Permalink
Browse files

A few small tidyups.

--HG--
extra : convert_revision : 2e07a3efa60dc4ab8f0e990fdc5ff2ab570a499a
  • Loading branch information...
1 parent d88331b commit e2009c7eab85feede8018dc210c24e54d00f4efb @bos committed Dec 15, 2009
Showing with 9 additions and 7 deletions.
  1. +9 −7 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

0 comments on commit e2009c7

Please sign in to comment.