UTF8 module: Remove \r
when reading.
This should prevent problems with extra CRs on windows.
This commit is contained in:
parent
f779411fe2
commit
c7f4333f83
1 changed files with 7 additions and 4 deletions
|
@ -56,7 +56,6 @@ import qualified Data.Text.Encoding as T
|
|||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Lazy as TL
|
||||
import qualified Data.Text.Lazy.Encoding as TL
|
||||
import Data.Text.Encoding.Error
|
||||
|
||||
readFile :: FilePath -> IO String
|
||||
readFile f = do
|
||||
|
@ -82,19 +81,23 @@ hPutStrLn :: Handle -> String -> IO ()
|
|||
hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
|
||||
|
||||
hGetContents :: Handle -> IO String
|
||||
hGetContents h = fmap (TL.unpack . TL.decodeUtf8) $ BL.hGetContents h
|
||||
hGetContents = fmap toStringLazy . BL.hGetContents
|
||||
-- hGetContents h = hSetEncoding h utf8_bom
|
||||
-- >> hSetNewlineMode h universalNewlineMode
|
||||
-- >> IO.hGetContents h
|
||||
|
||||
-- | Convert UTF8-encoded ByteString to String, also
|
||||
-- removing '\r' characters.
|
||||
toString :: B.ByteString -> String
|
||||
toString = T.unpack . T.decodeUtf8With lenientDecode
|
||||
toString = filter (/='\r') . T.unpack . T.decodeUtf8
|
||||
|
||||
fromString :: String -> B.ByteString
|
||||
fromString = T.encodeUtf8 . T.pack
|
||||
|
||||
-- | Convert UTF8-encoded ByteString to String, also
|
||||
-- removing '\r' characters.
|
||||
toStringLazy :: BL.ByteString -> String
|
||||
toStringLazy = TL.unpack . TL.decodeUtf8With lenientDecode
|
||||
toStringLazy = filter (/='\r') . TL.unpack . TL.decodeUtf8
|
||||
|
||||
fromStringLazy :: String -> BL.ByteString
|
||||
fromStringLazy = TL.encodeUtf8 . TL.pack
|
||||
|
|
Loading…
Reference in a new issue