git.iko.soy/typeable/pandoc
on master help sign in
UTF8 module: Remove `\r` when reading.

This should prevent problems with extra CRs on windows.

commitc7f4333f83b7441ad9a3a43c798b8f029670ffa3 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 6 Jan 2013, 16:35 (14 years ago) parentf779411
1 file changed+7−4
src/Text/Pandoc/UTF8.hs+7−4
src/Text/Pandoc/UTF8.hs+7−4
@@ -56,7 +56,6 @@ import qualified Data.Text.Encoding as T
5656import qualified Data.Text as T
5757import qualified Data.Text.Lazy as TL
5858import qualified Data.Text.Lazy.Encoding as TL
59−import Data.Text.Encoding.Error
6059
6160readFile :: FilePath -> IO String
6261readFile f = do
@@ -82,19 +81,23 @@ hPutStrLn :: Handle -> String -> IO ()
8281hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
8382
8483hGetContents :: Handle -> IO String
85−hGetContents h = fmap (TL.unpack . TL.decodeUtf8) $ BL.hGetContents h
84+hGetContents = fmap toStringLazy . BL.hGetContents
8685-- hGetContents h = hSetEncoding h utf8_bom
8786-- >> hSetNewlineMode h universalNewlineMode
8887-- >> IO.hGetContents h
8988
89+-- | Convert UTF8-encoded ByteString to String, also
90+-- removing '\r' characters.
9091toString :: B.ByteString -> String
91−toString = T.unpack . T.decodeUtf8With lenientDecode
92+toString = filter (/='\r') . T.unpack . T.decodeUtf8
9293
9394fromString :: String -> B.ByteString
9495fromString = T.encodeUtf8 . T.pack
9596
97+-- | Convert UTF8-encoded ByteString to String, also
98+-- removing '\r' characters.
9699toStringLazy :: BL.ByteString -> String
97−toStringLazy = TL.unpack . TL.decodeUtf8With lenientDecode
100+toStringLazy = filter (/='\r') . TL.unpack . TL.decodeUtf8
98101
99102fromStringLazy :: String -> BL.ByteString
100103fromStringLazy = TL.encodeUtf8 . TL.pack