2006-08-24 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 24 Aug 2006 11:32:00 +0000 (11:32 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 24 Aug 2006 11:32:00 +0000 (11:32 -0000)
* Encoding.cs :
  Consider DecoderFallback and EncoderFallback in 2.0 Equals()
  and GetHashCode().
* UTF32Encoding.cs, UTF7Encoding.cs :
  Fixed GetHashCode() and Equals() as well.
  Added several missing overrides in 2.0.

svn path=/trunk/mcs/; revision=64299

mcs/class/corlib/System.Text/ChangeLog
mcs/class/corlib/System.Text/Encoding.cs
mcs/class/corlib/System.Text/UTF32Encoding.cs
mcs/class/corlib/System.Text/UTF7Encoding.cs

index b1a40f4712760f5bd5ef9e37fa2358397b705fe0..0a476340a1cdf7f06b2f0022b4b328f978357eea 100644 (file)
@@ -1,3 +1,12 @@
+2006-08-24  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Encoding.cs :
+         Consider DecoderFallback and EncoderFallback in 2.0 Equals()
+         and GetHashCode().
+       * UTF32Encoding.cs, UTF7Encoding.cs :
+         Fixed GetHashCode() and Equals() as well.
+         Added several missing overrides in 2.0.
+
 2006-08-24  Atsushi Enomoto  <atsushi@ximian.com>
 
        * Encoding.cs : implemented IsAlwaysNormalized().
index 70475e1ff80105443ebaffd66aa2e4847e922b4f..e1c0cc2f133afc742bf9285c3df880ac59cb39a7 100644 (file)
@@ -193,7 +193,13 @@ public abstract class Encoding
        {
                Encoding enc = (obj as Encoding);
                if (enc != null) {
+#if NET_2_0
+                       return codePage == enc.codePage &&
+                               DecoderFallback.Equals (enc.DecoderFallback) &&
+                               EncoderFallback.Equals (enc.EncoderFallback);
+#else
                        return (codePage == enc.codePage);
+#endif
                } else {
                        return false;
                }
@@ -688,7 +694,11 @@ public abstract class Encoding
        // Get a hash code for this instance.
        public override int GetHashCode ()
        {
+#if NET_2_0
+               return DecoderFallback.GetHashCode () << 24 + EncoderFallback.GetHashCode () << 16 + codePage;
+#else
                return codePage;
+#endif
        }
 
        // Get the maximum number of bytes needed to encode a
index 1cb055a4d47e3fdc7ed908975886c68e3e9af0bf..af678abf6a6fda4ab8eabfd2d3d5055ed6007c85 100644 (file)
@@ -340,7 +340,12 @@ public sealed class UTF32Encoding : Encoding
        // Get the hash code for this object.
        public override int GetHashCode ()
        {
-               return base.GetHashCode ();
+               int basis = base.GetHashCode ();
+               if (bigEndian)
+                       basis ^= 0x1F;
+               if (byteOrderMark)
+                       basis ^= 0x3F;
+               return basis;
        }
 
        // UTF32 decoder implementation.
@@ -478,7 +483,48 @@ public sealed class UTF32Encoding : Encoding
                return base.GetBytes (s);
        }
 #endif
-       
+
+#if NET_2_0
+       // a bunch of practically missing implementations (but should just work)
+
+       public override int GetByteCount (string s)
+       {
+               return base.GetByteCount (s);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetBytes (char *chars, int charCount, byte *bytes, int byteCount)
+       {
+               return base.GetBytes (chars, charCount, bytes, byteCount);
+       }
+
+       public override int GetBytes (string s, int charIndex, int charCount, byte [] bytes, int byteIndex)
+       {
+               return base.GetBytes (s, charIndex, charCount, bytes, byteIndex);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetCharCount (byte *bytes, int count)
+       {
+               return base.GetCharCount (bytes, count);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetChars (byte *bytes, int byteCount, char* chars, int charCount)
+       {
+               return base.GetChars (bytes, byteCount, chars, charCount);
+       }
+
+       public override string GetString (byte [] bytes, int index, int count)
+       {
+               return base.GetString (bytes, index, count);
+       }
+
+       public override Encoder GetEncoder ()
+       {
+               return base.GetEncoder ();
+       }
+#endif
 
 }; // class UTF32Encoding
 
index d6a4f20776652e2eed54caaf4f60d14c2faa9e37..376346b73aa25259843bb397557a8d1bd9e1eb7f 100644 (file)
@@ -109,6 +109,24 @@ class UTF7Encoding : Encoding
                windows_code_page = UnicodeEncoding.UNICODE_CODE_PAGE;
        }
 
+#if NET_2_0
+       public override int GetHashCode ()
+       {
+               int basis = base.GetHashCode ();
+               return allowOptionals ? -basis : basis;
+       }
+
+       public override bool Equals (object other)
+       {
+               UTF7Encoding e = other as UTF7Encoding;
+               if (e == null)
+                       return false;
+               return allowOptionals == e.allowOptionals &&
+                       EncoderFallback.Equals (e.EncoderFallback) &&
+                       DecoderFallback.Equals (e.DecoderFallback);
+       }
+#endif
+
        // Internal version of "GetByteCount" that can handle
        // a rolling state between calls.
        private static int InternalGetByteCount
@@ -654,6 +672,50 @@ class UTF7Encoding : Encoding
 
        } // class UTF7Encoder
 
+#if NET_2_0
+       // a bunch of practically missing implementations (but should just work)
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetByteCount (char *chars, int count)
+       {
+               return base.GetByteCount (chars, count);
+       }
+
+       public override int GetByteCount (string s)
+       {
+               return base.GetByteCount (s);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetBytes (char *chars, int charCount, byte* bytes, int byteCount)
+       {
+               return base.GetBytes (chars, charCount, bytes, byteCount);
+       }
+
+       public override int GetBytes (string s, int charIndex, int charCount, byte [] bytes, int byteIndex)
+       {
+               return base.GetBytes (s, charIndex, charCount, bytes, byteIndex);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetCharCount (byte *bytes, int count)
+       {
+               return base.GetCharCount (bytes, count);
+       }
+
+       [CLSCompliantAttribute (false)]
+       public override unsafe int GetChars (byte* bytes, int byteCount, char* chars, int charCount)
+       {
+               return base.GetChars (bytes, byteCount, chars, charCount);
+       }
+
+       public override string GetString (byte [] bytes, int index, int count)
+       {
+               return base.GetString (bytes, index, count);
+       }
+
+#endif
+
 }; // class UTF7Encoding
 
 }; // namespace System.Text