bytestring hGetLine has moved

This commit is contained in:
rhiannon morris 2024-09-15 17:39:52 +02:00
parent 0438ee590f
commit 3ae0cd7c52

View file

@ -6,7 +6,7 @@ import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Misc import Misc
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as LazyBS import qualified Data.ByteString.Lazy as LazyBS
import qualified System.IO as IO import qualified System.IO as IO
@ -34,7 +34,7 @@ list = Sequence () untagged . map toYAML
-- @---@ and a @...@. throw an exception if there isn't one -- @---@ and a @...@. throw an exception if there isn't one
readHeader :: FilePath -> IO (Node Pos) readHeader :: FilePath -> IO (Node Pos)
readHeader file = IO.withFile file IO.ReadMode \h -> do readHeader file = IO.withFile file IO.ReadMode \h -> do
ln <- BS.hGetLine h ln <- BS8.hGetLine h
if (ln /= "---") then if (ln /= "---") then
fail $ file <> ": no header" fail $ file <> ": no header"
else else
@ -45,7 +45,7 @@ readHeader file = IO.withFile file IO.ReadMode \h -> do
linesUntil :: ByteString -> IO.Handle -> IO LazyBS.ByteString linesUntil :: ByteString -> IO.Handle -> IO LazyBS.ByteString
linesUntil end h = go [] where linesUntil end h = go [] where
go acc = do go acc = do
l <- BS.hGetLine h l <- BS8.hGetLine h
if l == end then if l == end then
return $ LazyBS.fromChunks $ reverse acc return $ LazyBS.fromChunks $ reverse acc
else else