Merge pull request #309 from i59/patch-1
[mono.git] / mcs / class / I18N / West / CP1252.cs
index 291ef914bf45fbdf17d9265f0496250ea93aa168..b0885181980f8de3a3772924a554d0a77d9ec600 100644 (file)
@@ -28,8 +28,10 @@ namespace I18N.West
 {
 
 using System;
+using System.Text;
 using I18N.Common;
 
+[Serializable]
 public class CP1252 : ByteEncoding
 {
        public CP1252()
@@ -84,13 +86,19 @@ public class CP1252 : ByteEncoding
                '\u00FC', '\u00FD', '\u00FE', '\u00FF', 
        };
 
-       protected override void ToBytes(char[] chars, int charIndex, int charCount,
-                                       byte[] bytes, int byteIndex)
+       protected unsafe override void ToBytes(char* chars, int charCount,
+                                       byte* bytes, int byteCount)
        {
                int ch;
+               int charIndex = 0;
+               int byteIndex = 0;
+#if NET_2_0
+               EncoderFallbackBuffer buffer = null;
+#endif
                while(charCount > 0)
                {
                        ch = (int)(chars[charIndex++]);
+                       --charCount;
                        if(ch >= 128) switch(ch)
                        {
                                case 0x0081:
@@ -226,16 +234,23 @@ public class CP1252 : ByteEncoding
                                {
                                        if(ch >= 0xFF01 && ch <= 0xFF5E)
                                                ch -= 0xFEE0;
-                                       else
+                                       else {
+#if NET_2_0
+                                               HandleFallback (ref buffer, chars, ref charIndex, ref charCount, bytes, ref byteIndex, ref byteCount);
+                                               continue;
+#else
                                                ch = 0x3F;
+#endif
+                                       }
                                }
                                break;
                        }
                        bytes[byteIndex++] = (byte)ch;
-                       --charCount;
+                       --byteCount;
                }
        }
 
+       /*
        protected override void ToBytes(String s, int charIndex, int charCount,
                                        byte[] bytes, int byteIndex)
        {
@@ -387,9 +402,11 @@ public class CP1252 : ByteEncoding
                        --charCount;
                }
        }
+       */
 
 }; // class CP1252
 
+[Serializable]
 public class ENCwindows_1252 : CP1252
 {
        public ENCwindows_1252() : base() {}