git.iko.soy/typeable/pandoc
on master help sign in
UTF8: Better error message for invalid UTF8.
c80ffe9John MacFarlane
src/Text/Pandoc/UTF8.hs+6−4
@@ -52,7 +52,8 @@ import Codec.Binary.UTF8.String (encodeString, decodeString)
52
52
53import System.IO hiding (readFile, writeFile, getContents,
53import System.IO hiding (readFile, writeFile, getContents,
54 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
54 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
55−import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
55+import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn,
56+ catch)
56import qualified System.IO as IO
57import qualified System.IO as IO
57import qualified Data.ByteString.Char8 as B
58import qualified Data.ByteString.Char8 as B
58import qualified Data.ByteString.Lazy as BL
59import qualified Data.ByteString.Lazy as BL
@@ -86,9 +87,10 @@ hPutStrLn :: Handle -> String -> IO ()
86hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
87hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
87
88
88hGetContents :: Handle -> IO String
89hGetContents :: Handle -> IO String
90+hGetContents h = fmap (TL.unpack . TL.decodeUtf8) $ BL.hGetContents h
89−hGetContents h = hSetEncoding h utf8_bom
91+-- hGetContents h = hSetEncoding h utf8_bom
90− >> hSetNewlineMode h universalNewlineMode
92+-- >> hSetNewlineMode h universalNewlineMode
91− >> IO.hGetContents h
93+-- >> IO.hGetContents h
92
94
93toString :: B.ByteString -> String
95toString :: B.ByteString -> String
94toString = T.unpack . T.decodeUtf8With lenientDecode
96toString = T.unpack . T.decodeUtf8With lenientDecode