add appendFile and hGetContents support to utf8 layer

This commit is contained in:
Simon Michael 2011-01-21 01:09:46 +00:00
parent 46422a7460
commit 0cda8e4c3f

View File

@ -1,5 +1,5 @@
{- {-
Copied from pandoc. From pandoc, slightly extended.
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu> Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
@ -32,7 +32,9 @@ UTF-8 aware string IO functions that will work with GHC 6.10 or 6.12.
-} -}
module Hledger.Data.UTF8 ( readFile module Hledger.Data.UTF8 ( readFile
, writeFile , writeFile
, appendFile
, getContents , getContents
, hGetContents
, putStr , putStr
, putStrLn , putStrLn
, hPutStr , hPutStr
@ -42,7 +44,7 @@ module Hledger.Data.UTF8 ( readFile
where where
import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy as B
import Data.ByteString.Lazy.UTF8 (toString, fromString) import Data.ByteString.Lazy.UTF8 (toString, fromString)
import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn) import Prelude hiding (readFile, writeFile, appendFile, getContents, putStr, putStrLn)
import System.IO (Handle) import System.IO (Handle)
import Control.Monad (liftM) import Control.Monad (liftM)
@ -59,9 +61,15 @@ readFile = liftM (toString . stripBOM) . B.readFile
writeFile :: FilePath -> String -> IO () writeFile :: FilePath -> String -> IO ()
writeFile f = B.writeFile f . fromString writeFile f = B.writeFile f . fromString
appendFile :: FilePath -> String -> IO ()
appendFile f = B.appendFile f . fromString
getContents :: IO String getContents :: IO String
getContents = liftM (toString . stripBOM) B.getContents getContents = liftM (toString . stripBOM) B.getContents
hGetContents :: Handle -> IO String
hGetContents h = liftM (toString . stripBOM) (B.hGetContents h)
putStr :: String -> IO () putStr :: String -> IO ()
putStr = B.putStr . fromString putStr = B.putStr . fromString