@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 Stability : alpha
25 Stability : alpha
26 Portability : portable
26 Portability : portable
28−UTF-8 aware string IO functions that will work with GHC 6.10 or 6.12.
28+UTF-8 aware string IO functions that will work with GHC 6.10, 6.12, or 7.
30module Text.Pandoc.UTF8 ( readFile
30module Text.Pandoc.UTF8 ( readFile
31 , writeFile
31 , writeFile
@@ -34,9 +34,46 @@ module Text.Pandoc.UTF8 ( readFile
34 , putStrLn
34 , putStrLn
36 , hPutStrLn
36 , hPutStrLn
42+#ifdef MIN_VERSION_base(4,2,0)
44+import System.IO hiding (readFile, writeFile, getContents,
45+ putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
46+import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
47+import qualified System.IO as IO
49+readFile :: FilePath -> IO String
51+ h <- openFile f ReadMode
54+writeFile :: FilePath -> String -> IO ()
55+writeFile f s = withFile f WriteMode $ \h -> hPutStr h s
57+getContents :: IO String
58+getContents = hGetContents stdin
60+putStr :: String -> IO ()
61+putStr s = hPutStr stdout s
63+putStrLn :: String -> IO ()
64+putStrLn s = hPutStrLn stdout s
66+hPutStr :: Handle -> String -> IO ()
67+hPutStr h s = hSetEncoding h utf8 >> IO.hPutStr h s
69+hPutStrLn :: Handle -> String -> IO ()
70+hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
72+hGetContents :: Handle -> IO String
73+hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
40import qualified Data.ByteString as B
77import qualified Data.ByteString as B
41import Codec.Binary.UTF8.String (encodeString)
78import Codec.Binary.UTF8.String (encodeString)
42import Data.ByteString.UTF8 (toString, fromString)
79import Data.ByteString.UTF8 (toString, fromString)
@@ -44,6 +81,7 @@ import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
44import System.IO (Handle)
81import System.IO (Handle)
45import Control.Monad (liftM)
82import Control.Monad (liftM)
47bom :: B.ByteString
85bom :: B.ByteString
48bom = B.pack [0xEF, 0xBB, 0xBF]
86bom = B.pack [0xEF, 0xBB, 0xBF]
@@ -60,6 +98,9 @@ writeFile f = B.writeFile (encodeString f) . fromString
60getContents :: IO String
98getContents :: IO String
61getContents = liftM (toString . stripBOM) B.getContents
99getContents = liftM (toString . stripBOM) B.getContents
101+hGetContents :: Handle -> IO String
102+hGetContents h = liftM (toString . stripBOM) (B.hGetContents h)
63putStr :: String -> IO ()
104putStr :: String -> IO ()
64putStr = B.putStr . fromString
105putStr = B.putStr . fromString
@@ -71,3 +112,5 @@ hPutStr h = B.hPutStr h . fromString
72hPutStrLn :: Handle -> String -> IO ()
113hPutStrLn :: Handle -> String -> IO ()
73hPutStrLn h s = hPutStr h (s ++ "\n")
114hPutStrLn h s = hPutStr h (s ++ "\n")