|Copyright||(c) 2009 2010 Bryan O'Sullivan
(c) 2009 Simon Marlow
Efficient locale-sensitive support for lazy text I/O.
Skip past the synopsis for some important notes on performance and portability across different versions of GHC.
The functions in this module obey the runtime system's locale, character set encoding, and line ending conversion settings.
If you know in advance that you will be working with data that has a specific encoding (e.g. UTF-8), and your application is highly performance sensitive, you may find that it is faster to perform I/O with bytestrings and to encode and decode yourself than to use the functions in this module.
Whether this will hold depends on the version of GHC you are using, the platform you are working on, the data you are working with, and the encodings you are using, so be sure to test for yourself.
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.Lazy as B import Data.Text.Lazy (Text) import Data.Text.Lazy.Encoding (encodeUtf16) putStr_Utf16LE :: Text -> IO () putStr_Utf16LE t = B.putStr (encodeUtf16LE t)
Read a file and return its contents as a string. The file is read lazily, as with
Write a string to a file. The file is truncated to zero length before writing begins.
Write a string the end of a file.
Read a single line from a handle.
Write a string to a handle.
Write a string to a handle, followed by a newline.
interact function takes a function of type
Text -> Text as its argument. The entire input from the standard input device is passed (lazily) to this function as its argument, and the resulting string is output on the standard output device.
Lazily read all user input on
stdin as a single string.
Read a single line of user input from
Write a string to
Write a string to
stdout, followed by a newline.
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).