Clean up CharsetDecoder and CharsetEncoder.

This patch also fixes a few bugs, and a few test bugs, and then the bugs
exposed by fixing those tests.

(cherry picked from commit 6ad37f500b023ef09fd177ad8cd8e2ba0b842cae)

Change-Id: Ia58d30e414cc59c27a1d259e8056523d6df2c6bc
8 files changed