Skip to content

Commit

Permalink
Enable supported ECI charsets dynamically (#1625)
Browse files Browse the repository at this point in the history
* Enable supported ECI charsets dynamically

* Remove use of Java 9+ API

* Remove property-based override for dynamic ECI charsets
  • Loading branch information
gredler committed May 22, 2023
1 parent c062955 commit b892c40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions core/src/main/java/com/google/zxing/common/CharacterSetECI.java
Expand Up @@ -38,14 +38,14 @@ public enum CharacterSetECI {
ISO8859_3(5, "ISO-8859-3"),
ISO8859_4(6, "ISO-8859-4"),
ISO8859_5(7, "ISO-8859-5"),
// ISO8859_6(8, "ISO-8859-6"),
ISO8859_6(8, "ISO-8859-6"),
ISO8859_7(9, "ISO-8859-7"),
// ISO8859_8(10, "ISO-8859-8"),
ISO8859_8(10, "ISO-8859-8"),
ISO8859_9(11, "ISO-8859-9"),
// ISO8859_10(12, "ISO-8859-10"),
// ISO8859_11(13, "ISO-8859-11"),
ISO8859_10(12, "ISO-8859-10"),
ISO8859_11(13, "ISO-8859-11"),
ISO8859_13(15, "ISO-8859-13"),
// ISO8859_14(16, "ISO-8859-14"),
ISO8859_14(16, "ISO-8859-14"),
ISO8859_15(17, "ISO-8859-15"),
ISO8859_16(18, "ISO-8859-16"),
SJIS(20, "Shift_JIS"),
Expand All @@ -60,16 +60,19 @@ public enum CharacterSetECI {
GB18030(29, "GB2312", "EUC_CN", "GBK"),
EUC_KR(30, "EUC-KR");

// only character sets supported by the current JVM are registered here
private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<>();
private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<>();
static {
for (CharacterSetECI eci : values()) {
for (int value : eci.values) {
VALUE_TO_ECI.put(value, eci);
}
NAME_TO_ECI.put(eci.name(), eci);
for (String name : eci.otherEncodingNames) {
NAME_TO_ECI.put(name, eci);
if (Charset.isSupported(eci.name())) {
for (int value : eci.values) {
VALUE_TO_ECI.put(value, eci);
}
NAME_TO_ECI.put(eci.name(), eci);
for (String name : eci.otherEncodingNames) {
NAME_TO_ECI.put(name, eci);
}
}
}
}
Expand Down
Expand Up @@ -500,7 +500,7 @@ public void testECIs() {
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested to have originated from Hebrew " +
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)"));
assertEquals("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254" +
" 116 33 241 25 231 186 14 212 64 253 151 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184" +
" 116 33 241 9 231 186 14 206 64 248 144 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184" +
" 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114" +
" 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16 174 125 24 10 125 116 42 129",
visualized);
Expand Down

0 comments on commit b892c40

Please sign in to comment.