From 0cda8e4c3f0852a9a19ac846ddd697d37fdd5946 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 21 Jan 2011 01:09:46 +0000 Subject: [PATCH] add appendFile and hGetContents support to utf8 layer --- hledger-lib/Hledger/Data/UTF8.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Data/UTF8.hs b/hledger-lib/Hledger/Data/UTF8.hs index 17523ae44..d1422a407 100644 --- a/hledger-lib/Hledger/Data/UTF8.hs +++ b/hledger-lib/Hledger/Data/UTF8.hs @@ -1,5 +1,5 @@ {- -Copied from pandoc. +From pandoc, slightly extended. ---------------------------------------------------------------------- Copyright (C) 2010 John MacFarlane @@ -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 , writeFile + , appendFile , getContents + , hGetContents , putStr , putStrLn , hPutStr @@ -42,7 +44,7 @@ module Hledger.Data.UTF8 ( readFile where import qualified Data.ByteString.Lazy as B 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 Control.Monad (liftM) @@ -59,9 +61,15 @@ readFile = liftM (toString . stripBOM) . B.readFile writeFile :: FilePath -> String -> IO () writeFile f = B.writeFile f . fromString +appendFile :: FilePath -> String -> IO () +appendFile f = B.appendFile f . fromString + getContents :: IO String getContents = liftM (toString . stripBOM) B.getContents +hGetContents :: Handle -> IO String +hGetContents h = liftM (toString . stripBOM) (B.hGetContents h) + putStr :: String -> IO () putStr = B.putStr . fromString