Committed C# port from Mohamad
[zxing.git] / csharp / common / CharacterSetECI.cs
1 /*\r
2 * Copyright 2008 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 namespace com.google.zxing.common\r
17 {\r
18     using System;\r
19     using System.Text;\r
20     using System.Collections;\r
21 \r
22     /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
23     /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
24     /// *\r
25     /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
26     /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
27     /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
28     /// less memory and go with bytes.\r
29     /// *\r
30     /// </summary>\r
31     /// <author>  dswitkin@google.com (Daniel Switkin)\r
32     /// \r
33     /// </author>\r
34     public sealed class CharacterSetECI : ECI\r
35     { \r
36         private static Hashtable VALUE_TO_ECI=new Hashtable(29);\r
37         /*static VALUE_TO_ECI = new Hashtable(29){\r
38         // TODO figure out if these values are even right!\r
39         addCharacterSet(0, "Cp437");\r
40         addCharacterSet(1, "ISO8859_1");\r
41         addCharacterSet(2, "Cp437");\r
42         addCharacterSet(3, "ISO8859_1");\r
43         addCharacterSet(4, "ISO8859_2");\r
44         addCharacterSet(5, "ISO8859_3");\r
45         addCharacterSet(6, "ISO8859_4");\r
46         addCharacterSet(7, "ISO8859_5");\r
47         addCharacterSet(8, "ISO8859_6");\r
48         addCharacterSet(9, "ISO8859_7");\r
49         addCharacterSet(10, "ISO8859_8");\r
50         addCharacterSet(11, "ISO8859_9");\r
51         addCharacterSet(12, "ISO8859_10");\r
52         addCharacterSet(13, "ISO8859_11");\r
53         addCharacterSet(15, "ISO8859_13");\r
54         addCharacterSet(16, "ISO8859_14");\r
55         addCharacterSet(17, "ISO8859_15");\r
56         addCharacterSet(18, "ISO8859_16");\r
57         addCharacterSet(20, "SJIS");\r
58       }*/\r
59 \r
60       private String encodingName;\r
61      \r
62       private CharacterSetECI(int value, String encodingName):base(value) {\r
63         addCharacterSet(0, "Cp437");\r
64         addCharacterSet(1, "ISO8859_1");\r
65         addCharacterSet(2, "Cp437");\r
66         addCharacterSet(3, "ISO8859_1");\r
67         addCharacterSet(4, "ISO8859_2");\r
68         addCharacterSet(5, "ISO8859_3");\r
69         addCharacterSet(6, "ISO8859_4");\r
70         addCharacterSet(7, "ISO8859_5");\r
71         addCharacterSet(8, "ISO8859_6");\r
72         addCharacterSet(9, "ISO8859_7");\r
73         addCharacterSet(10, "ISO8859_8");\r
74         addCharacterSet(11, "ISO8859_9");\r
75         addCharacterSet(12, "ISO8859_10");\r
76         addCharacterSet(13, "ISO8859_11");\r
77         addCharacterSet(15, "ISO8859_13");\r
78         addCharacterSet(16, "ISO8859_14");\r
79         addCharacterSet(17, "ISO8859_15");\r
80         addCharacterSet(18, "ISO8859_16");\r
81         addCharacterSet(20, "SJIS");\r
82         this.encodingName = encodingName;\r
83       }\r
84 \r
85       public String getEncodingName() {\r
86         return encodingName;\r
87       }\r
88 \r
89       private static void addCharacterSet(int value, String encodingName) {\r
90         VALUE_TO_ECI.Add(value, new CharacterSetECI(value, encodingName));\r
91       }\r
92 \r
93       public static CharacterSetECI getCharacterSetECIByValue(int value) {          \r
94         CharacterSetECI eci = (CharacterSetECI) VALUE_TO_ECI[value];\r
95         if (eci == null) {\r
96           throw new Exception("Unsupported value: " + value);\r
97         }\r
98         return eci;\r
99       }\r
100     }\r
101 }