[commit: packages/bytestring] master: Partially Revert "Data.ByteString.Char8 uses IO functions exported from Data.ByteString" (56a4016)

git at git.haskell.org git at git.haskell.org
Mon Apr 17 21:32:06 UTC 2017


Repository : ssh://git@git.haskell.org/bytestring

On branch  : master
Link       : http://git.haskell.org/packages/bytestring.git/commitdiff/56a40166e3c2279ba729a84819fc63a5ecc1db29

>---------------------------------------------------------------

commit 56a40166e3c2279ba729a84819fc63a5ecc1db29
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Wed Feb 8 19:27:59 2017 -0500

    Partially Revert "Data.ByteString.Char8 uses IO functions exported from Data.ByteString"
    
    While several of these functions are indeed exported from Data.ByteString, they
    are justifiably marked as deprecated there. Ultimately it is the Data.ByteString
    functions that ought to be removed, not those in Data.ByteString.Char8. Namely,
    hPutStrLn and putStrLn rightly belong in Data.ByteString.Char8.
    
    This partially reverts commit 2fba115881b2da32ce076c1114ad6fe8d893086b.


>---------------------------------------------------------------

56a40166e3c2279ba729a84819fc63a5ecc1db29
 Data/ByteString/Char8.hs | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/Data/ByteString/Char8.hs b/Data/ByteString/Char8.hs
index f548a5e..9b0793c 100644
--- a/Data/ByteString/Char8.hs
+++ b/Data/ByteString/Char8.hs
@@ -250,8 +250,8 @@ import Data.ByteString (empty,null,length,tail,init,append
                        ,getLine, getContents, putStr, interact
                        ,readFile, writeFile, appendFile
                        ,hGetContents, hGet, hGetSome, hPut, hPutStr
-                       ,hPutStrLn, putStrLn, hGetLine, hGetNonBlocking
-                       ,hPutNonBlocking, packCString, packCStringLen
+                       ,hGetLine, hGetNonBlocking, hPutNonBlocking
+                       ,packCString,packCStringLen
                        ,useAsCString,useAsCStringLen
                        )
 
@@ -264,6 +264,7 @@ import GHC.Char (eqChar)
 #endif
 import qualified Data.List as List (intersperse)
 
+import System.IO    (Handle,stdout)
 import Foreign
 
 
@@ -963,3 +964,16 @@ readInteger as
 
           combine2 b (n:m:ns) = let t = m*b + n in t `seq` (t : combine2 b ns)
           combine2 _ ns       = ns
+
+------------------------------------------------------------------------
+-- For non-binary text processing:
+
+-- | Write a ByteString to a handle, appending a newline byte
+hPutStrLn :: Handle -> ByteString -> IO ()
+hPutStrLn h ps
+    | length ps < 1024 = hPut h (ps `B.snoc` 0x0a)
+    | otherwise        = hPut h ps >> hPut h (B.singleton 0x0a) -- don't copy
+
+-- | Write a ByteString to stdout, appending a newline byte
+putStrLn :: ByteString -> IO ()
+putStrLn = hPutStrLn stdout



More information about the ghc-commits mailing list