[msvc] Update csproj files (#4846)
[mono.git] / mcs / class / I18N / CJK / CP950.cs
index 72722728afc817b974c093f2194bbe34fb22f76e..8e2420ca14c516256d55d92bef0c84820b7d2a1e 100644 (file)
@@ -27,15 +27,13 @@ namespace I18N.CJK
                        return DbcsConvert.Big5;
                }
 
+#if !DISABLE_UNSAFE
                // Get the bytes that result from encoding a character buffer.
                public unsafe override int GetByteCountImpl (char* chars, int count)
                {
                        DbcsConvert convert = GetConvert ();
                        int index = 0;
                        int length = 0;
-#if NET_2_0
-                       EncoderFallbackBuffer buffer = null;
-#endif
 
                        while (count-- > 0) {
                                char c = chars[index++];
@@ -46,12 +44,8 @@ namespace I18N.CJK
                                byte b1 = convert.u2n[((int)c) * 2 + 1];
                                byte b2 = convert.u2n[((int)c) * 2];
                                if (b1 == 0 && b2 == 0) {
-#if NET_2_0
                                        // FIXME: handle fallback for GetByteCountImpl().
                                        length++;
-#else
-                                       length++;
-#endif
                                }
                                else
                                        length += 2;
@@ -66,13 +60,13 @@ namespace I18N.CJK
                        DbcsConvert convert = GetConvert ();
                        int charIndex = 0;
                        int byteIndex = 0;
-#if NET_2_0
+                       int end = charCount;
                        EncoderFallbackBuffer buffer = null;
-#endif
 
                        int origIndex = byteIndex;
-                       while (charCount-- > 0) {
-                               char c = chars[charIndex++];
+                       for (int i = charIndex; i < end; i++, charCount--) 
+                       {
+                               char c = chars[i];
                                if (c <= 0x80 || c == 0xFF) { // ASCII
                                        bytes[byteIndex++] = (byte)c;
                                        continue;
@@ -80,13 +74,9 @@ namespace I18N.CJK
                                byte b1 = convert.u2n[((int)c) * 2 + 1];
                                byte b2 = convert.u2n[((int)c) * 2];
                                if (b1 == 0 && b2 == 0) {
-#if NET_2_0
                                        HandleFallback (ref buffer, chars,
-                                               ref charIndex, ref charCount,
-                                               bytes, ref byteIndex, ref byteCount);
-#else
-                                       bytes[byteIndex++] = (byte)'?';
-#endif
+                                               ref i, ref charCount,
+                                               bytes, ref byteIndex, ref byteCount, null);
                                } else {
                                        bytes[byteIndex++] = b1;
                                        bytes[byteIndex++] = b2;
@@ -94,7 +84,68 @@ namespace I18N.CJK
                        }
                        return byteIndex - origIndex;
                }
-               
+#else
+               // Get the bytes that result from encoding a character buffer.
+               public override int GetByteCount(char[] chars, int index, int count)
+               {
+                       DbcsConvert convert = GetConvert();
+                       int length = 0;
+
+                       while (count-- > 0)
+                       {
+                               char c = chars[index++];
+                               if (c <= 0x80 || c == 0xFF)
+                               { // ASCII
+                                       length++;
+                                       continue;
+                               }
+                               byte b1 = convert.u2n[((int)c) * 2 + 1];
+                               byte b2 = convert.u2n[((int)c) * 2];
+                               if (b1 == 0 && b2 == 0)
+                               {
+                                       // FIXME: handle fallback for GetByteCountImpl().
+                                       length++;
+                               }
+                               else
+                                       length += 2;
+                       }
+                       return length;
+               }
+
+               // Get the bytes that result from encoding a character buffer.
+               public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
+               {
+                       int byteCount = bytes.Length;
+                       int end = charIndex + charCount;
+
+                       DbcsConvert convert = GetConvert();
+                       EncoderFallbackBuffer buffer = null;
+
+                       int origIndex = byteIndex;
+                       for (int i = charIndex; i < end; i++, charCount--)
+                       {
+                               char c = chars[i];
+                               if (c <= 0x80 || c == 0xFF)
+                               { // ASCII
+                                       bytes[byteIndex++] = (byte)c;
+                                       continue;
+                               }
+                               byte b1 = convert.u2n[((int)c) * 2 + 1];
+                               byte b2 = convert.u2n[((int)c) * 2];
+                               if (b1 == 0 && b2 == 0)
+                               {
+                                       HandleFallback (ref buffer, chars, ref i, ref charCount,
+                                               bytes, ref byteIndex, ref byteCount, null);
+                               }
+                               else
+                               {
+                                       bytes[byteIndex++] = b1;
+                                       bytes[byteIndex++] = b2;
+                               }
+                       }
+                       return byteIndex - origIndex;
+               }
+#endif
                // Get the characters that result from decoding a byte buffer.
                public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
                                             char[] chars, int charIndex)
@@ -188,9 +239,7 @@ namespace I18N.CJK
                                return GetCharCount (bytes, index, count, false);
                        }
 
-#if NET_2_0
                        public override
-#endif
                        int GetCharCount (byte[] bytes, int index, int count, bool refresh)
                        {
                                CheckRange (bytes, index, count);
@@ -240,9 +289,7 @@ namespace I18N.CJK
                                return GetChars (bytes, byteIndex, byteCount, chars, charIndex, false);
                        }
 
-#if NET_2_0
                        public override
-#endif
                        int GetChars(byte[] bytes, int byteIndex, int byteCount,
                                                     char[] chars, int charIndex, bool refresh)
                        {