| |||||||||||||||||||||||
| |||||||||||||||||||||||
| |||||||||||||||||||||||
Description | |||||||||||||||||||||||
Efficient locale-sensitive support for text I/O. | |||||||||||||||||||||||
Synopsis | |||||||||||||||||||||||
| |||||||||||||||||||||||
Locale support | |||||||||||||||||||||||
Note: The behaviour of functions in this module depends on the version of GHC you are using. Beginning with GHC 6.12, text I/O is performed using the system or handle's current locale and line ending conventions. Under GHC 6.10 and earlier, the system I/O libraries do not support locale-sensitive I/O or line ending conversion. On these versions of GHC, functions in this library all use UTF-8. What does this mean in practice?
If you must use a non-UTF-8 locale on an older version of GHC, you will have to perform the transcoding yourself, e.g. as follows: import qualified Data.ByteString as B import Data.Text (Text) import Data.Text.Encoding (encodeUtf16) putStr_Utf16LE :: Text -> IO () putStr_Utf16LE t = B.putStr (encodeUtf16LE t) | |||||||||||||||||||||||
readFile :: FilePath -> IO Text | |||||||||||||||||||||||
The readFile function reads a file and returns the contents of the file as a string. The entire file is read strictly, as with getContents. | |||||||||||||||||||||||
writeFile :: FilePath -> Text -> IO () | |||||||||||||||||||||||
Write a string to a file. The file is truncated to zero length before writing begins. | |||||||||||||||||||||||
appendFile :: FilePath -> Text -> IO () | |||||||||||||||||||||||
Write a string the end of a file. | |||||||||||||||||||||||
Operations on handles | |||||||||||||||||||||||
hGetContents :: Handle -> IO Text | |||||||||||||||||||||||
Read the remaining contents of a Handle as a string. The Handle is closed once the contents have been read, or if an exception is thrown. Internally, this function reads a chunk at a time from the lower-level buffering abstraction, and concatenates the chunks into a single string once the entire file has been read. As a result, it requires approximately twice as much memory as its result to construct its result. For files more than a half of available RAM in size, this may result in memory exhaustion. | |||||||||||||||||||||||
hGetLine :: Handle -> IO Text | |||||||||||||||||||||||
Read a single line from a handle. | |||||||||||||||||||||||
hPutStr :: Handle -> Text -> IO () | |||||||||||||||||||||||
Write a string to a handle. | |||||||||||||||||||||||
hPutStrLn :: Handle -> Text -> IO () | |||||||||||||||||||||||
Write a string to a handle, followed by a newline. | |||||||||||||||||||||||
Special cases for standard input and output | |||||||||||||||||||||||
interact :: (Text -> Text) -> IO () | |||||||||||||||||||||||
The interact function takes a function of type Text -> Text as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device. | |||||||||||||||||||||||
getContents :: IO Text | |||||||||||||||||||||||
Read all user input on stdin as a single string. | |||||||||||||||||||||||
getLine :: IO Text | |||||||||||||||||||||||
Read a single line of user input from stdin. | |||||||||||||||||||||||
putStr :: Text -> IO () | |||||||||||||||||||||||
Write a string to stdout. | |||||||||||||||||||||||
putStrLn :: Text -> IO () | |||||||||||||||||||||||
Write a string to stdout, followed by a newline. | |||||||||||||||||||||||
Produced by Haddock version 2.7.2 |