Save and restore the codec state when re-decoding
authorSimon Marlow <marlowsd@gmail.com>
Sun, 14 Jun 2009 18:53:32 +0000 (18:53 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Sun, 14 Jun 2009 18:53:32 +0000 (18:53 +0000)
commitccc931d0905f6e0d55cb90b045881d4515112411
tree2d435eb791898082bd55b1582e0f8eecb9479a88
parent049f089928e25a3b9ea297c0c0936b2e6bc7a508
Save and restore the codec state when re-decoding

We previously had an ugly hack to check for a BOM when re-decoding
some binary data in flushCharBuffer.  The hack was there essentially
because codecs like UTF-16 have a state, and we had not restored it.
This patch gives codecs an explicit state, and implemented
saving/restoring of the state as necessary.  Hence, the hack in
flushCharBuffer is replaced by a more general mechanism that works for
any codec with state.

Unfortunately, iconv doesn't give us a way to save and restore the
state, so this is currently only implemented for the built-in codecs.
GHC/IO/Encoding/Iconv.hs
GHC/IO/Encoding/Latin1.hs
GHC/IO/Encoding/Types.hs
GHC/IO/Encoding/UTF16.hs
GHC/IO/Encoding/UTF32.hs
GHC/IO/Encoding/UTF8.hs
GHC/IO/Handle.hs
GHC/IO/Handle/Internals.hs
GHC/IO/Handle/Types.hs