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).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); }
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).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; }
public DBCSDecoder(DBCSEncoding encoding) { _encoding = encoding; }