encoding-0.10.2: A library for various character encodings

Safe Haskell | None
Language | Haskell2010

System.IO.Encoding

Description

This module provides a replacement for the normal (unicode unaware) IO functions of haskell. By using implicit parameters, it can be used almost as a drop-in replacement. For example, consider the following simple echo program:

    main = do
      str <- getContents
      putStr str

To make this program process UTF-8 data, change the program to:

    {-# LANGUAGE ImplicitParams #-}

    import Prelude hiding (getContents,putStr)
    import System.IO.Encoding
    import Data.Encoding.UTF8

    main = do
      let ?enc = UTF8
      str <- getContents
      putStr str

Or, if you want to use the standard system encoding:

    {-# LANGUAGE ImplicitParams #-}

    import Prelude hiding (getContents,putStr)
    import System.IO.Encoding

    main = do
      e <- getSystemEncoding
      let ?enc = e
      str <- getContents
      putStr str

Synopsis

- getSystemEncoding :: IO (Maybe DynEncoding)
- getContents :: (Encoding e, ?enc :: e) => IO String
- putStr :: (Encoding e, ?enc :: e) => String -> IO ()
- putStrLn :: (Encoding e, ?enc :: e) => String -> IO ()
- hPutStr :: (Encoding e, ?enc :: e) => Handle -> String -> IO ()
- hPutStrLn :: (Encoding e, ?enc :: e) => Handle -> String -> IO ()
- hGetContents :: (Encoding e, ?enc :: e) => Handle -> IO String
- readFile :: (Encoding e, ?enc :: e) => FilePath -> IO String
- writeFile :: (Encoding e, ?enc :: e) => FilePath -> String -> IO ()
- appendFile :: (Encoding e, ?enc :: e) => FilePath -> String -> IO ()
- getChar :: (Encoding e, ?enc :: e) => IO Char
- hGetChar :: (Encoding e, ?enc :: e) => Handle -> IO Char
- getLine :: (Encoding e, ?enc :: e) => IO String
- hGetLine :: (Encoding e, ?enc :: e) => Handle -> IO String
- putChar :: (Encoding e, ?enc :: e) => Char -> IO ()
- hPutChar :: (Encoding e, ?enc :: e) => Handle -> Char -> IO ()
- interact :: (Encoding e, ?enc :: e) => (String -> String) -> IO ()
- print :: (Encoding e, Show a, ?enc :: e) => a -> IO ()
- hPrint :: (Encoding e, Show a, ?enc :: e) => Handle -> a -> IO ()

# Documentation

getSystemEncoding :: IO (Maybe DynEncoding) Source #

On unix machines, returns the system's currently configured text encoding, or Nothing if there was an error. On Windows, currently always returns Nothing.

getContents :: (Encoding e, ?enc :: e) => IO String Source #

putStr :: (Encoding e, ?enc :: e) => String -> IO () Source #

putStrLn :: (Encoding e, ?enc :: e) => String -> IO () Source #

hPutStr :: (Encoding e, ?enc :: e) => Handle -> String -> IO () Source #

Like the normal `hPutStr`, but encodes the output using an encoding.

hPutStrLn :: (Encoding e, ?enc :: e) => Handle -> String -> IO () Source #

hGetContents :: (Encoding e, ?enc :: e) => Handle -> IO String Source #

Like the normal `hGetContents`, but decodes the input using an encoding.

readFile :: (Encoding e, ?enc :: e) => FilePath -> IO String Source #

writeFile :: (Encoding e, ?enc :: e) => FilePath -> String -> IO () Source #

appendFile :: (Encoding e, ?enc :: e) => FilePath -> String -> IO () Source #

getChar :: (Encoding e, ?enc :: e) => IO Char Source #

hGetChar :: (Encoding e, ?enc :: e) => Handle -> IO Char Source #

getLine :: (Encoding e, ?enc :: e) => IO String Source #

hGetLine :: (Encoding e, ?enc :: e) => Handle -> IO String Source #

putChar :: (Encoding e, ?enc :: e) => Char -> IO () Source #

hPutChar :: (Encoding e, ?enc :: e) => Handle -> Char -> IO () Source #

interact :: (Encoding e, ?enc :: e) => (String -> String) -> IO () Source #

print :: (Encoding e, Show a, ?enc :: e) => a -> IO () Source #

hPrint :: (Encoding e, Show a, ?enc :: e) => Handle -> a -> IO () Source #