Merge pull request #2408 from tastywheattasteslikechicken/MoreInterfaceSupport
[mono.git] / mcs / class / I18N / Rare / CP20285.cs
index 20efc688ffb8e28647e43399e34954112e2daf89..81967392bc9cb5c19772669b691f46c3034293f2 100644 (file)
 
 // Generated from "ibm-285.ucm".
 
+// WARNING: Modifying this file directly might be a bad idea.
+// You should edit the code generator tools/ucm2cp.c instead for your changes
+// to appear in all relevant classes.
 namespace I18N.Rare
 {
 
 using System;
+using System.Text;
 using I18N.Common;
 
+[Serializable]
 public class CP20285 : ByteEncoding
 {
        public CP20285()
@@ -84,13 +89,63 @@ public class CP20285 : ByteEncoding
                '\u00DC', '\u00D9', '\u00DA', '\u009F', 
        };
 
-       protected override void ToBytes(char[] chars, int charIndex, int charCount,
-                                       byte[] bytes, int byteIndex)
+       // Get the number of bytes needed to encode a character buffer.
+       public unsafe override int GetByteCountImpl (char* chars, int count)
+       {
+               if (this.EncoderFallback != null)               {
+                       //Calculate byte count by actually doing encoding and discarding the data.
+                       return GetBytesImpl(chars, count, null, 0);
+               }
+               else
+               
+               {
+                       return count;
+               }
+       }
+       
+       // Get the number of bytes needed to encode a character buffer.
+       public override int GetByteCount (String s)
+       {
+               if (this.EncoderFallback != null)
+               {
+                       //Calculate byte count by actually doing encoding and discarding the data.
+                       unsafe
+                       {
+                               fixed (char *s_ptr = s)
+                               {
+                                       return GetBytesImpl(s_ptr, s.Length, null, 0);
+                               }
+                       }
+               }
+               else
+               {
+                       //byte count equals character count because no EncoderFallback set
+                       return s.Length;
+               }
+       }
+       
+       //ToBytes is just an alias for GetBytesImpl, but doesn't return byte count
+       protected unsafe override void ToBytes(char* chars, int charCount,
+                                       byte* bytes, int byteCount)
+       {
+               //Calling ToBytes with null destination buffer doesn't make any sense
+               if (bytes == null)
+                       throw new ArgumentNullException("bytes");
+               GetBytesImpl(chars, charCount, bytes, byteCount);
+       }
+       
+       public unsafe override int GetBytesImpl (char* chars, int charCount,
+                                                byte* bytes, int byteCount)
        {
                int ch;
-               while(charCount > 0)
+               int charIndex = 0;
+               int byteIndex = 0;
+               EncoderFallbackBuffer buffer = null;
+               while (charCount > 0)
                {
-                       ch = (int)(chars[charIndex++]);
+                       ch = (int)(chars[charIndex]);
+                       charIndex++;
+                       charCount--;
                        if(ch >= 4) switch(ch)
                        {
                                case 0x000B:
@@ -478,13 +533,20 @@ public class CP20285 : ByteEncoding
                                case 0xFF5C: ch = 0x4F; break;
                                case 0xFF5D: ch = 0xD0; break;
                                case 0xFF5E: ch = 0xBC; break;
-                               default: ch = 0x3F; break;
+                               default:
+                                       HandleFallback (ref buffer, chars, ref charIndex, ref charCount, bytes, ref byteIndex, ref byteCount);
+                                       continue;
                        }
-                       bytes[byteIndex++] = (byte)ch;
-                       --charCount;
+                       //Write encoded byte to buffer, if buffer is defined and fallback was not used
+                       if (bytes != null)
+                               bytes[byteIndex] = (byte)ch;
+                       byteIndex++;
+                       byteCount--;
                }
+               return byteIndex;
        }
 
+       /*
        protected override void ToBytes(String s, int charIndex, int charCount,
                                        byte[] bytes, int byteIndex)
        {
@@ -885,9 +947,11 @@ public class CP20285 : ByteEncoding
                        --charCount;
                }
        }
+       */
 
 }; // class CP20285
 
+[Serializable]
 public class ENCibm285 : CP20285
 {
        public ENCibm285() : base() {}