@@ -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