支持GB2312、BIG5编码
Inheritance: Encoding
コード例 #1
0
ファイル: Encoding.cs プロジェクト: cmpute/iTV6
        /// <summary>
        /// 获取Encoding(非BIG5、GB2312编码调用原有的Encoding.GetEncoding)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static new Encoding GetEncoding(string name)
        {
            if (!_supportedEncoding.Any(m => m.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                return(Encoding.GetEncoding(name));
            }

            name = name.ToLower();
            SuperEncoding encoding = new SuperEncoding();

            encoding._webName = name;
            if (_cache.ContainsKey(name))
            {
                var tuple = _cache[name];
                encoding._dbcsToUnicode = tuple.Item1;
                encoding._unicodeToDbcs = tuple.Item2;
                return(encoding);
            }
            var dbcsToUnicode = new char[0x10000];
            var unicodeToDbcs = new ushort[0x10000];

            /*
             * According to many feedbacks, add this automatic function for finding resource in revision 1.0.0.1.
             * We suggest that use the old method as below if you understand how to embed the resource.
             * Please make sure the *.bin file was correctly embedded if throw an exception at here.
             */
            using (Stream stream = typeof(SuperEncoding).GetTypeInfo().Assembly
                                   .GetManifestResourceStream(typeof(SuperEncoding).GetTypeInfo().Assembly.
                                                              GetManifestResourceNames().Single(s => s.EndsWith("." + name + ".bin"))))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    for (int i = 0; i < 0xffff; i++)
                    {
                        ushort u = reader.ReadUInt16();
                        unicodeToDbcs[i] = u;
                    }
                    for (int i = 0; i < 0xffff; i++)
                    {
                        ushort u = reader.ReadUInt16();
                        dbcsToUnicode[i] = (char)u;
                    }
                }

            _cache[name]            = new Tuple <char[], ushort[]>(dbcsToUnicode, unicodeToDbcs);
            encoding._dbcsToUnicode = dbcsToUnicode;
            encoding._unicodeToDbcs = unicodeToDbcs;
            return(encoding);
        }
コード例 #2
0
        /// <summary>
        /// 获取Encoding(非BIG5、GB2312编码调用原有的Encoding.GetEncoding)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static new Encoding GetEncoding(string name)
        {
            if (!_supportedEncoding.Any(m => m.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                return Encoding.GetEncoding(name);
            }

            name = name.ToLower();
            SuperEncoding encoding = new SuperEncoding();
            encoding._webName = name;
            if (_cache.ContainsKey(name))
            {
                var tuple = _cache[name];
                encoding._dbcsToUnicode = tuple.Item1;
                encoding._unicodeToDbcs = tuple.Item2;
                return encoding;
            }
            var dbcsToUnicode = new char[0x10000];
            var unicodeToDbcs = new ushort[0x10000];
            /*
             * According to many feedbacks, add this automatic function for finding resource in revision 1.0.0.1.
             * We suggest that use the old method as below if you understand how to embed the resource.
             * Please make sure the *.bin file was correctly embedded if throw an exception at here.
             */
            using (Stream stream = typeof(SuperEncoding).GetTypeInfo().Assembly
                .GetManifestResourceStream(typeof(SuperEncoding).GetTypeInfo().Assembly.
                GetManifestResourceNames().Single(s => s.EndsWith("." + name + ".bin"))))
            using (BinaryReader reader = new BinaryReader(stream))
            {
                for (int i = 0; i < 0xffff; i++)
                {
                    ushort u = reader.ReadUInt16();
                    unicodeToDbcs[i] = u;
                }
                for (int i = 0; i < 0xffff; i++)
                {
                    ushort u = reader.ReadUInt16();
                    dbcsToUnicode[i] = (char)u;
                }
            }

            _cache[name] = new Tuple<char[], ushort[]>(dbcsToUnicode, unicodeToDbcs);
            encoding._dbcsToUnicode = dbcsToUnicode;
            encoding._unicodeToDbcs = unicodeToDbcs;
            return encoding;
        }
コード例 #3
0
ファイル: Encoding.cs プロジェクト: Hanyuz1996/iTV6
 public SuperDecoder(SuperEncoding encoding)
 {
     _encoding = encoding;
 }
コード例 #4
0
 public SuperDecoder(SuperEncoding encoding)
 {
     _encoding = encoding;
 }