summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/UTF8.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-05-06 23:04:44 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2010-05-06 23:04:44 -0700
commit7d20ffe3e0192d9a8c4cc476a21e5060d601de65 (patch)
tree59f996828267be2758f98f17657766b78b081066 /src/Text/Pandoc/UTF8.hs
parentfb201a5b46bb49aa57a8462d7ded8ea2ff76be81 (diff)
UTF8: Modified readFile and getContents to strip BOM if present.
Diffstat (limited to 'src/Text/Pandoc/UTF8.hs')
-rw-r--r--src/Text/Pandoc/UTF8.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/UTF8.hs b/src/Text/Pandoc/UTF8.hs
index fb912a373..3dd61176c 100644
--- a/src/Text/Pandoc/UTF8.hs
+++ b/src/Text/Pandoc/UTF8.hs
@@ -43,14 +43,21 @@ import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
import System.IO (Handle)
import Control.Monad (liftM)
+bom :: B.ByteString
+bom = B.pack [0xEF, 0xBB, 0xBF]
+
+stripBOM :: B.ByteString -> B.ByteString
+stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
+stripBOM s = s
+
readFile :: FilePath -> IO String
-readFile = liftM toString . B.readFile
+readFile = liftM (toString . stripBOM) . B.readFile
writeFile :: FilePath -> String -> IO ()
writeFile f = B.writeFile f . fromString
getContents :: IO String
-getContents = liftM toString B.getContents
+getContents = liftM (toString . stripBOM) B.getContents
putStr :: String -> IO ()
putStr = B.putStr . fromString