Commit d993f5b0 authored by sof's avatar sof
Browse files

[project @ 1999-05-10 16:55:43 by sof]

The implementation of hGetLine, as given in the report, doesn't handle
partial lines on unbuffered handles that well (not at all, as it turns
out). Fixed.
parent 1c6ce98a
......@@ -216,14 +216,34 @@ hGetChar handle =
then return (chr intc)
else constructErrorAndFail "hGetChar"
{-
If EOF is reached before EOL is encountered, ignore the
EOF and return the partial line. Next attempt at calling
hGetLine on the handle will yield an EOF IO exception though.
-}
hGetLine :: Handle -> IO String
hGetLine h = do
c <- hGetChar h
if c == '\n'
then return ""
if c == '\n' then
return ""
else do
s <- hGetLine h
return (c:s)
l <- getRest
return (c:l)
where
getRest = do
c <-
catch
(hGetChar h)
(\ err -> do
if isEOFError err then
return '\n'
else
ioError err)
if c == '\n' then
return ""
else do
s <- getRest
return (c:s)
\end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment