Skip to content

Commit

Permalink
A few small tidyups.
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : 2e07a3efa60dc4ab8f0e990fdc5ff2ab570a499a
  • Loading branch information
bos committed Dec 15, 2009
1 parent d88331b commit e2009c7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Data/Text/IO/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2009c7

Please sign in to comment.