2 * Copyright 2008 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.common;
19 import java.util.HashMap;
22 import com.google.zxing.FormatException;
25 * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1
30 public enum CharacterSetECI {
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"),
56 ASCII(new int[] {27, 170}, "US-ASCII"),
58 GB18030(29, "GB2312", "EUC_CN", "GBK"),
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>();
64 for (CharacterSetECI eci : values()) {
65 for (int value : eci.values) {
66 VALUE_TO_ECI.put(value, eci);
68 NAME_TO_ECI.put(eci.name(), eci);
69 for (String name : eci.otherEncodingNames) {
70 NAME_TO_ECI.put(name, eci);
75 private final int[] values;
76 private final String[] otherEncodingNames;
78 CharacterSetECI(int value) {
79 this(new int[] {value});
82 CharacterSetECI(int value, String... otherEncodingNames) {
83 this.values = new int[] {value};
84 this.otherEncodingNames = otherEncodingNames;
87 CharacterSetECI(int[] values, String... otherEncodingNames) {
89 this.otherEncodingNames = otherEncodingNames;
92 public int getValue() {
97 * @param value character set ECI value
98 * @return CharacterSetECI representing ECI of given value, or null if it is legal but
100 * @throws IllegalArgumentException if ECI value is invalid
102 public static CharacterSetECI getCharacterSetECIByValue(int value) throws FormatException {
103 if (value < 0 || value >= 900) {
104 throw FormatException.getFormatInstance();
106 return VALUE_TO_ECI.get(value);
110 * @param name character set ECI encoding name
111 * @return CharacterSetECI representing ECI for character encoding, or null if it is legal
114 public static CharacterSetECI getCharacterSetECIByName(String name) {
115 return NAME_TO_ECI.get(name);