Skip to content

Commit

Permalink
2006-04-13 Atsushi Enomoto <atsushi@ximian.com>
Browse files Browse the repository at this point in the history
        * ASCIIEncoding.cs : 2.0 decoder fallback support was missing.

        * ASCIIEncodingTest.cs : added DecoderFallback().


svn path=/trunk/mcs/; revision=59434
  • Loading branch information
atsushieno committed Apr 13, 2006
1 parent ea6506e commit 8e3081f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mcs/class/corlib/System.Text/ASCIIEncoding.cs
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions mcs/class/corlib/System.Text/ChangeLog
@@ -1,3 +1,7 @@
2006-04-13 Atsushi Enomoto <atsushi@ximian.com>

* ASCIIEncoding.cs : 2.0 decoder fallback support was missing.

2006-03-30 Atsushi Enomoto <atsushi@ximian.com>

* Encoder.cs, Decoder.cs : implemented Convert(). Also added argument
Expand Down
10 changes: 10 additions & 0 deletions mcs/class/corlib/Test/System.Text/ASCIIEncodingTest.cs
Expand Up @@ -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
}

}
4 changes: 4 additions & 0 deletions mcs/class/corlib/Test/System.Text/ChangeLog
@@ -1,3 +1,7 @@
2006-04-13 Atsushi Enomoto <atsushi@ximian.com>

* ASCIIEncodingTest.cs : added DecoderFallback().

2006-03-30 Atsushi Enomoto <atsushi@ximian.com>

* EncoderTest.cs, DecoderTest.cs : new tests, for Convert().
Expand Down

0 comments on commit 8e3081f

Please sign in to comment.