X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FIO%2FEncoding.hs;h=44cdd86d7ef5c1a8528a4d2ddb0f65a18e115aa2;hb=595f2cbc9072003f4e86dab6d1c9a408d388f3b7;hp=a1da1b1b21986879f3416d7c624f9a11f2ad6d53;hpb=1bf6eeca9b174c5d9522a551e58daad6895faab7;p=ghc-base.git diff --git a/GHC/IO/Encoding.hs b/GHC/IO/Encoding.hs index a1da1b1..44cdd86 100644 --- a/GHC/IO/Encoding.hs +++ b/GHC/IO/Encoding.hs @@ -1,4 +1,4 @@ -{-# OPTIONS_GHC -fno-implicit-prelude -funbox-strict-fields #-} +{-# OPTIONS_GHC -XNoImplicitPrelude -funbox-strict-fields #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.IO.Encoding @@ -30,6 +30,9 @@ import GHC.IO.Encoding.Types import GHC.Word #if !defined(mingw32_HOST_OS) import qualified GHC.IO.Encoding.Iconv as Iconv +#else +import qualified GHC.IO.Encoding.CodePage as CodePage +import Text.Read (reads) #endif import qualified GHC.IO.Encoding.Latin1 as Latin1 import qualified GHC.IO.Encoding.UTF8 as UTF8 @@ -96,14 +99,34 @@ localeEncoding :: TextEncoding #if !defined(mingw32_HOST_OS) localeEncoding = Iconv.localeEncoding #else -localeEncoding = Latin1.latin1 +localeEncoding = CodePage.localeEncoding #endif -- | Look up the named Unicode encoding. May fail with -- -- * 'isDoesNotExistError' if the encoding is unknown -- --- The set of known encodings is system-dependent. +-- The set of known encodings is system-dependent, but includes at least: +-- +-- * @UTF-8@ +-- +-- * @UTF-16@, @UTF-16BE@, @UTF-16LE@ +-- +-- * @UTF-32@, @UTF-32BE@, @UTF-32LE@ +-- +-- On systems using GNU iconv (e.g. Linux), there is additional +-- notation for specifying how illegal characters are handled: +-- +-- * a suffix of @\/\/IGNORE@, e.g. @UTF-8\/\/IGNORE@, will cause +-- all illegal sequences on input to be ignored, and on output +-- will drop all code points that have no representation in the +-- target encoding. +-- +-- * a suffix of @\/\/TRANSLIT@ will choose a replacement character +-- for illegal sequences or code points. +-- +-- On Windows, you can access supported code pages with the prefix +-- @CP@; for example, @\"CP1250\"@. -- mkTextEncoding :: String -> IO TextEncoding #if !defined(mingw32_HOST_OS) @@ -116,6 +139,8 @@ mkTextEncoding "UTF-16BE" = return utf16be mkTextEncoding "UTF-32" = return utf32 mkTextEncoding "UTF-32LE" = return utf32le mkTextEncoding "UTF-32BE" = return utf32be +mkTextEncoding ('C':'P':n) + | [(cp,"")] <- reads n = return $ CodePage.codePageEncoding cp mkTextEncoding e = ioException (IOError Nothing NoSuchThing "mkTextEncoding" ("unknown encoding:" ++ e) Nothing Nothing)