git.iko.soy/typeable/pandoc
on master help sign in
UTF8: Modified readFile and getContents to strip BOM if present.
commit7d20ffe3e0192d9a8c4cc476a21e5060d601de65 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 6 May 2010, 23:04 (16 years ago) parentfb201a5
1 file changed+9−2
src/Text/Pandoc/UTF8.hs+9−2
src/Text/Pandoc/UTF8.hs+9−2
@@ -43,14 +43,21 @@ import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
4343import System.IO (Handle)
4444import Control.Monad (liftM)
4545
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+
4653readFile :: FilePath -> IO String
47−readFile = liftM toString . B.readFile
54+readFile = liftM (toString . stripBOM) . B.readFile
4855
4956writeFile :: FilePath -> String -> IO ()
5057writeFile f = B.writeFile f . fromString
5158
5259getContents :: IO String
53−getContents = liftM toString B.getContents
60+getContents = liftM (toString . stripBOM) B.getContents
5461
5562putStr :: String -> IO ()
5663putStr = B.putStr . fromString