Inheritance: System.Text.Encoding
Esempio n. 1
0
        public static DBCSEncoding GetDBCSEncoding(string name)
        {
            name = name.ToLower();
            DBCSEncoding encoding = new DBCSEncoding();

            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(DBCSEncoding).Assembly.GetManifestResourceStream(typeof(DBCSEncoding).Namespace + "." + name + ".bin"))
            Assembly assembly   = Assembly.Load(new AssemblyName("BJUTHelper"));
            string   gb2312name = "";

            foreach (string item in assembly.GetManifestResourceNames())
            {
                if (item.Contains("gb2312"))
                {
                    gb2312name = item;
                    break;
                }
            }
            using (Stream stream = assembly.GetManifestResourceStream(gb2312name))
                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);
        }
Esempio n. 2
0
        public static DBCSEncoding GetDBCSEncoding(string name)
        {
            name = name.ToLower();
            DBCSEncoding encoding = new DBCSEncoding();
            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(DBCSEncoding).Assembly.GetManifestResourceStream(typeof(DBCSEncoding).Namespace + "." + name + ".bin"))
            using (Stream stream = typeof(DBCSEncoding).GetTypeInfo()
                                                       .Assembly
                                                       .GetManifestResourceStream(typeof(DBCSEncoding).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;
        }
Esempio n. 3
0
        public static DBCSEncoding GetDBCSEncoding(string name)
        {
            name = name.ToLower();
            DBCSEncoding encoding = new DBCSEncoding();

            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 = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(name + ".bin").AsTask().Result.OpenStreamForReadAsync().Result)
                //using (Stream stream = typeof(DBCSEncoding).Assembly.GetManifestResourceStream(typeof(DBCSEncoding).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);
        }
Esempio n. 4
0
 public DBCSDecoder(DBCSEncoding encoding)
 {
     _encoding = encoding;
 }
Esempio n. 5
0
 public DBCSDecoder(DBCSEncoding encoding)
 {
     _encoding = encoding;
 }