Repository : ssh://darcs.haskell.org//srv/darcs/packages/bytestring

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/9a23ac026aeac21d443ae3f12ac6edc0c3e6b821

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

commit 9a23ac026aeac21d443ae3f12ac6edc0c3e6b821
Author: Duncan Coutts <[email protected]>
Date:   Mon May 16 12:26:24 2011 +0000

    Export putStrLn and hPutStrLn from D.B.Lazy.Char8
    and deprecate both functions in the non-Char8 modules.
    Functions that rely on ASCII encodings belong in the Char8 modules.

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

 Data/ByteString.hs            |    7 +++++++
 Data/ByteString/Char8.hs      |   16 +++++++++++++---
 Data/ByteString/Lazy.hs       |    4 ++++
 Data/ByteString/Lazy/Char8.hs |   16 ++++++++++++++--
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/Data/ByteString.hs b/Data/ByteString.hs
index 0c124d5..8e8d23c 100644
--- a/Data/ByteString.hs
+++ b/Data/ByteString.hs
@@ -1938,6 +1938,13 @@ putStr = hPut stdout
 putStrLn :: ByteString -> IO ()
 putStrLn = hPutStrLn stdout
 
+{-# DEPRECATED hPutStrLn
+    "Use Data.ByteString.Char8.hPutStrLn instead. (Functions that rely on 
ASCII encodings belong in Data.ByteString.Char8)"
+  #-}
+{-# DEPRECATED putStrLn
+    "Use Data.ByteString.Char8.putStrLn instead. (Functions that rely on ASCII 
encodings belong in Data.ByteString.Char8)"
+  #-}
+
 ------------------------------------------------------------------------
 -- Low level IO
 
diff --git a/Data/ByteString/Char8.hs b/Data/ByteString/Char8.hs
index 5cb34f0..a4fb461 100644
--- a/Data/ByteString/Char8.hs
+++ b/Data/ByteString/Char8.hs
@@ -237,8 +237,8 @@ import Data.ByteString (empty,null,length,tail,init,append
                        ,sort,isPrefixOf,isSuffixOf,isInfixOf
                        ,findSubstring,findSubstrings,breakSubstring,copy,group
 
-                       ,getLine, getContents, putStr, putStrLn, interact
-                       ,hGetContents, hGet, hPut, hPutStr, hPutStrLn
+                       ,getLine, getContents, putStr, interact
+                       ,hGetContents, hGet, hPut, hPutStr
                        ,hGetLine, hGetNonBlocking, hPutNonBlocking
                        ,packCString,packCStringLen
                        ,useAsCString,useAsCStringLen
@@ -250,7 +250,7 @@ import Data.ByteString.Internal (ByteString(PS), c2w, w2c, 
isSpaceWord8
 import Data.Char    ( isSpace )
 import qualified Data.List as List (intersperse)
 
-import System.IO                (openFile,hClose,hFileSize,IOMode(..))
+import System.IO                
(Handle,stdout,openFile,hClose,hFileSize,IOMode(..))
 #ifndef __NHC__
 import Control.Exception        (bracket)
 #else
@@ -1040,3 +1040,13 @@ appendFile :: FilePath -> ByteString -> IO ()
 appendFile f txt = bracket (openFile f AppendMode) hClose
     (\h -> hPut h txt)
 
+
+-- | 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
diff --git a/Data/ByteString/Lazy.hs b/Data/ByteString/Lazy.hs
index 9820e33..fbf9324 100644
--- a/Data/ByteString/Lazy.hs
+++ b/Data/ByteString/Lazy.hs
@@ -1322,6 +1322,10 @@ putStr = hPut stdout
 putStrLn :: ByteString -> IO ()
 putStrLn ps = hPut stdout ps >> hPut stdout (singleton 0x0a)
 
+{-# DEPRECATED putStrLn
+    "Use Data.ByteString.Lazy.Char8.putStrLn instead. (Functions that rely on 
ASCII encodings belong in Data.ByteString.Lazy.Char8)"
+  #-}
+
 -- | The interact function takes a function of type @ByteString -> ByteString@
 -- as its argument. The entire input from the standard input device is passed
 -- to this function as its argument, and the resulting string is output on the
diff --git a/Data/ByteString/Lazy/Char8.hs b/Data/ByteString/Lazy/Char8.hs
index f34678f..90bf4d8 100644
--- a/Data/ByteString/Lazy/Char8.hs
+++ b/Data/ByteString/Lazy/Char8.hs
@@ -173,6 +173,8 @@ module Data.ByteString.Lazy.Char8 (
         hGetNonBlocking,        -- :: Handle -> Int64 -> IO ByteString
         hPut,                   -- :: Handle -> ByteString -> IO ()
         hPutNonBlocking,        -- :: Handle -> ByteString -> IO ByteString
+        hPutStr,                -- :: Handle -> ByteString -> IO ()
+        hPutStrLn,              -- :: Handle -> ByteString -> IO ()
 
   ) where
 
@@ -183,7 +185,7 @@ import Data.ByteString.Lazy
         ,concat,take,drop,splitAt,intercalate,isPrefixOf,group,inits,tails,copy
         ,hGetContents, hGet, hPut, getContents
         ,hGetNonBlocking, hPutNonBlocking
-        ,putStr, putStrLn, interact)
+        ,putStr, hPutStr, interact)
 
 -- Functions we need to wrap.
 import qualified Data.ByteString.Lazy as L
@@ -204,7 +206,7 @@ import Prelude hiding
         
,readFile,writeFile,appendFile,replicate,getContents,getLine,putStr,putStrLn
         ,zip,zipWith,unzip,notElem,repeat,iterate,interact,cycle)
 
-import System.IO            (hClose,openFile,IOMode(..))
+import System.IO            (Handle,stdout,hClose,openFile,IOMode(..))
 #ifndef __NHC__
 import Control.Exception    (bracket)
 #else
@@ -855,6 +857,16 @@ appendFile f txt = bracket (openFile f AppendMode) hClose
     (\hdl -> hPut hdl txt)
 
 
+-- | Write a ByteString to a handle, appending a newline byte
+--
+hPutStrLn :: Handle -> ByteString -> IO ()
+hPutStrLn h ps = hPut h ps >> hPut h (L.singleton 0x0a)
+
+-- | Write a ByteString to stdout, appending a newline byte
+putStrLn :: ByteString -> IO ()
+putStrLn = hPutStrLn stdout
+
+
 -- ---------------------------------------------------------------------
 -- Internal utilities
 



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to