--- /dev/null 2018-10-26 11:50:55 +0000 +++ new/src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM33722.java.template 2018-10-26 11:50:54 +0000 @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package $PACKAGE$; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import java.nio.charset.CoderResult; +import sun.nio.cs.HistoricallyNamedCharset; +import sun.nio.cs.DelegatableDecoder; +import sun.nio.cs.DoubleByte; +import sun.nio.cs.Surrogate; +import sun.nio.cs.SingleByte; +import sun.nio.cs.*; +import static sun.nio.cs.CharsetMapping.*; + +public class IBM33722 + extends Charset + implements HistoricallyNamedCharset +{ + public IBM33722() { + super("x-IBM33722", $ALIASES$); + } + + public String historicalName() { + return "Cp33722"; + } + + public boolean contains(Charset cs) { + return ((cs.name().equals("US-ASCII")) + || (cs instanceof IBM33722)); + } + + public CharsetDecoder newDecoder() { + return new Decoder(this); + } + + public CharsetEncoder newEncoder() { + return new Encoder(this); + } + + private static class Decoder extends IBM29626C.Decoder { + + private final String G2_b = "\uA1F1\uA1F2\uA2CC"; + + private final String G2_c = "\uFFE0\uFFE1\uFFE2"; + + private final String G3_b = + "\uF3B8\uF3B9\uF3AB\uF3AC\uF3AD\uF3AE\uF3AF\uF3B0\uF3B1\uF3B2"+ + "\uF3B3\uF3B4\uF3A1\uF3A2\uF3A3\uF3A4\uF3A5\uF3A6\uF3A7\uF3A8"+ + "\uF3A9\uF3AA\uF3B7\uF4A2\uF4A3\uF4A4\uF4A5\uF4A6\uF4A8\uF4A9"+ + "\uF4AC\uF4AE\uF4AF\uF4B0\uF4B2\uF4B3\uF4B4\uF4B5\uF4B6\uF4B7"+ + "\uF4BA\uF4BD\uF4BE\uF4C0\uF4BF\uF4C2\uF4A1\uF4C6\uF4C7\uF4C8"+ + "\uF4CB\uF4D0\uF4D4\uF4D5\uF4D7\uF4D9\uF4DC\uF4DF\uF4E0\uF4E1"+ + "\uF4E5\uF4E7\uF4EA\uF4ED\uF4EE\uF4EF\uF4F4\uF4F5\uF4F6\uF4F8"+ + "\uF4B9\uF4EB\uF4A7\uF4AA\uF4AB\uF4B1\uF4B8\uF4BB\uF4BC\uF4C4"+ + "\uF4C5\uF4C9\uF4CC\uF4CD\uF4CE\uF4CF\uF4D1\uF4D3\uF4D6\uF4D8"+ + "\uF4DA\uF4DB\uF4DE\uF4E2\uF4E3\uF4E4\uF4E6\uF4E8\uF4E9\uF4EC"+ + "\uF4F1\uF4F2\uF4F3\uF4F7\uF3B6\uF3B5"; + + private final String G3_c = + "\u2116\u2121\u2160\u2161\u2162\u2163\u2164\u2165\u2166\u2167"+ + "\u2168\u2169\u2170\u2171\u2172\u2173\u2174\u2175\u2176\u2177"+ + "\u2178\u2179\u3231\u4EFC\u50F4\u51EC\u5307\u5324\u548A\u5759"+ + "\u589E\u5BEC\u5CF5\u5D53\u5FB7\u6085\u6120\u654E\u663B\u6665"+ + "\u6801\u6A6B\u6AE2\u6DF2\u6DF8\u7028\u70BB\u7501\u7682\u769E"+ + "\u7930\u7AE7\u7DA0\u7DD6\u8362\u85B0\u8807\u8B7F\u8CF4\u8D76"+ + "\u90DE\u9115\u9592\u973B\u974D\u9751\u999E\u9AD9\u9B72\u9ED1"+ + "\uF929\uF9DC\uFA0E\uFA0F\uFA10\uFA11\uFA12\uFA13\uFA14\uFA15"+ + "\uFA16\uFA17\uFA18\uFA19\uFA1A\uFA1B\uFA1C\uFA1D\uFA1E\uFA1F"+ + "\uFA20\uFA21\uFA22\uFA23\uFA24\uFA25\uFA26\uFA27\uFA28\uFA29"+ + "\uFA2A\uFA2B\uFA2C\uFA2D\uFF02\uFF07"; + + private final SingleByte.Decoder dec0201; + private final DoubleByte.Decoder dec0208; + private final DoubleByte.Decoder dec0212; + + protected Decoder(Charset cs) { + super(cs); + this.dec0201 = DEC0201; + this.dec0208 = DEC0208; + this.dec0212 = DEC0212; + } + + protected char decodeSingle(int b) { + if (b == 0x5c) + return '\u00A5'; + if (b == 0x7e) + return '\u203E'; + if (b < 0x8e) + return (char) b; + if (b < 0x90) + return UNMAPPABLE_DECODING; + if (b < 0xa0) + return (char) b; + return UNMAPPABLE_DECODING; + } + + final static String g1_c = "\u00a2\u00a3\u00ac\\\u007e"; + + protected char decodeDouble(int byte1, int byte2) { + if (byte1 == 0x8e) { + if (byte2 < 0x80) + return UNMAPPABLE_DECODING; + char c = dec0201.decode((byte)byte2); + if (byte2 >= 0xe0 && byte2 <= 0xe4) + c = g1_c.charAt(byte2 - 0xe0); + return c; + } + if ((byte1 >= 0xa1 && byte1 <= 0xfe) + && (byte2 >= 0xa1 && byte2 <= 0xfe)) { + char c = (char)((byte1 << 8) + byte2); + int idx = G2_b.indexOf(c); + if (idx > -1) + return G2_c.charAt(idx); + } + char ch = dec0208.decodeDouble(byte1 - 0x80, byte2 - 0x80); + if (ch == UNMAPPABLE_DECODING) + ch = decodeUDC(byte1, byte2, 0xe000); + return ch; + } + + protected char decodeDoubleG3(int byte1, int byte2) { + if ((byte1 >= 0xa1 && byte1 <= 0xfe) + && (byte2 >= 0xa1 && byte2 <= 0xfe)) { + char c = (char)((byte1 << 8) + byte2); + int idx = G3_b.indexOf(c); + if (idx > -1) + return G3_c.charAt(idx); + } + char ch = dec0212.decodeDouble(byte1 - 0x80, byte2 - 0x80); + if (ch == '\u2116') + ch = UNMAPPABLE_DECODING; + if (ch != UNMAPPABLE_DECODING) + ch = ibm943.canEncode(ch) ? ch : UNMAPPABLE_DECODING; + if (ch == UNMAPPABLE_DECODING) + ch = decodeUDC(byte1, byte2, 0xe3ac); + return ch; + } + } + + private static class Encoder extends IBM29626C.Encoder { + + private final String G2_c = + "\u2015\u2225\u4FE0\u525D\u551E\u555E\u5699\u56CA\u5861\u5C5B"+ + "\u5C62\u6414\u6451\u6522\u6805\u688E\u6D00\u6F1E\u6F51\u7006"+ + "\u70FF\u7130\u7626\u79B1\u7C1E\u7E48\u7E61\u7E6B\u8141\u8346"+ + "\u840A\u8523\u8741\u881F\u8EC0\u91AC\u91B1\u92CA\u9830\u9839"+ + "\u985A\u9A52\u9DD7\u9E7C\u9EB4\u9EB5\uFF0D\uFF5E\uFFE0\uFFE1"+ + "\uFFE2\uFFE4"; + + private final String G2_b = + "\uA1BD\uA1C2\uB6A2\uC7ED\uC0E6\uB0A2\uB3FA\uC7B9\uC5B6\uD6A2"+ + "\uBCC8\uC1DF\uC4CF\uDAB9\uBAF4\uDBF4\uC6C2\uC2CD\uC8AE\uC6C2"+ + "\uB6A2\uB1EB\uC1E9\uC5F8\uC3BD\uE5DA\uBDAB\uB7D2\uE7A6\uB7D5"+ + "\uCDE9\uBED5\uB0A2\uCFB9\uB6ED\uBEDF\uC8B0\uB3FA\uCBCB\uF0F8"+ + "\uC5BF\uC2CD\uB2AA\uB8B4\uB9ED\uCCCD\uA1DD\uA1C1\uA1F1\uA1F2"+ + "\uA2CC\uA2C3"; + + private final String G3_c = + "\u2116\u2121\u2160\u2161\u2162\u2163\u2164\u2165\u2166\u2167"+ + "\u2168\u2169\u2170\u2171\u2172\u2173\u2174\u2175\u2176\u2177"+ + "\u2178\u2179\u3231\u4EFC\u50F4\u51EC\u5307\u5324\u548A\u5759"+ + "\u589E\u5BEC\u5CF5\u5D53\u5FB7\u6085\u6120\u654E\u663B\u6665"+ + "\u6801\u6A6B\u6AE2\u6DF2\u6DF8\u7028\u70BB\u7501\u7682\u769E"+ + "\u7930\u7AE7\u7DA0\u7DD6\u8362\u85B0\u8807\u8B7F\u8CF4\u8D76"+ + "\u8F91\u90DE\u9115\u9592\u973B\u974D\u9751\u999E\u9AD9\u9B72"+ + "\u9ED1\uF86F\uF929\uF9DC\uFA0E\uFA0F\uFA10\uFA11\uFA12\uFA13"+ + "\uFA14\uFA15\uFA16\uFA17\uFA18\uFA19\uFA1A\uFA1B\uFA1C\uFA1D"+ + "\uFA1E\uFA1F\uFA20\uFA21\uFA22\uFA23\uFA24\uFA25\uFA26\uFA27"+ + "\uFA28\uFA29\uFA2A\uFA2B\uFA2C\uFA2D\uFF02\uFF07"; + + private final String G3_b = + "\uF3B8\uF3B9\uF3AB\uF3AC\uF3AD\uF3AE\uF3AF\uF3B0\uF3B1\uF3B2"+ + "\uF3B3\uF3B4\uF3A1\uF3A2\uF3A3\uF3A4\uF3A5\uF3A6\uF3A7\uF3A8"+ + "\uF3A9\uF3AA\uF3B7\uF4A2\uF4A3\uF4A4\uF4A5\uF4A6\uF4A8\uF4A9"+ + "\uF4AC\uF4AE\uF4AF\uF4B0\uF4B2\uF4B3\uF4B4\uF4B5\uF4B6\uF4B7"+ + "\uF4BA\uF4BD\uF4BE\uF4C0\uF4BF\uF4C2\uF4A1\uF4C6\uF4C7\uF4C8"+ + "\uF4CB\uF4D0\uF4D4\uF4D5\uF4D7\uF4D9\uF4DC\uF4DF\uF4E0\uF4E1"+ + "\uF3B8\uF4E5\uF4E7\uF4EA\uF4ED\uF4EE\uF4EF\uF4F4\uF4F5\uF4F6"+ + "\uF4F8\uF3B8\uF4B9\uF4EB\uF4A7\uF4AA\uF4AB\uF4B1\uF4B8\uF4BB"+ + "\uF4BC\uF4C4\uF4C5\uF4C9\uF4CC\uF4CD\uF4CE\uF4CF\uF4D1\uF4D3"+ + "\uF4D6\uF4D8\uF4DA\uF4DB\uF4DE\uF4E2\uF4E3\uF4E4\uF4E6\uF4E8"+ + "\uF4E9\uF4EC\uF4F1\uF4F2\uF4F3\uF4F7\uF3B6\uF3B5"; + + private final SingleByte.Encoder enc0201; + private final DoubleByte.Encoder enc0208; + private final DoubleByte.Encoder enc0212; + + protected Encoder(Charset cs) { + super(cs); + this.enc0201 = ENC0201; + this.enc0208 = ENC0208; + this.enc0212 = ENC0212; + } + + private final static String G1_c = "\u00A2\u00A3\u00AC\\\u007e"; + + protected int encodeSingle(char inputChar, byte[] outputByte) { + if (inputChar == 0xa5) { + outputByte[0] = (byte)0x5c; + return 1; + } + if (inputChar == 0x203e) { + outputByte[0] = (byte)0x7e; + return 1; + } + if (inputChar >= 0x80 && inputChar < 0x8e) { + outputByte[0] = (byte)inputChar; + return 1; + } + if (inputChar >= 0x90 && inputChar < 0xa0) { + outputByte[0] = (byte)inputChar; + return 1; + } + int b = enc0201.encode(inputChar); + if (inputChar == 0x5c || inputChar == 0x7e) { + b = UNMAPPABLE_ENCODING; + } + if (b == UNMAPPABLE_ENCODING) { + int idx = G1_c.indexOf(inputChar); + if (idx > -1) + b = 0xe0 + idx; + } + if (b == UNMAPPABLE_ENCODING) + return 0; + if (b >= 0 && b < 128) { + outputByte[0] = (byte)b; + return 1; + } + outputByte[0] = (byte)0x8e; + outputByte[1] = (byte)b; + return 2; + } + + protected int encodeDouble(char ch) { + int idx = G2_c.indexOf(ch); + if (idx > -1) + return (int)G2_b.charAt(idx); + idx = G3_c.indexOf(ch); + if (idx > -1) + return (int)G3_b.charAt(idx) + 0x8f0000; + int b = enc0208.encodeChar(ch); + if (b != UNMAPPABLE_ENCODING) + return b + 0x8080; + b = encodeUDC(ch); + if (b != UNMAPPABLE_ENCODING) + return b; + if (ibm943.canEncode(ch)) { + b = enc0212.encodeChar(ch); + if (b != UNMAPPABLE_ENCODING) { + b += 0x8f8080; + return b; + } + } + return b; + } + } +}