]> Pileus Git - ~andy/freeotp/blob - src/com/google/zxing/common/CharacterSetECI.java
Add native camera support
[~andy/freeotp] / src / com / google / zxing / common / CharacterSetECI.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.common;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import com.google.zxing.FormatException;
23
24 /**
25  * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1
26  * of ISO 18004.
27  *
28  * @author Sean Owen
29  */
30 public enum CharacterSetECI {
31
32   // Enum name is a Java encoding valid for java.lang and java.io
33   Cp437(new int[]{0,2}),
34   ISO8859_1(new int[]{1,3}, "ISO-8859-1"),
35   ISO8859_2(4, "ISO-8859-2"),
36   ISO8859_3(5, "ISO-8859-3"),
37   ISO8859_4(6, "ISO-8859-4"),
38   ISO8859_5(7, "ISO-8859-5"),
39   ISO8859_6(8, "ISO-8859-6"),
40   ISO8859_7(9, "ISO-8859-7"),
41   ISO8859_8(10, "ISO-8859-8"),
42   ISO8859_9(11, "ISO-8859-9"),
43   ISO8859_10(12, "ISO-8859-10"),
44   ISO8859_11(13, "ISO-8859-11"),
45   ISO8859_13(15, "ISO-8859-13"),
46   ISO8859_14(16, "ISO-8859-14"),
47   ISO8859_15(17, "ISO-8859-15"),
48   ISO8859_16(18, "ISO-8859-16"),
49   SJIS(20, "Shift_JIS"),
50   Cp1250(21, "windows-1250"),
51   Cp1251(22, "windows-1251"),
52   Cp1252(23, "windows-1252"),
53   Cp1256(24, "windows-1256"),
54   UnicodeBigUnmarked(25, "UTF-16BE", "UnicodeBig"),
55   UTF8(26, "UTF-8"),
56   ASCII(new int[] {27, 170}, "US-ASCII"),
57   Big5(28),
58   GB18030(29, "GB2312", "EUC_CN", "GBK"),
59   EUC_KR(30, "EUC-KR");
60
61   private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<Integer, CharacterSetECI>();
62   private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<String, CharacterSetECI>();
63   static {
64     for (CharacterSetECI eci : values()) {
65       for (int value : eci.values) {
66         VALUE_TO_ECI.put(value, eci);
67       }
68       NAME_TO_ECI.put(eci.name(), eci);
69       for (String name : eci.otherEncodingNames) {
70         NAME_TO_ECI.put(name, eci);
71       }
72     }
73   }
74
75   private final int[] values;
76   private final String[] otherEncodingNames;
77
78   CharacterSetECI(int value) {
79     this(new int[] {value});
80   }
81
82   CharacterSetECI(int value, String... otherEncodingNames) {
83     this.values = new int[] {value};
84     this.otherEncodingNames = otherEncodingNames;
85   }
86
87   CharacterSetECI(int[] values, String... otherEncodingNames) {
88     this.values = values;
89     this.otherEncodingNames = otherEncodingNames;
90   }
91
92   public int getValue() {
93     return values[0];
94   }
95
96   /**
97    * @param value character set ECI value
98    * @return CharacterSetECI representing ECI of given value, or null if it is legal but
99    *   unsupported
100    * @throws IllegalArgumentException if ECI value is invalid
101    */
102   public static CharacterSetECI getCharacterSetECIByValue(int value) throws FormatException {
103     if (value < 0 || value >= 900) {
104       throw FormatException.getFormatInstance();
105     }
106     return VALUE_TO_ECI.get(value);
107   }
108
109   /**
110    * @param name character set ECI encoding name
111    * @return CharacterSetECI representing ECI for character encoding, or null if it is legal
112    *   but unsupported
113    */
114   public static CharacterSetECI getCharacterSetECIByName(String name) {
115     return NAME_TO_ECI.get(name);
116   }
117
118 }