public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
        {
            uint num  = 0;
            uint num1 = 0;

            return(UnixEncoding.InternalGetChars(bytes, byteIndex, byteCount, chars, charIndex, ref num, ref num1, true, true));
        }
 public override int GetMaxCharCount(int byteCount)
 {
     if (byteCount < 0)
     {
         throw new ArgumentOutOfRangeException("byteCount", UnixEncoding._("ArgRange_NonNegative"));
     }
     return(byteCount);
 }
예제 #3
0
        // Determine if this object is equal to another.
        public override bool Equals(Object value)
        {
            UnixEncoding enc = (value as UnixEncoding);

            if (enc != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
		public void TestDecodingGetChars1()
		{
			UnixEncoding unixEnc = new UnixEncoding ();
			// 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>." 
			// see (RFC 2044)
			byte[] unixBytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
			char[] UniCodeChars = unixEnc.GetChars(unixBytes);

			Assert.AreEqual (0x0041, UniCodeChars [0], "UTF #1");
			Assert.AreEqual (0x2262, UniCodeChars [1], "UTF #2");
			Assert.AreEqual (0x0391, UniCodeChars [2], "UTF #3");
			Assert.AreEqual (0x002E, UniCodeChars [3], "UTF #4");
		}
예제 #5
0
		public void TestEncodingGetBytes1()
		{
			UnixEncoding unixEnc = new UnixEncoding ();
			string UniCode = "\u0041\u2262\u0391\u002E";

			// "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E 
			// see (RFC 2044)
			byte[] unixBytes = unixEnc.GetBytes (UniCode);

			Assert.AreEqual (0x41, unixBytes [0], "UTF #1");
			Assert.AreEqual (0xE2, unixBytes [1], "UTF #2");
			Assert.AreEqual (0x89, unixBytes [2], "UTF #3");
			Assert.AreEqual (0xA2, unixBytes [3], "UTF #4");
			Assert.AreEqual (0xCE, unixBytes [4], "UTF #5");
			Assert.AreEqual (0x91, unixBytes [5], "UTF #6");
			Assert.AreEqual (0x2E, unixBytes [6], "UTF #7");
		}
 private static void CopyRaw(byte[] raw, ref int next_raw, char[] chars, ref int posn, int length)
 {
     if (posn + next_raw * 2 > length)
     {
         throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "chars");
     }
     for (int i = 0; i < next_raw; i++)
     {
         int num  = posn;
         int num1 = num;
         posn        = num + 1;
         chars[num1] = UnixEncoding.EscapeByte;
         int num2 = posn;
         num1        = num2;
         posn        = num2 + 1;
         chars[num1] = (char)raw[i];
     }
     next_raw = 0;
 }
예제 #7
0
		public void TestEncodingGetBytes2()
		{
			UnixEncoding unixEnc = new UnixEncoding ();
			string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";

			// "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21 
			// see (RFC 2044)
			byte[] unixBytes = new byte [11];

			int ByteCnt = unixEnc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, unixBytes, 0);

			Assert.AreEqual (11, ByteCnt, "UTF #1");
			Assert.AreEqual (0x48, unixBytes [0], "UTF #2");
			Assert.AreEqual (0x69, unixBytes [1], "UTF #3");
			Assert.AreEqual (0x20, unixBytes [2], "UTF #4");
			Assert.AreEqual (0x4D, unixBytes [3], "UTF #5");
			Assert.AreEqual (0x6F, unixBytes [4], "UTF #6");
			Assert.AreEqual (0x6D, unixBytes [5], "UTF #7");
			Assert.AreEqual (0x20, unixBytes [6], "UTF #8");
			Assert.AreEqual (0xE2, unixBytes [7], "UTF #9");
			Assert.AreEqual (0x98, unixBytes [8], "UTF #10");
			Assert.AreEqual (0xBA, unixBytes [9], "UTF #11");
			Assert.AreEqual (0x21, unixBytes [10], "UTF #12");
		}
 public override int GetByteCount(char[] chars, int index, int count)
 {
     return(UnixEncoding.InternalGetByteCount(chars, index, count, 0, true));
 }
예제 #9
0
		public void Create () 
		{
			unix = new UnixEncoding ();
		}
예제 #10
0
		public void TestThrowOnInvalid ()
		{
			UnixEncoding u = new UnixEncoding ();

			byte[] data = new byte [] { 0xC0, 0xAF };
			string s = u.GetString (data);
			Assert.AreEqual (4, s.Length);
			Assert.AreEqual (0x0000, (int) s [0]);
			Assert.AreEqual (0xC0,   (int) s [1]);
			Assert.AreEqual (0x0000, (int) s [2]);
			Assert.AreEqual (0xAF,   (int) s [3]);
			Assert.AreEqual ("\u0000\xC0\u0000\xAF", s, "Output-TestThrowOnInvalid");
			Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (unix.GetBytes (s)), "Reconverted-TestThrowOnInvalid");

			data = new byte [] { 0x30, 0x31, 0xC0, 0xAF, 0x30, 0x32 };
			s = u.GetString (data);
			Assert.AreEqual (8, s.Length);
			Assert.AreEqual (0x30,   (int) s [0]);
			Assert.AreEqual (0x31,   (int) s [1]);
			Assert.AreEqual (0x0000, (int) s [2]);
			Assert.AreEqual (0xC0,   (int) s [3]);
			Assert.AreEqual (0x0000, (int) s [4]);
			Assert.AreEqual (0xAF,   (int) s [5]);
			Assert.AreEqual (0x30,   (int) s [6]);
			Assert.AreEqual (0x32,   (int) s [7]);

			Assert.AreEqual ("\x30\x31\u0000\xC0\u0000\xAF\x30\x32", s, "Output-TestThrowOnInvalid2");
			Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (unix.GetBytes (s)), "Reconverted-TestThrowOnInvalid2");
		}
예제 #11
0
 public override int GetCharCount(byte[] bytes, int index, int count)
 {
     return(UnixEncoding.InternalGetCharCount(bytes, index, count, 0, 0, true, true));
 }
예제 #12
0
            public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteCount, bool flush)
            {
                int num = UnixEncoding.InternalGetBytes(chars, charIndex, charCount, bytes, byteCount, ref this.leftOver, flush);

                return(num);
            }
예제 #13
0
 public override int GetByteCount(char[] chars, int index, int count, bool flush)
 {
     return(UnixEncoding.InternalGetByteCount(chars, index, count, this.leftOver, flush));
 }
예제 #14
0
 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
 {
     return(UnixEncoding.InternalGetChars(bytes, byteIndex, byteCount, chars, charIndex, ref this.leftOverBits, ref this.leftOverCount, true, false));
 }
예제 #15
0
        public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            uint num;

            if (s == null)
            {
                throw new ArgumentNullException("s");
            }
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (charIndex < 0 || charIndex > s.Length)
            {
                throw new ArgumentOutOfRangeException("charIndex", UnixEncoding._("ArgRange_StringIndex"));
            }
            if (charCount < 0 || charCount > s.Length - charIndex)
            {
                throw new ArgumentOutOfRangeException("charCount", UnixEncoding._("ArgRange_StringRange"));
            }
            if (byteIndex < 0 || byteIndex > (int)bytes.Length)
            {
                throw new ArgumentOutOfRangeException("byteIndex", UnixEncoding._("ArgRange_Array"));
            }
            int length = (int)bytes.Length;
            int num1   = byteIndex;

            while (charCount > 0)
            {
                int num2 = charIndex;
                charIndex = num2 + 1;
                char chr = s[num2];
                if (chr >= '\uD800' && chr <= '\uDBFF' && charCount > 1)
                {
                    num = s[charIndex];
                    if (num < 56320 || num > 57343)
                    {
                        num = chr;
                    }
                    else
                    {
                        num = num - 56320 + (chr - 55296 << '\n') + 65536;
                        charIndex++;
                        charCount--;
                    }
                }
                else if (chr != UnixEncoding.EscapeByte || charCount <= 1)
                {
                    num = chr;
                }
                else
                {
                    if (num1 >= length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    charCount -= 2;
                    if (charCount >= 0)
                    {
                        int num3 = num1;
                        num1 = num3 + 1;
                        int num4 = charIndex;
                        charIndex   = num4 + 1;
                        bytes[num3] = (byte)s[num4];
                    }
                    continue;
                }
                charCount--;
                if (num < 128)
                {
                    if (num1 >= length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num5 = num1;
                    num1        = num5 + 1;
                    bytes[num5] = (byte)num;
                }
                else if (num < 2048)
                {
                    if (num1 + 2 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num6 = num1;
                    num1        = num6 + 1;
                    bytes[num6] = (byte)(192 | num >> 6);
                    int num7 = num1;
                    num1        = num7 + 1;
                    bytes[num7] = (byte)(128 | num & 63);
                }
                else if (num >= 65536)
                {
                    if (num1 + 4 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num8 = num1;
                    num1        = num8 + 1;
                    bytes[num8] = (byte)(240 | num >> 18);
                    int num9 = num1;
                    num1        = num9 + 1;
                    bytes[num9] = (byte)(128 | num >> 12 & 63);
                    int num10 = num1;
                    num1         = num10 + 1;
                    bytes[num10] = (byte)(128 | num >> 6 & 63);
                    int num11 = num1;
                    num1         = num11 + 1;
                    bytes[num11] = (byte)(128 | num & 63);
                }
                else
                {
                    if (num1 + 3 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num12 = num1;
                    num1         = num12 + 1;
                    bytes[num12] = (byte)(224 | num >> 12);
                    int num13 = num1;
                    num1         = num13 + 1;
                    bytes[num13] = (byte)(128 | num >> 6 & 63);
                    int num14 = num1;
                    num1         = num14 + 1;
                    bytes[num14] = (byte)(128 | num & 63);
                }
            }
            return(num1 - byteIndex);
        }
예제 #16
0
		// bug #75065 and #73086.
		public void GetCharsFEFF ()
		{
			byte [] data = new byte [] {0xEF, 0xBB, 0xBF};
			Encoding enc = new UnixEncoding ();
			string s = enc.GetString (data);
			Assert.AreEqual (s, "\uFEFF");

			Encoding utf = enc;
			char[] testChars = {'\uFEFF','A'};

			byte[] bytes = utf.GetBytes(testChars);
			char[] chars = utf.GetChars(bytes);
			Assert.AreEqual ('\uFEFF', chars [0], "#1");
			Assert.AreEqual ('A', chars [1], "#2");
		}
예제 #17
0
        private static int InternalGetCharCount(byte[] bytes, int index, int count, uint leftOverBits, uint leftOverCount, bool throwOnInvalid, bool flush)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (index < 0 || index > (int)bytes.Length)
            {
                throw new ArgumentOutOfRangeException("index", UnixEncoding._("ArgRange_Array"));
            }
            if (count < 0 || count > (int)bytes.Length - index)
            {
                throw new ArgumentOutOfRangeException("count", UnixEncoding._("ArgRange_Array"));
            }
            int  num  = 0;
            int  num1 = 0;
            uint num2 = leftOverBits;
            uint num3 = leftOverCount & 15;
            uint num4 = leftOverCount >> 4 & 15;

            while (count > 0)
            {
                int num5 = index;
                index = num5 + 1;
                uint num6 = bytes[num5];
                num++;
                count--;
                if (num4 != 0)
                {
                    if ((num6 & 192) != 128)
                    {
                        !throwOnInvalid;
                        if (num6 < 128)
                        {
                            index--;
                            count++;
                            num--;
                        }
                        num1 = num1 + num * 2;
                        num4 = 0;
                        num  = 0;
                    }
                    else
                    {
                        num2 = num2 << 6 | num6 & 63;
                        UInt32 num7 = num3 + 1;
                        num3 = num7;
                        if (num7 >= num4)
                        {
                            if (num2 < 65536)
                            {
                                bool flag = false;
                                switch (num4)
                                {
                                case 2:
                                {
                                    flag = num2 <= 127;
                                    break;
                                }

                                case 3:
                                {
                                    flag = num2 <= 2047;
                                    break;
                                }

                                case 4:
                                {
                                    flag = num2 <= 65535;
                                    break;
                                }

                                case 5:
                                {
                                    flag = num2 <= 2097151;
                                    break;
                                }

                                case 6:
                                {
                                    flag = num2 <= 67108863;
                                    break;
                                }
                                }
                                if (!flag)
                                {
                                    num1++;
                                }
                                else
                                {
                                    num1 = num1 + num * 2;
                                }
                            }
                            else if (num2 < 1114112)
                            {
                                num1 += 2;
                            }
                            else if (throwOnInvalid)
                            {
                                num1 = num1 + num * 2;
                            }
                            num4 = 0;
                            num  = 0;
                        }
                    }
                }
                else if (num6 < 128)
                {
                    num1++;
                    num = 0;
                }
                else if ((num6 & 224) == 192)
                {
                    num2 = num6 & 31;
                    num3 = 1;
                    num4 = 2;
                }
                else if ((num6 & 240) == 224)
                {
                    num2 = num6 & 15;
                    num3 = 1;
                    num4 = 3;
                }
                else if ((num6 & 248) == 240)
                {
                    num2 = num6 & 7;
                    num3 = 1;
                    num4 = 4;
                }
                else if ((num6 & 252) == 248)
                {
                    num2 = num6 & 3;
                    num3 = 1;
                    num4 = 5;
                }
                else if ((num6 & 254) != 252)
                {
                    !throwOnInvalid;
                    num1 = num1 + num * 2;
                    num  = 0;
                }
                else
                {
                    num2 = num6 & 3;
                    num3 = 1;
                    num4 = 6;
                }
            }
            if (flush && num4 != 0 && throwOnInvalid)
            {
                num1 = num1 + num * 2;
            }
            return(num1);
        }
예제 #18
0
        private static int InternalGetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, ref uint leftOver, bool flush)
        {
            uint num;

            if (chars == null)
            {
                throw new ArgumentNullException("chars");
            }
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (charIndex < 0 || charIndex > (int)chars.Length)
            {
                throw new ArgumentOutOfRangeException("charIndex", UnixEncoding._("ArgRange_Array"));
            }
            if (charCount < 0 || charCount > (int)chars.Length - charIndex)
            {
                throw new ArgumentOutOfRangeException("charCount", UnixEncoding._("ArgRange_Array"));
            }
            if (byteIndex < 0 || byteIndex > (int)bytes.Length)
            {
                throw new ArgumentOutOfRangeException("byteIndex", UnixEncoding._("ArgRange_Array"));
            }
            int  length = (int)bytes.Length;
            uint num1   = leftOver;
            int  num2   = byteIndex;

            while (charCount > 0)
            {
                int num3 = charIndex;
                charIndex = num3 + 1;
                char chr = chars[num3];
                charCount--;
                if (num1 != 0)
                {
                    if (chr < '\uDC00' || chr > '\uDFFF')
                    {
                        num  = num1;
                        num1 = 0;
                        charIndex--;
                        charCount++;
                    }
                    else
                    {
                        num  = (num1 - 55296 << 10) + (chr - 56320) + 65536;
                        num1 = 0;
                    }
                }
                else if (chr >= '\uD800' && chr <= '\uDBFF')
                {
                    num1 = chr;
                    continue;
                }
                else if (chr != UnixEncoding.EscapeByte)
                {
                    num = chr;
                }
                else
                {
                    if (num2 >= length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num4 = charCount - 1;
                    charCount = num4;
                    if (num4 >= 0)
                    {
                        int num5 = num2;
                        num2 = num5 + 1;
                        int num6 = charIndex;
                        charIndex   = num6 + 1;
                        bytes[num5] = (byte)chars[num6];
                    }
                    continue;
                }
                if (num < 128)
                {
                    if (num2 >= length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num7 = num2;
                    num2        = num7 + 1;
                    bytes[num7] = (byte)num;
                }
                else if (num < 2048)
                {
                    if (num2 + 2 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num8 = num2;
                    num2        = num8 + 1;
                    bytes[num8] = (byte)(192 | num >> 6);
                    int num9 = num2;
                    num2        = num9 + 1;
                    bytes[num9] = (byte)(128 | num & 63);
                }
                else if (num >= 65536)
                {
                    if (num2 + 4 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num10 = num2;
                    num2         = num10 + 1;
                    bytes[num10] = (byte)(240 | num >> 18);
                    int num11 = num2;
                    num2         = num11 + 1;
                    bytes[num11] = (byte)(128 | num >> 12 & 63);
                    int num12 = num2;
                    num2         = num12 + 1;
                    bytes[num12] = (byte)(128 | num >> 6 & 63);
                    int num13 = num2;
                    num2         = num13 + 1;
                    bytes[num13] = (byte)(128 | num & 63);
                }
                else
                {
                    if (num2 + 3 > length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                    }
                    int num14 = num2;
                    num2         = num14 + 1;
                    bytes[num14] = (byte)(224 | num >> 12);
                    int num15 = num2;
                    num2         = num15 + 1;
                    bytes[num15] = (byte)(128 | num >> 6 & 63);
                    int num16 = num2;
                    num2         = num16 + 1;
                    bytes[num16] = (byte)(128 | num & 63);
                }
            }
            if (flush && num1 != 0)
            {
                if (num2 + 3 > length)
                {
                    throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "bytes");
                }
                int num17 = num2;
                num2         = num17 + 1;
                bytes[num17] = (byte)(224 | num1 >> 12);
                int num18 = num2;
                num2         = num18 + 1;
                bytes[num18] = (byte)(128 | num1 >> 6 & 63);
                int num19 = num2;
                num2         = num19 + 1;
                bytes[num19] = (byte)(128 | num1 & 63);
                num1         = 0;
            }
            leftOver = num1;
            return(num2 - byteIndex);
        }
예제 #19
0
        private static int InternalGetByteCount(char[] chars, int index, int count, uint leftOver, bool flush)
        {
            if (chars == null)
            {
                throw new ArgumentNullException("chars");
            }
            if (index < 0 || index > (int)chars.Length)
            {
                throw new ArgumentOutOfRangeException("index", UnixEncoding._("ArgRange_Array"));
            }
            if (count < 0 || count > (int)chars.Length - index)
            {
                throw new ArgumentOutOfRangeException("count", UnixEncoding._("ArgRange_Array"));
            }
            int  num  = 0;
            uint num1 = leftOver;

            while (count > 0)
            {
                char chr = chars[index];
                if (num1 != 0)
                {
                    if (chr < '\uDC00' || chr > '\uDFFF')
                    {
                        num += 3;
                        num1 = 0;
                        continue;
                    }
                    else
                    {
                        num += 4;
                        num1 = 0;
                    }
                }
                else if (chr == UnixEncoding.EscapeByte && count > 1)
                {
                    num++;
                    index++;
                    count--;
                }
                else if (chr < '\u0080')
                {
                    num++;
                }
                else if (chr < '\u0800')
                {
                    num += 2;
                }
                else if (chr < '\uD800' || chr > '\uDBFF')
                {
                    num += 3;
                }
                else
                {
                    num1 = chr;
                }
                index++;
                count--;
            }
            if (flush && num1 != 0)
            {
                num += 3;
            }
            return(num);
        }
예제 #20
0
        private static int InternalGetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref uint leftOverBits, ref uint leftOverCount, bool throwOnInvalid, bool flush)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (chars == null)
            {
                throw new ArgumentNullException("chars");
            }
            if (byteIndex < 0 || byteIndex > (int)bytes.Length)
            {
                throw new ArgumentOutOfRangeException("byteIndex", UnixEncoding._("ArgRange_Array"));
            }
            if (byteCount < 0 || byteCount > (int)bytes.Length - byteIndex)
            {
                throw new ArgumentOutOfRangeException("byteCount", UnixEncoding._("ArgRange_Array"));
            }
            if (charIndex < 0 || charIndex > (int)chars.Length)
            {
                throw new ArgumentOutOfRangeException("charIndex", UnixEncoding._("ArgRange_Array"));
            }
            if (charIndex == (int)chars.Length)
            {
                return(0);
            }
            byte[] numArray = new byte[6];
            int    num      = 0;
            int    length   = (int)chars.Length;
            int    num1     = charIndex;
            uint   num2     = leftOverBits;
            uint   num3     = leftOverCount & 15;
            uint   num4     = leftOverCount >> 4 & 15;

            while (byteCount > 0)
            {
                int num5 = byteIndex;
                byteIndex = num5 + 1;
                uint num6 = bytes[num5];
                int  num7 = num;
                num            = num7 + 1;
                numArray[num7] = (byte)num6;
                byteCount--;
                if (num4 != 0)
                {
                    if ((num6 & 192) != 128)
                    {
                        !throwOnInvalid;
                        if (num6 < 128)
                        {
                            byteIndex--;
                            byteCount++;
                            num--;
                        }
                        UnixEncoding.CopyRaw(numArray, ref num, chars, ref num1, length);
                        num4 = 0;
                        num  = 0;
                    }
                    else
                    {
                        num2 = num2 << 6 | num6 & 63;
                        UInt32 num8 = num3 + 1;
                        num3 = num8;
                        if (num8 >= num4)
                        {
                            if (num2 < 65536)
                            {
                                bool flag = false;
                                switch (num4)
                                {
                                case 2:
                                {
                                    flag = num2 <= 127;
                                    break;
                                }

                                case 3:
                                {
                                    flag = num2 <= 2047;
                                    break;
                                }

                                case 4:
                                {
                                    flag = num2 <= 65535;
                                    break;
                                }

                                case 5:
                                {
                                    flag = num2 <= 2097151;
                                    break;
                                }

                                case 6:
                                {
                                    flag = num2 <= 67108863;
                                    break;
                                }
                                }
                                if (!flag)
                                {
                                    if (num1 >= length)
                                    {
                                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "chars");
                                    }
                                    int num9 = num1;
                                    num1        = num9 + 1;
                                    chars[num9] = (char)num2;
                                }
                                else
                                {
                                    UnixEncoding.CopyRaw(numArray, ref num, chars, ref num1, length);
                                }
                            }
                            else if (num2 < 1114112)
                            {
                                if (num1 + 2 > length)
                                {
                                    throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "chars");
                                }
                                num2 -= 65536;
                                int num10 = num1;
                                num1         = num10 + 1;
                                chars[num10] = (char)((num2 >> 10) + 55296);
                                int num11 = num1;
                                num1         = num11 + 1;
                                chars[num11] = (char)((num2 & 1023) + 56320);
                            }
                            else if (throwOnInvalid)
                            {
                                UnixEncoding.CopyRaw(numArray, ref num, chars, ref num1, length);
                            }
                            num4 = 0;
                            num  = 0;
                        }
                    }
                }
                else if (num6 < 128)
                {
                    if (num1 >= length)
                    {
                        throw new ArgumentException(UnixEncoding._("Arg_InsufficientSpace"), "chars");
                    }
                    num = 0;
                    int num12 = num1;
                    num1         = num12 + 1;
                    chars[num12] = (char)num6;
                }
                else if ((num6 & 224) == 192)
                {
                    num2 = num6 & 31;
                    num3 = 1;
                    num4 = 2;
                }
                else if ((num6 & 240) == 224)
                {
                    num2 = num6 & 15;
                    num3 = 1;
                    num4 = 3;
                }
                else if ((num6 & 248) == 240)
                {
                    num2 = num6 & 7;
                    num3 = 1;
                    num4 = 4;
                }
                else if ((num6 & 252) == 248)
                {
                    num2 = num6 & 3;
                    num3 = 1;
                    num4 = 5;
                }
                else if ((num6 & 254) != 252)
                {
                    !throwOnInvalid;
                    num = 0;
                    int num13 = num1;
                    num1         = num13 + 1;
                    chars[num13] = UnixEncoding.EscapeByte;
                    int num14 = num1;
                    num1         = num14 + 1;
                    chars[num14] = (char)num6;
                }
                else
                {
                    num2 = num6 & 3;
                    num3 = 1;
                    num4 = 6;
                }
            }
            if (flush && num4 != 0 && throwOnInvalid)
            {
                UnixEncoding.CopyRaw(numArray, ref num, chars, ref num1, length);
            }
            leftOverBits  = num2;
            leftOverCount = num3 | num4 << 4;
            return(num1 - charIndex);
        }
예제 #21
0
 public override int GetCharCount(byte[] bytes, int index, int count)
 {
     return(UnixEncoding.InternalGetCharCount(bytes, index, count, this.leftOverBits, this.leftOverCount, true, false));
 }
예제 #22
0
		public void TestMaxByteCount()
		{
			UnixEncoding unixenc = new UnixEncoding ();
			Assert.AreEqual (200, unixenc.GetMaxByteCount(50), "UTF #1");
		}
예제 #23
0
        public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            uint num = 0;

            return(UnixEncoding.InternalGetBytes(chars, charIndex, charCount, bytes, byteIndex, ref num, true));
        }