@@ -39,21 +39,25 @@ module Text.Pandoc.UTF8 ( readFile
3939
4040where
4141
42+#if MIN_VERSION_base(4,5,0)
43+#else
44+import Codec.Binary.UTF8.String (encodeString)
45+#endif
46+
4247#if MIN_VERSION_base(4,2,0)
4348
4449import System.IO hiding (readFile, writeFile, getContents,
4550 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
4651import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
47−import Codec.Binary.UTF8.String (encodeString)
4852import qualified System.IO as IO
4953
5054readFile :: FilePath -> IO String
5155readFile f = do
52− h <- openFile (encodeString f) ReadMode
56+ h <- openFile (encodePath f) ReadMode
5357 hGetContents h
5458
5559writeFile :: 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
5761
5862getContents :: IO String
5963getContents = hGetContents stdin
@@ -76,7 +80,6 @@ hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
7680#else
7781
7882import qualified Data.ByteString as B
79−import Codec.Binary.UTF8.String (encodeString)
8083import Data.ByteString.UTF8 (toString, fromString)
8184import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
8285import System.IO (Handle)
@@ -91,10 +94,10 @@ stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
9194stripBOM s = s
9295
9396readFile :: FilePath -> IO String
94−readFile = liftM (toString . stripBOM) . B.readFile . encodeString
97+readFile = liftM (toString . stripBOM) . B.readFile . encodePath
9598
9699writeFile :: FilePath -> String -> IO ()
97−writeFile f = B.writeFile (encodeString f) . fromString
100+writeFile f = B.writeFile (encodePath f) . fromString
98101
99102getContents :: IO String
100103getContents = liftM (toString . stripBOM) B.getContents
@@ -115,3 +118,10 @@ hPutStrLn :: Handle -> String -> IO ()
115118hPutStrLn h s = hPutStr h (s ++ "\n")
116119
117120#endif
121+
122+encodePath :: FilePath -> FilePath
123+#if MIN_VERSION_base(4,5,0)
124+encodePath = id
125+#else
126+encodePath = encodeString
127+#endif