@@ -39,21 +39,25 @@ module Text.Pandoc.UTF8 ( readFile
42+#if MIN_VERSION_base(4,5,0)
44+import Codec.Binary.UTF8.String (encodeString)
42#if MIN_VERSION_base(4,2,0)
47#if MIN_VERSION_base(4,2,0)
44import System.IO hiding (readFile, writeFile, getContents,
49import System.IO hiding (readFile, writeFile, getContents,
45 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
50 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
46import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
51import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
47−import Codec.Binary.UTF8.String (encodeString)
48import qualified System.IO as IO
52import qualified System.IO as IO
50readFile :: FilePath -> IO String
54readFile :: FilePath -> IO String
51readFile f = do
55readFile f = do
52− h <- openFile (encodeString f) ReadMode
56+ h <- openFile (encodePath f) ReadMode
53 hGetContents h
57 hGetContents h
55writeFile :: FilePath -> String -> IO ()
59writeFile :: FilePath -> String -> IO ()
56−writeFile f s = withFile (encodeString f) WriteMode $ \h -> hPutStr h s
60+writeFile f s = withFile (encodePath f) WriteMode $ \h -> hPutStr h s
58getContents :: IO String
62getContents :: IO String
59getContents = hGetContents stdin
63getContents = hGetContents stdin
@@ -76,7 +80,6 @@ hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
78import qualified Data.ByteString as B
82import qualified Data.ByteString as B
79−import Codec.Binary.UTF8.String (encodeString)
80import Data.ByteString.UTF8 (toString, fromString)
83import Data.ByteString.UTF8 (toString, fromString)
81import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
84import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
82import System.IO (Handle)
85import System.IO (Handle)
@@ -91,10 +94,10 @@ stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
91stripBOM s = s
94stripBOM s = s
93readFile :: FilePath -> IO String
96readFile :: FilePath -> IO String
94−readFile = liftM (toString . stripBOM) . B.readFile . encodeString
97+readFile = liftM (toString . stripBOM) . B.readFile . encodePath
96writeFile :: FilePath -> String -> IO ()
99writeFile :: FilePath -> String -> IO ()
97−writeFile f = B.writeFile (encodeString f) . fromString
100+writeFile f = B.writeFile (encodePath f) . fromString
99getContents :: IO String
102getContents :: IO String
100getContents = liftM (toString . stripBOM) B.getContents
103getContents = liftM (toString . stripBOM) B.getContents
@@ -115,3 +118,10 @@ hPutStrLn :: Handle -> String -> IO ()
115hPutStrLn h s = hPutStr h (s ++ "\n")
118hPutStrLn h s = hPutStr h (s ++ "\n")
122+encodePath :: FilePath -> FilePath
123+#if MIN_VERSION_base(4,5,0)
126+encodePath = encodeString