Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / corlib / System.Text / UTF32Encoding.cs
index af678abf6a6fda4ab8eabfd2d3d5055ed6007c85..16413e8ad578a703c747aabed5bd206b6c0e0c2c 100644 (file)
@@ -31,8 +31,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#if NET_2_0
-
 namespace System.Text
 {
 
@@ -59,30 +57,28 @@ public sealed class UTF32Encoding : Encoding
        {
        }
 
-       public UTF32Encoding (bool bigEndian, bool byteOrderMark, bool throwOnInvalid)
+       public UTF32Encoding (bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters)
                : base ((bigEndian ? BIG_UTF32_CODE_PAGE : UTF32_CODE_PAGE))
        {
                this.bigEndian = bigEndian;
                this.byteOrderMark = byteOrderMark;
 
-               if (throwOnInvalid)
+               if (throwOnInvalidCharacters)
                        SetFallbackInternal (EncoderFallback.ExceptionFallback,
                                DecoderFallback.ExceptionFallback);
                else
-                       SetFallbackInternal (EncoderFallback.ReplacementFallback,
-                               DecoderFallback.ReplacementFallback);
+                       SetFallbackInternal (new EncoderReplacementFallback ("\uFFFD"),
+                               new DecoderReplacementFallback ("\uFFFD"));
 
                if (bigEndian){
                        body_name = "utf-32BE";
                        encoding_name = "UTF-32 (Big-Endian)";
                        header_name = "utf-32BE";
-                       is_browser_save = false;
                        web_name = "utf-32BE";
                } else {
                        body_name = "utf-32";
                        encoding_name = "UTF-32";
                        header_name = "utf-32";
-                       is_browser_save = true;
                        web_name = "utf-32";
                }
                
@@ -105,7 +101,7 @@ public sealed class UTF32Encoding : Encoding
                        throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
                }
                int ret = 0;
-               for (int i = index; i < count; i++) {
+               for (int i = index; i < index + count; i++) {
                        if (Char.IsSurrogate (chars [i])) {
                                if (i + 1 < chars.Length && Char.IsSurrogate (chars [i + 1]))
                                        ret += 4;
@@ -309,18 +305,18 @@ public sealed class UTF32Encoding : Encoding
        public override byte[] GetPreamble ()
        {
                if (byteOrderMark) {
-                       byte[] preamble = new byte[2];
+                       byte[] preamble = new byte[4];
                        if (bigEndian) {
-                               preamble[0] = (byte)0xFE;
-                               preamble[1] = (byte)0xFF;
+                               preamble[2] = (byte)0xFE;
+                               preamble[3] = (byte)0xFF;
                        } else {
                                preamble[0] = (byte)0xFF;
                                preamble[1] = (byte)0xFE;
                        }
                        return preamble;
-               } else {
-                       return new byte [0];
                }
+               
+               return EmptyArray<byte>.Value;
        }
 
        // Determine if this object is equal to another.
@@ -471,20 +467,14 @@ public sealed class UTF32Encoding : Encoding
 
        } // class UTF32Decoder
        
-#if NET_2_0
        [CLSCompliantAttribute(false)]
        public unsafe override int GetByteCount (char *chars, int count)
        {
+               if (chars == null)
+                       throw new ArgumentNullException ("chars");
                return count * 4;
        }
-#else
-       public override byte [] GetBytes (String s)
-       {
-               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)
@@ -524,10 +514,6 @@ public sealed class UTF32Encoding : Encoding
        {
                return base.GetEncoder ();
        }
-#endif
-
 }; // class UTF32Encoding
 
 }; // namespace System.Text
-
-#endif