diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-05-06 23:04:44 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-05-06 23:04:44 -0700 |
commit | 7d20ffe3e0192d9a8c4cc476a21e5060d601de65 (patch) | |
tree | 59f996828267be2758f98f17657766b78b081066 | |
parent | fb201a5b46bb49aa57a8462d7ded8ea2ff76be81 (diff) | |
download | pandoc-7d20ffe3e0192d9a8c4cc476a21e5060d601de65.tar.gz |
UTF8: Modified readFile and getContents to strip BOM if present.
-rw-r--r-- | src/Text/Pandoc/UTF8.hs | 11 |
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 |