@@ -13,8 +13,8 @@
1313module Data.Text.IO.Internal
1414 (
1515#if __GLASGOW_HASKELL__ >= 612
16− hGetLineLoop
17− , getSomeCharacters
16+ getSomeCharacters
17+ , hGetLineWith
1818 , unpack
1919 , unpack_nl
2020#endif
@@ -23,7 +23,6 @@ module Data.Text.IO.Internal
2323#if __GLASGOW_HASKELL__ >= 612
2424import Control.Exception (throw)
2525import Data.IORef (readIORef, writeIORef)
26−import qualified Data.Text as T
2726import Data.Text (Text)
2827import Data.Text.Fusion (stream, unstream)
2928import Data.Text.Fusion.Internal (Step(..), Stream(..))
@@ -40,7 +39,16 @@ import GHC.IO.Handle.Internals (augmentIOError, ioe_EOF, readTextDevice,
4039import GHC.IO.Handle.Text (commitBuffer')
4140import GHC.IO.Handle.Types (BufferList(..), BufferMode(..), Handle__(..),
4241 Newline(..))
42+import System.IO (Handle)
4343import System.IO.Error (isEOFError)
44+import qualified Data.Text as T
45+
46+hGetLineWith :: ([Text] -> t) -> Handle -> IO t
47+hGetLineWith f h = wantReadableHandle_ "hGetLine" h go
48+ where go hh@Handle__{..} = do
49+ buf <- readIORef haCharBuffer
50+ ts <- hGetLineLoop hh [] buf
51+ return (f ts)
4452
4553hGetLineLoop :: Handle__ -> [Text] -> CharBuffer -> IO [Text]
4654hGetLineLoop hh@Handle__{..} ts buf@Buffer{ bufL=r0, bufR=w, bufRaw=raw0 } = do