diff --git a/mcs/class/corlib/System.Text/ASCIIEncoding.cs b/mcs/class/corlib/System.Text/ASCIIEncoding.cs index b2d2801c43479..933c22c4b4858 100644 --- a/mcs/class/corlib/System.Text/ASCIIEncoding.cs +++ b/mcs/class/corlib/System.Text/ASCIIEncoding.cs @@ -223,6 +223,18 @@ public override int GetCharCount (byte[] bytes, int index, int count) // Get the characters that result from decoding a byte buffer. public override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { +#if NET_2_0 +// well, yes, I know this #if is ugly, but I think it is the simplest switch. + DecoderFallbackBuffer buffer = null; + return GetChars (bytes, byteIndex, byteCount, chars, + charIndex, ref buffer); + } + + int GetChars (byte[] bytes, int byteIndex, int byteCount, + char[] chars, int charIndex, + ref DecoderFallbackBuffer buffer) + { +#endif if (bytes == null) throw new ArgumentNullException ("bytes"); if (chars == null) @@ -242,8 +254,17 @@ public override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] char c = (char) bytes [byteIndex++]; if (c < '\x80') chars [charIndex++] = c; - else + else { +#if NET_2_0 + if (buffer == null) + buffer = DecoderFallback.CreateFallbackBuffer (); + buffer.Fallback (bytes, byteIndex); + while (buffer.Remaining > 0) + chars [charIndex++] = buffer.GetNextChar (); +#else chars [charIndex++] = '?'; +#endif + } } return byteCount; } diff --git a/mcs/class/corlib/System.Text/ChangeLog b/mcs/class/corlib/System.Text/ChangeLog index db76dffc5eed2..500695715ffb3 100644 --- a/mcs/class/corlib/System.Text/ChangeLog +++ b/mcs/class/corlib/System.Text/ChangeLog @@ -1,3 +1,7 @@ +2006-04-13 Atsushi Enomoto + + * ASCIIEncoding.cs : 2.0 decoder fallback support was missing. + 2006-03-30 Atsushi Enomoto * Encoder.cs, Decoder.cs : implemented Convert(). Also added argument diff --git a/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs b/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs index e848ac8261caf..11a6065ab399a 100644 --- a/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs +++ b/mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs @@ -171,6 +171,16 @@ public void TestZero () AssertEquals ("#02", encoding.GetString (new byte [0], 0, 0), ""); } +#if NET_2_0 + [Test] + [ExpectedException (typeof (DecoderFallbackException))] + public void DecoderFallback () + { + Encoding e = Encoding.ASCII.Clone () as Encoding; + e.DecoderFallback = new DecoderExceptionFallback (); + e.GetChars (new byte [] {0x80}); + } +#endif } } diff --git a/mcs/class/corlib/Test/System.Text/ChangeLog b/mcs/class/corlib/Test/System.Text/ChangeLog index f495f5c30b29f..a3eeeb6e02b83 100644 --- a/mcs/class/corlib/Test/System.Text/ChangeLog +++ b/mcs/class/corlib/Test/System.Text/ChangeLog @@ -1,3 +1,7 @@ +2006-04-13 Atsushi Enomoto + + * ASCIIEncodingTest.cs : added DecoderFallback(). + 2006-03-30 Atsushi Enomoto * EncoderTest.cs, DecoderTest.cs : new tests, for Convert().