Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/charsetmapping/EUC_TW.java
32287 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.charsetmapping;2627import java.io.*;28import java.util.ArrayList;29import java.util.Scanner;30import java.util.Formatter;31import java.util.regex.*;32import java.nio.charset.*;33import static build.tools.charsetmapping.Utils.*;3435public class EUC_TW {3637static char[] toCharArray(int[] db,38int b1Min, int b1Max,39int b2Min, int b2Max)40{41char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];42int off = 0;43for (int b1 = b1Min; b1 <= b1Max; b1++) {44for (int b2 = b2Min; b2 <= b2Max; b2++) {45ca[off++] = (char)(db[b1 * 256 + b2] & 0xffff);46}47}48return ca;49}5051static char[] toCharArray(byte[] ba,52int b1Min, int b1Max,53int b2Min, int b2Max)54{55char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];56int off = 0;57for (int b1 = b1Min; b1 <= b1Max; b1++) {58int b2 = b2Min;59while (b2 <= b2Max) {60ca[off++] = (char)(((ba[b1 * 256 + b2++] & 0xff) << 8) |61(ba[b1 * 256 + b2++] & 0xff));62}63}64return ca;65}6667private static int initC2BIndex(char[] index) {68int off = 0;69for (int i = 0; i < index.length; i++) {70if (index[i] != 0) {71index[i] = (char)off;72off += 0x100;73} else {74index[i] = UNMAPPABLE_ENCODING;75}76}77return off;78}7980private static Pattern euctw = Pattern.compile("(?:8ea)?(\\p{XDigit}++)\\s++(\\p{XDigit}++)?\\s*+.*");8182static void genClass(String args[]) throws Exception83{84InputStream is = new FileInputStream(new File(args[0], "euc_tw.map"));85PrintStream ps = new PrintStream(new File(args[1], "EUC_TWMapping.java"),86"ISO-8859-1");87String copyright = getCopyright(new File(args[3]));888990// ranges of byte1 and byte2, something should come from a "config" file91int b1Min = 0xa1;92int b1Max = 0xfe;93int b2Min = 0xa1;94int b2Max = 0xfe;9596try {97int[][] db = new int[8][0x10000]; // doublebyte98byte[] suppFlag = new byte[0x10000]; // doublebyte99char[] indexC2B = new char[256];100char[] indexC2BSupp = new char[256];101102for (int i = 0; i < 8; i++)103for (int j = 0; j < 0x10000; j++)104db[i][j] = UNMAPPABLE_DECODING;105106Parser p = new Parser(is, euctw);107Entry e = null;108while ((e = p.next()) != null) {109int plane = 0;110if (e.bs >= 0x10000) {111plane = ((e.bs >> 16) & 0xff) - 1;112if (plane >= 14)113plane = 7;114e.bs = e.bs & 0xffff;115}116db[plane][e.bs] = e.cp;117if (e.cp < 0x10000) {118indexC2B[e.cp>>8] = 1;119} else {120indexC2BSupp[(e.cp&0xffff)>>8] = 1;121suppFlag[e.bs] |= (1 << plane);122}123}124125StringBuilder sb = new StringBuilder();126Output out = new Output(new Formatter(sb));127128out.format(copyright);129out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");130out.format("package sun.nio.cs.ext;%n%n");131out.format("class EUC_TWMapping {%n%n");132133// boundaries134out.format(" final static int b1Min = 0x%x;%n", b1Min);135out.format(" final static int b1Max = 0x%x;%n", b1Max);136out.format(" final static int b2Min = 0x%x;%n", b2Min);137out.format(" final static int b2Max = 0x%x;%n", b2Max);138139// b2c tables140out.format("%n final static String[] b2c = {%n");141for (int plane = 0; plane < 8; plane++) {142out.format(" // Plane %d%n", plane);143out.format(toCharArray(db[plane], b1Min, b1Max, b2Min, b2Max),144",");145out.format("%n");146}147out.format(" };%n");148149// c2bIndex150out.format("%n static final int C2BSIZE = 0x%x;%n",151initC2BIndex(indexC2B));152out.format("%n static char[] c2bIndex = new char[] {%n");153out.format(indexC2B);154out.format(" };%n");155156// c2bIndexSupp157out.format("%n static final int C2BSUPPSIZE = 0x%x;%n",158initC2BIndex(indexC2BSupp));159out.format("%n static char[] c2bSuppIndex = new char[] {%n");160out.format(indexC2BSupp);161out.format(" };%n");162163// suppFlags164out.format("%n static String b2cIsSuppStr =%n");165out.format(toCharArray(suppFlag, b1Min, b1Max, b2Min, b2Max),166";");167out.format("}");168out.close();169170ps.println(sb.toString());171ps.close();172} catch (Exception x) {173x.printStackTrace();174}175}176}177178179