~ubuntu-branches/ubuntu/raring/agda/raring-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Utils/IO.hs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-07-20 19:49:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090720194941-hcjy91vrn16csh7d
Tags: upstream-2.2.4+dfsg
ImportĀ upstreamĀ versionĀ 2.2.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Agda.Utils.IO
 
2
  ( readBinaryFile'
 
3
  , readTextFile
 
4
  , module System.IO.UTF8
 
5
  ) where
 
6
 
 
7
import System.IO.UTF8
 
8
import qualified System.IO.UTF8 as UTF8
 
9
import qualified System.IO as IO
 
10
import qualified Data.ByteString.Lazy as BS
 
11
import Control.Applicative
 
12
 
 
13
import Agda.Utils.Unicode
 
14
 
 
15
-- | Returns a close function for the file together with the contents.
 
16
 
 
17
readBinaryFile' :: FilePath -> IO (BS.ByteString, IO ())
 
18
readBinaryFile' file = do
 
19
    h <- IO.openBinaryFile file IO.ReadMode
 
20
    s <- BS.hGetContents h
 
21
    return (s, IO.hClose h)
 
22
 
 
23
-- | Reads a UTF8-encoded file in binary mode and converts all Unicode
 
24
-- line endings into '\n'.
 
25
 
 
26
readTextFile :: FilePath -> IO String
 
27
readTextFile file = convertLineEndings <$> UTF8.readFile file