Commit 881ba6be authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Refactor some use-sites of `{to,from}UTF8` to use `{to,From}UTF8LBS`

parent 0763b05a
......@@ -94,7 +94,7 @@ import System.Directory
import System.FilePath
( (<.>), splitFileName )
import System.IO
( openBinaryFile, withFile, withBinaryFile
( withFile, withBinaryFile
, openBinaryTempFileWithDefaultPermissions
, IOMode(ReadMode), hGetContents, hClose )
import qualified Control.Exception as Exception
......@@ -246,8 +246,7 @@ startsWithBOM _ = False
-- | Check whether a file has Unicode byte order mark (BOM).
fileHasBOM :: FilePath -> NoCallStackIO Bool
fileHasBOM f = fmap (startsWithBOM . fromUTF8)
. hGetContents =<< openBinaryFile f ReadMode
fileHasBOM f = (startsWithBOM . fromUTF8LBS) <$> BS.readFile f
-- | Ignore a Unicode byte order mark (BOM) at the beginning of the input
--
......@@ -260,8 +259,7 @@ ignoreBOM string = string
-- Reads lazily using ordinary 'readFile'.
--
readUTF8File :: FilePath -> NoCallStackIO String
readUTF8File f = fmap (ignoreBOM . fromUTF8)
. hGetContents =<< openBinaryFile f ReadMode
readUTF8File f = (ignoreBOM . fromUTF8LBS) <$> BS.readFile f
-- | Reads a UTF8 encoded text file as a Unicode String
--
......@@ -270,7 +268,7 @@ readUTF8File f = fmap (ignoreBOM . fromUTF8)
withUTF8FileContents :: FilePath -> (String -> IO a) -> IO a
withUTF8FileContents name action =
withBinaryFile name ReadMode
(\hnd -> hGetContents hnd >>= action . ignoreBOM . fromUTF8)
(\hnd -> BS.hGetContents hnd >>= action . ignoreBOM . fromUTF8LBS)
-- | Writes a Unicode String as a UTF8 encoded text file.
--
......
......@@ -81,7 +81,7 @@ import Distribution.ParseUtils
import Distribution.PackageDescription.Parse
( parseGenericPackageDescription )
import Distribution.Simple.Utils
( fromUTF8, ignoreBOM )
( fromUTF8LBS, ignoreBOM )
import qualified Distribution.PackageDescription.Parse as PackageDesc.Parse
#endif
......@@ -477,8 +477,7 @@ extractPkg verbosity entry blockNo = case Tar.entryContent entry of
Nothing -> error $ "Couldn't read cabal file "
++ show fileName
#else
parsed = parseGenericPackageDescription . ignoreBOM . fromUTF8 . BS.Char8.unpack
$ content
parsed = parseGenericPackageDescription . ignoreBOM . fromUTF8LBS $ content
descr = case parsed of
ParseOk _ d -> d
_ -> error $ "Couldn't read cabal file "
......@@ -746,7 +745,7 @@ packageListFromCache verbosity mkPkg hnd Cache{..} mode = accum mempty [] mempty
Just gpd -> return gpd
Nothing -> interror "failed to parse .cabal file"
#else
case parseGenericPackageDescription . ignoreBOM . fromUTF8 . BS.Char8.unpack $ content of
case parseGenericPackageDescription . ignoreBOM . fromUTF8LBS $ content of
ParseOk _ d -> return d
_ -> interror "failed to parse .cabal file"
#endif
......
......@@ -98,8 +98,7 @@ import Distribution.PackageDescription.Parsec
import Distribution.PackageDescription.Parse
( readGenericPackageDescription, parseGenericPackageDescription, ParseResult(..) )
import Distribution.Simple.Utils
( fromUTF8, ignoreBOM )
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
( fromUTF8LBS, ignoreBOM )
#endif
-- import Data.List ( find, nub )
......@@ -563,7 +562,7 @@ readPackageTarget verbosity = traverse modifyLocation
parseGenericPackageDescriptionMaybe (BS.toStrict bs)
#else
parsePackageDescription' content =
case parseGenericPackageDescription . ignoreBOM . fromUTF8 . BS.Char8.unpack $ content of
case parseGenericPackageDescription . ignoreBOM . fromUTF8LBS $ content of
ParseOk _ pkg -> Just pkg
_ -> Nothing
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment