Skip to content

Commit

Permalink
Deprecate D.B.getLine/hGetLine in favor of D.B.Char8 (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Jun 24, 2023
1 parent dac5675 commit 4672a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,11 @@ copy (BS x l) = unsafeCreateFp l $ \p -> memcpyFp p x l
getLine :: IO ByteString
getLine = hGetLine stdin

-- | Read a line from a handle
{-# DEPRECATED getLine
"Deprecated since @bytestring-0.12@. Use 'Data.ByteString.Char8.getLine' instead. (Functions that rely on ASCII encodings belong in \"Data.ByteString.Char8\")"
#-}

-- | Read a line from a handle
hGetLine :: Handle -> IO ByteString
hGetLine h =
wantReadableHandle_ "Data.ByteString.hGetLine" h $
Expand Down Expand Up @@ -1874,6 +1877,10 @@ hGetLine h =
then return r -- NB. not r+1: don't include the '\n'
else findEOL (r+1) w raw

{-# DEPRECATED hGetLine
"Deprecated since @bytestring-0.12@. Use 'Data.ByteString.Char8.hGetLine' instead. (Functions that rely on ASCII encodings belong in \"Data.ByteString.Char8\")"
#-}

mkPS :: RawBuffer Word8 -> Int -> Int -> IO ByteString
mkPS buf start end =
createFp len $ \fp -> memcpyFp fp (buf `plusForeignPtr` start) len
Expand Down
13 changes: 11 additions & 2 deletions Data/ByteString/Char8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE MagicHash #-}
{-# OPTIONS_HADDOCK prune #-}
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -Wno-deprecations #-}

-- |
-- Module : Data.ByteString.Char8
Expand Down Expand Up @@ -269,10 +270,10 @@ import Data.ByteString (null,length,tail,init,append
,isInfixOf,stripPrefix,stripSuffix
,breakSubstring,copy,group

,getLine, getContents, putStr, interact
,getContents, putStr, interact
,readFile, writeFile, appendFile
,hGetContents, hGet, hGetSome, hPut, hPutStr
,hGetLine, hGetNonBlocking, hPutNonBlocking
,hGetNonBlocking, hPutNonBlocking
,packCString,packCStringLen
,useAsCString,useAsCStringLen
)
Expand Down Expand Up @@ -997,6 +998,14 @@ unwords = intercalate (singleton ' ')
------------------------------------------------------------------------
-- For non-binary text processing:

-- | Read a line from stdin.
getLine :: IO ByteString
getLine = B.getLine

-- | Read a line from a handle
hGetLine :: Handle -> IO ByteString
hGetLine = B.hGetLine

-- | Write a ByteString to a handle, appending a newline byte.
--
-- Unlike 'hPutStr', this is not atomic: other threads might write
Expand Down

0 comments on commit 4672a57

Please sign in to comment.