From cdf8b4f5f54986d9537c6e77b2d8ee797f9a0366 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Fri, 16 Jun 2023 23:12:38 +0100 Subject: [PATCH] Deprecate D.B.getLine/hGetLine in favor of D.B.Char8 --- Data/ByteString.hs | 9 ++++++++- Data/ByteString/Char8.hs | 13 +++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Data/ByteString.hs b/Data/ByteString.hs index 6958e4e11..37e8077d5 100644 --- a/Data/ByteString.hs +++ b/Data/ByteString.hs @@ -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 $ @@ -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 diff --git a/Data/ByteString/Char8.hs b/Data/ByteString/Char8.hs index 17e2d143f..1d4d9accd 100644 --- a/Data/ByteString/Char8.hs +++ b/Data/ByteString/Char8.hs @@ -2,6 +2,7 @@ {-# LANGUAGE MagicHash #-} {-# OPTIONS_HADDOCK prune #-} {-# LANGUAGE Trustworthy #-} +{-# OPTIONS_GHC -Wno-deprecations #-} -- | -- Module : Data.ByteString.Char8 @@ -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 ) @@ -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