2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
22 namespace FirebirdSql.Data.Common
24 internal sealed class Charset
28 private readonly static CharsetCollection supportedCharsets = Charset.InitializeSupportedCharsets();
32 #region Static Properties
34 public static CharsetCollection SupportedCharsets
36 get { return Charset.supportedCharsets; }
39 public static Charset DefaultCharset
41 get { return Charset.SupportedCharsets[0]; }
49 private int bytesPerCharacter;
51 private string systemName;
59 get { return this.id; }
64 get { return this.name; }
67 public int BytesPerCharacter
69 get { return this.bytesPerCharacter; }
77 int id, string name, int bytesPerCharacter, string systemName)
81 this.bytesPerCharacter = bytesPerCharacter;
82 this.systemName = systemName;
89 public byte[] GetBytes(string s)
91 return this.GetEncoding().GetBytes(s);
94 public int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
96 return this.GetEncoding().GetBytes(s, charIndex, charCount, bytes, byteIndex);
99 public string GetString(byte[] buffer)
101 return this.GetString(buffer, 0, buffer.Length);
104 public string GetString(byte[] buffer, int index, int count)
106 return this.GetEncoding().GetString(buffer, index, count);
111 #region Private Methods
113 private Encoding GetEncoding()
115 switch (this.systemName)
118 return Encoding.Default;
121 return new BinaryEncoding();
124 return Encoding.GetEncoding(this.systemName);
130 #region Static Methods
132 public static CharsetCollection InitializeSupportedCharsets()
134 CharsetCollection charsets = new CharsetCollection();
137 Charset.Add(charsets, 0, "NONE", 1, "NONE");
139 Charset.Add(charsets, 1, "OCTETS", 1, "OCTETS");
140 // American Standard Code for Information Interchange
141 Charset.Add(charsets, 2, "ASCII", 1, "ascii");
142 // Eight-bit Unicode Transformation Format
143 Charset.Add(charsets, 3, "UNICODE_FSS", 3, "UTF-8");
144 // Shift-JIS, Japanese
145 Charset.Add(charsets, 5, "SJIS_0208", 2, "shift_jis");
146 // JIS X 0201, 0208, 0212, EUC encoding, Japanese
147 Charset.Add(charsets, 6, "EUCJ_0208", 2, "euc-jp");
149 Charset.Add(charsets, 7, "ISO2022-JP", 2, "iso-2022-jp");
150 // MS-DOS United States, Australia, New Zealand, South Africa
151 Charset.Add(charsets, 10, "DOS437", 1, "IBM437");
153 Charset.Add(charsets, 11, "DOS850", 1, "ibm850");
155 Charset.Add(charsets, 12, "DOS865", 1, "IBM865");
157 Charset.Add(charsets, 13, "DOS860", 1, "IBM860");
158 // MS-DOS Canadian French
159 Charset.Add(charsets, 14, "DOS863", 1, "IBM863");
160 // ISO 8859-1, Latin alphabet No. 1
161 Charset.Add(charsets, 21, "ISO8859_1", 1, "iso-8859-1");
162 // ISO 8859-2, Latin alphabet No. 2
163 Charset.Add(charsets, 22, "ISO8859_2", 1, "iso-8859-2");
165 Charset.Add(charsets, 44, "KSC_5601", 2, "ks_c_5601-1987");
167 Charset.Add(charsets, 47, "DOS861", 1, "ibm861");
168 // Windows Eastern European
169 Charset.Add(charsets, 51, "WIN1250", 1, "windows-1250");
171 Charset.Add(charsets, 52, "WIN1251", 1, "windows-1251");
173 Charset.Add(charsets, 53, "WIN1252", 1, "windows-1252");
175 Charset.Add(charsets, 54, "WIN1253", 1, "windows-1253");
177 Charset.Add(charsets, 55, "WIN1254", 1, "windows-1254");
178 // Big5, Traditional Chinese
179 Charset.Add(charsets, 56, "BIG_5", 2, "big5");
180 // GB2312, EUC encoding, Simplified Chinese
181 Charset.Add(charsets, 57, "GB_2312", 2, "gb2312");
183 Charset.Add(charsets, 58, "WIN1255", 1, "windows-1255");
185 Charset.Add(charsets, 59, "WIN1256", 1, "windows-1256");
187 Charset.Add(charsets, 60, "WIN1257", 1, "windows-1257");
192 private static void Add(
193 CharsetCollection charsets, int id, string charset, int bytesPerCharacter, string systemName)