コード例 #1
0
ファイル: Compact.cs プロジェクト: JobsLj/dp2
        public static string Bit7Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(7);
                if (bits.Count < 7)
                {
                    break;
                }

                char ch = (char)BitExtract.ToByte(bits, 7);

                // 正好末尾是 7 bits 1111111,需要丢弃
                // TODO: 注意测试这种情况
                if (extract.Count == 0 && ch == 0x7f)
                {
                    break;
                }

                result.Append(ch);
            }

            return(result.ToString());
        }
コード例 #2
0
ファイル: Compact.cs プロジェクト: JobsLj/dp2
        public static string Bit6Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(6);
                if (bits.Count < 6)
                {
                    break;
                }

                char ch = (char)BitExtract.ToByte(bits, 6);

                // 如果正好末尾是 6 bits 100000,需丢弃
                // 注意测试这种情形, 应正确丢弃
                if (extract.Count == 0 && ch == 0x20)
                {
                    break;
                }

                if ((ch & 0x20) == 0x00)
                {
                    ch = (char)(ch | 0x40);
                }
                result.Append(ch);
            }
            return(result.ToString());
        }
コード例 #3
0
ファイル: Compact.cs プロジェクト: JobsLj/dp2
        public static string Bit5Extract(byte[] data)
        {
            BitExtract    extract = new BitExtract(data);
            StringBuilder result  = new StringBuilder();

            while (true)
            {
                List <bool> bits = extract.GetBits(5);
                if (bits.Count < 5)
                {
                    break;
                }
                if (BitExtract.IsZero(bits))
                {
                    break;
                }
                char ch = (char)(BitExtract.ToByte(bits, 5) | 0x40);
                result.Append(ch);
            }
            return(result.ToString());
        }
コード例 #4
0
ファイル: Compact.cs プロジェクト: JobsLj/dp2
        public static string IsilExtract(byte[] data)
        {
            char          save_charset    = 'u';
            char          current_charset = 'u';
            BitExtract    extract         = new BitExtract(data);
            StringBuilder result          = new StringBuilder();

            while (true)
            {
                int    bit_count = char.ToLower(current_charset) == 'd' ? 4 : 5;
                string bits      = extract.GetBitsString(bit_count);
                if (bits.Length < bit_count)
                {
                    break;
                }

                // 切换命令
                if (current_charset == 'u' || current_charset == 'U')
                {
                    // 小写锁定
                    if (bits == "11100")
                    {
                        current_charset = 'l';
                        continue;
                    }

                    // 小写 shift
                    if (bits == "11101")
                    {
                        save_charset    = current_charset;
                        current_charset = 'L';
                        continue;
                    }

                    // 数字锁定
                    if (bits == "11110")
                    {
                        current_charset = 'd';
                        continue;
                    }

                    // 数字 shift
                    if (bits == "11111")
                    {
                        save_charset    = current_charset;
                        current_charset = 'D';
                        continue;
                    }
                }

                // 切换命令
                if (current_charset == 'l' || current_charset == 'L')
                {
                    // 大写锁定
                    if (bits == "11100")
                    {
                        current_charset = 'u';
                        continue;
                    }

                    // 大写 shift
                    if (bits == "11101")
                    {
                        save_charset    = current_charset;
                        current_charset = 'U';
                        continue;
                    }

                    // 数字锁定
                    if (bits == "11110")
                    {
                        current_charset = 'd';
                        continue;
                    }

                    // 数字 shift
                    if (bits == "11111")
                    {
                        save_charset    = current_charset;
                        current_charset = 'D';
                        continue;
                    }
                }

                // 切换命令
                if (current_charset == 'd' || current_charset == 'D')
                {
                    // 大写锁定
                    if (bits == "1100")
                    {
                        current_charset = 'u';
                        continue;
                    }

                    // 大写 shift
                    if (bits == "1101")
                    {
                        save_charset    = current_charset;
                        current_charset = 'U';
                        continue;
                    }

                    // 小写锁定
                    if (bits == "1110")
                    {
                        current_charset = 'l';
                        continue;
                    }

                    // 小写 shift
                    if (bits == "1111")
                    {
                        save_charset    = current_charset;
                        current_charset = 'L';
                        continue;
                    }
                }

                char ch = (char)BitExtract.ToByte(bits, bit_count);

                if (current_charset == 'u' || current_charset == 'U')
                {
                    if (bits == "00000")
                    {
                        result.Append('-');
                    }
                    else if (bits == "11011")
                    {
                        result.Append(':');
                    }
                    else if (ch >= 0x01 && ch <= 0x1a)
                    {
                        result.Append((char)(ch - 1 + 'A'));
                    }
                    else
                    {
                        throw new Exception("error 1");
                    }

                    if (current_charset == 'U')
                    {
                        current_charset = save_charset;
                    }
                    continue;
                }

                if (current_charset == 'l' || current_charset == 'L')
                {
                    if (bits == "00000")
                    {
                        result.Append('-');
                    }
                    else if (bits == "11011")
                    {
                        result.Append('/');
                    }
                    else if (ch >= 0x01 && ch <= 0x1a)
                    {
                        result.Append((char)(ch - 1 + 'a'));
                    }
                    else
                    {
                        throw new Exception("error 2");
                    }

                    if (current_charset == 'L')
                    {
                        current_charset = save_charset;
                    }
                    continue;
                }

                if (current_charset == 'd' || current_charset == 'D')
                {
                    if (bits == "1010")
                    {
                        result.Append('-');
                    }
                    else if (bits == "1011")
                    {
                        result.Append(':');
                    }
                    else if (ch >= 0 && ch <= 0x09)
                    {
                        result.Append((char)('0' + ch));
                        continue;
                    }
                    else
                    {
                        throw new Exception("error 3");
                    }

                    if (current_charset == 'D')
                    {
                        current_charset = save_charset;
                    }
                    continue;
                }

                break;
            }

            return(result.ToString());
        }