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 static CharsetCollection supportedCharsets;
32 #region Static Properties
34 public static CharsetCollection SupportedCharsets
38 if (Charset.supportedCharsets == null)
40 Charset.InitializeSupportedCharsets();
43 return Charset.supportedCharsets;
47 public static Charset DefaultCharset
49 get { return Charset.SupportedCharsets[0]; }
57 private int bytesPerCharacter;
59 private string systemName;
67 get { return this.id; }
72 get { return this.name; }
75 public int BytesPerCharacter
77 get { return this.bytesPerCharacter; }
85 int id, string name, int bytesPerCharacter, string systemName)
89 this.bytesPerCharacter = bytesPerCharacter;
90 this.systemName = systemName;
97 public byte[] GetBytes(string s)
99 return this.GetEncoding().GetBytes(s);
102 public int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
104 return this.GetEncoding().GetBytes(s, charIndex, charCount, bytes, byteIndex);
107 public string GetString(byte[] buffer)
109 return this.GetString(buffer, 0, buffer.Length);
112 public string GetString(byte[] buffer, int index, int count)
114 return this.GetEncoding().GetString(buffer, index, count);
119 #region Private Methods
121 private Encoding GetEncoding()
123 switch (this.systemName)
126 return Encoding.Default;
129 return new BinaryEncoding();
132 return Encoding.GetEncoding(this.systemName);
138 #region Static Methods
140 public static void InitializeSupportedCharsets()
142 Charset.supportedCharsets = new CharsetCollection();
145 Charset.Add(0, "NONE", 1, "NONE");
147 Charset.Add(1, "OCTETS", 1, "OCTETS");
148 // American Standard Code for Information Interchange
149 Charset.Add(2, "ASCII", 1, "ascii");
150 // Eight-bit Unicode Transformation Format
151 Charset.Add(3, "UNICODE_FSS", 3, "UTF-8");
152 // Shift-JIS, Japanese
153 Charset.Add(5, "SJIS_0208", 2, "shift_jis");
154 // JIS X 0201, 0208, 0212, EUC encoding, Japanese
155 Charset.Add(6, "EUCJ_0208", 2, "euc-jp");
157 Charset.Add(7, "ISO2022-JP", 2, "iso-2022-jp");
158 // MS-DOS United States, Australia, New Zealand, South Africa
159 Charset.Add(10, "DOS437", 1, "IBM437");
161 Charset.Add(11, "DOS850", 1, "ibm850");
163 Charset.Add(12, "DOS865", 1, "IBM865");
165 Charset.Add(13, "DOS860", 1, "IBM860");
166 // MS-DOS Canadian French
167 Charset.Add(14, "DOS863", 1, "IBM863");
168 // ISO 8859-1, Latin alphabet No. 1
169 Charset.Add(21, "ISO8859_1", 1, "iso-8859-1");
170 // ISO 8859-2, Latin alphabet No. 2
171 Charset.Add(22, "ISO8859_2", 1, "iso-8859-2");
173 Charset.Add(44, "KSC_5601", 2, "ks_c_5601-1987");
175 Charset.Add(47, "DOS861", 1, "ibm861");
176 // Windows Eastern European
177 Charset.Add(51, "WIN1250", 1, "windows-1250");
179 Charset.Add(52, "WIN1251", 1, "windows-1251");
181 Charset.Add(53, "WIN1252", 1, "windows-1252");
183 Charset.Add(54, "WIN1253", 1, "windows-1253");
185 Charset.Add(55, "WIN1254", 1, "windows-1254");
186 // Big5, Traditional Chinese
187 Charset.Add(56, "BIG_5", 2, "big5");
188 // GB2312, EUC encoding, Simplified Chinese
189 Charset.Add(57, "GB_2312", 2, "gb2312");
191 Charset.Add(58, "WIN1255", 1, "windows-1255");
193 Charset.Add(59, "WIN1256", 1, "windows-1256");
195 Charset.Add(60, "WIN1257", 1, "windows-1257");
198 private static void Add(
199 int id, string charset, int bytesPerCharacter, string systemName)
201 Charset.SupportedCharsets.Add(