Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/charsetmapping/HKSCS.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.Arrays;29import java.util.ArrayList;30import java.util.Scanner;31import java.util.Formatter;32import java.util.regex.*;33import java.nio.charset.*;34import static build.tools.charsetmapping.Utils.*;3536public class HKSCS {3738// HKSCS2001.map has the third column for "UnicodeAlternate", which39// is for c->b non-roundtrip mapping.40// For HKSCS2008, those non-roundtrip mappings are in .nr file41private static Pattern hkscs =42Pattern.compile("(?:0x)?+(\\p{XDigit}++)\\s++(?:0x|U\\+)?+(\\p{XDigit}++)?\\s*+(?:0x|U\\+)?(\\p{XDigit}++)?\\s*+.*");4344static void genClass(String args[]) throws Exception {4546// hkscs200847genClass0(new FileInputStream(new File(args[0], "HKSCS2008.map")),48new FileInputStream(new File(args[0], "HKSCS2008.c2b")),49new PrintStream(new File(args[1], "HKSCSMapping.java"),50"ISO-8859-1"),51"HKSCSMapping",52getCopyright(new File(args[3])));535455// xp200156genClass0(new FileInputStream(new File(args[0], "HKSCS_XP.map")),57null,58new PrintStream(new File(args[1], "HKSCS_XPMapping.java"),59"ISO-8859-1"),60"HKSCS_XPMapping",61getCopyright(new File(args[3])));6263// hkscs200164genClass0(new FileInputStream(new File(args[0], "HKSCS2001.map")),65new FileInputStream(new File(args[0], "HKSCS2001.c2b")),66new PrintStream(new File(args[1], "HKSCS2001Mapping.java"),67"ISO-8859-1"),68"HKSCS2001Mapping",69getCopyright(new File(args[3])));70}7172static void genClass0(InputStream isB2C,73InputStream isC2B,74PrintStream ps,75String clzName,76String copyright)77throws Exception78{79// ranges of byte1 and byte2, something should come from a "config" file80int b1Min = 0x87;81int b1Max = 0xfe;82int b2Min = 0x40;83int b2Max = 0xfe;8485try {86char[] bmp = new char[0x10000];87char[] supp = new char[0x10000];8889boolean[] b2cBmp = new boolean[0x100];90boolean[] b2cSupp = new boolean[0x100];91// pua should be in range of e000-f8ff. Expand92// it to 0xf93b becase the hkscs2001.c2b has93// the f920-f93b filled94//char[] pua = new char[0xF8FF - 0xE000 + 1];95char[] pua = new char[0xF93b - 0xE000 + 1];96boolean hasSupp = false;97boolean hasPua = false;9899Arrays.fill(bmp, UNMAPPABLE_DECODING);100Arrays.fill(supp, UNMAPPABLE_DECODING);101Arrays.fill(pua, UNMAPPABLE_DECODING);102103Parser p = new Parser(isB2C, hkscs);104Entry e = null;105while ((e = p.next()) != null) {106if (e.cp >= 0x10000) {107supp[e.bs] = (char)e.cp;108b2cSupp[e.bs>>8] = true;109hasSupp = true;110} else {111bmp[e.bs] = (char)e.cp;112b2cBmp[e.bs>>8] = true;113}114if (e.cp2 != 0 && e.cp2 >= 0xe000 && e.cp2 <= 0xf8ff) {115hasPua = true;116pua[e.cp2 - 0xE000] = (char)e.bs;117}118}119120if (isC2B != null) {121p = new Parser(isC2B, hkscs);122e = null;123while ((e = p.next()) != null) {124pua[e.cp - 0xE000] = (char)e.bs;125}126hasPua = true;127}128129StringBuilder sb = new StringBuilder();130Output out = new Output(new Formatter(sb));131132out.format(copyright);133out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");134out.format("package sun.nio.cs.ext;%n%n");135out.format("class %s {%n%n", clzName);136137/* hardcoded in sun.nio.cs.ext.HKSCS.java138out.format(" final static int b1Min = 0x%x;%n", b1Min);139out.format(" final static int b1Max = 0x%x;%n", b1Max);140out.format(" final static int b2Min = 0x%x;%n", b2Min);141out.format(" final static int b2Max = 0x%x;%n", b2Max);142*/143144// bmp tables145out.format("%n static final String[] b2cBmpStr = new String[] {%n");146for (int i = 0; i < 0x100; i++) {147if (b2cBmp[i])148out.format(bmp, i, b2Min, b2Max, ",");149else150out.format(" null,%n"); //unmappable segments151}152out.format(" };%n");153154// supp tables155out.format("%n static final String[] b2cSuppStr =");156if (hasSupp) {157out.format(" new String[] {%n");158for (int i = 0; i < 0x100; i++) {159if (b2cSupp[i])160out.format(supp, i, b2Min, b2Max, ",");161else162out.format(" null,%n"); //unmappable segments163}164out.format(" };%n");165} else {166out.format(" null;%n");167}168169// private area tables170out.format("%n final static String pua =");171if (hasPua) {172out.format("%n");173out.format(pua, 0, pua.length, ";");174} else {175out.format(" null;%n");176}177out.format("%n");178out.format("}");179180out.close();181182ps.println(sb.toString());183ps.close();184185} catch (Exception x) {186x.printStackTrace();187}188}189}190191192