git.iko.soy/typeable/pandoc
on master help sign in
UTF8: Modified readFile and getContents to strip BOM if present.
7d20ffeJohn MacFarlane
src/Text/Pandoc/UTF8.hs+9−2
@@ -43,14 +43,21 @@ import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
43import System.IO (Handle)
43import System.IO (Handle)
44import Control.Monad (liftM)
44import Control.Monad (liftM)
45
45
46+bom :: B.ByteString
47+bom = B.pack [0xEF, 0xBB, 0xBF]
48+
49+stripBOM :: B.ByteString -> B.ByteString
50+stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
51+stripBOM s = s
52+
46readFile :: FilePath -> IO String
53readFile :: FilePath -> IO String
47−readFile = liftM toString . B.readFile
54+readFile = liftM (toString . stripBOM) . B.readFile
48
55
49writeFile :: FilePath -> String -> IO ()
56writeFile :: FilePath -> String -> IO ()
50writeFile f = B.writeFile f . fromString
57writeFile f = B.writeFile f . fromString
51
58
52getContents :: IO String
59getContents :: IO String
53−getContents = liftM toString B.getContents
60+getContents = liftM (toString . stripBOM) B.getContents
54
61
55putStr :: String -> IO ()
62putStr :: String -> IO ()
56putStr = B.putStr . fromString
63putStr = B.putStr . fromString