author | sherman |
Mon, 16 Feb 2015 14:53:59 -0800 | |
changeset 28969 | f980bee32887 |
parent 23010 | 6dadb192ad81 |
child 33663 | 2cd62a4bd471 |
permissions | -rw-r--r-- |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
1 |
/* |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
2 |
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
4 |
* |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
10 |
* |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
15 |
* accompanied this code). |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
16 |
* |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
24 |
*/ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
25 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
26 |
package build.tools.charsetmapping; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
27 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
28 |
import java.io.*; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
29 |
import java.util.Arrays; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
30 |
import java.util.ArrayList; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
31 |
import java.util.Scanner; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
32 |
import java.util.Formatter; |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
33 |
import java.util.regex.Pattern; |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
34 |
import static build.tools.charsetmapping.Utils.*; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
35 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
36 |
public class SBCS { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
37 |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
7668
diff
changeset
|
38 |
static Pattern sbmap = Pattern.compile("0x(\\p{XDigit}++)\\s++(?:U\\+|0x)?(\\p{XDigit}++)(?:\\s++#.*)?"); |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
39 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
40 |
public static void genClass(Charset cs, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
41 |
String srcDir, String dstDir, String template) |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
42 |
throws Exception |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
43 |
{ |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
44 |
String clzName = cs.clzName; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
45 |
String csName = cs.csName; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
46 |
String hisName = cs.hisName; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
47 |
String pkgName = cs.pkgName; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
48 |
boolean isASCII = cs.isASCII; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
49 |
|
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
50 |
StringBuilder b2cSB = new StringBuilder(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
51 |
StringBuilder b2cNRSB = new StringBuilder(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
52 |
StringBuilder c2bNRSB = new StringBuilder(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
53 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
54 |
char[] sb = new char[0x100]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
55 |
char[] c2bIndex = new char[0x100]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
56 |
int c2bOff = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
57 |
Arrays.fill(sb, UNMAPPABLE_DECODING); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
58 |
Arrays.fill(c2bIndex, UNMAPPABLE_DECODING); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
59 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
60 |
// (1)read in .map to parse all b->c entries |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
61 |
FileInputStream in = new FileInputStream( |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
62 |
new File(srcDir, clzName + ".map")); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
63 |
Parser p = new Parser(in, sbmap); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
64 |
Entry e = null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
65 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
66 |
while ((e = p.next()) != null) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
67 |
sb[e.bs] = (char)e.cp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
68 |
if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
69 |
c2bOff += 0x100; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
70 |
c2bIndex[e.cp>>8] = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
71 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
72 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
73 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
74 |
Formatter fm = new Formatter(b2cSB); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
75 |
fm.format("%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
76 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
77 |
// vm -server shows cc[byte + 128] access is much faster than |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
78 |
// cc[byte&0xff] so we output the upper segment first |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
79 |
toString(sb, 0x80, 0x100, fm, "+", true); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
80 |
toString(sb, 0x00, 0x80, fm, ";", true); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
81 |
fm.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
82 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
83 |
// (2)now the .nr file which includes "b->c" non-roundtrip entries |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
84 |
File f = new File(srcDir, clzName + ".nr"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
85 |
if (f.exists()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
86 |
in = new FileInputStream(f); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
87 |
fm = new Formatter(b2cNRSB); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
88 |
p = new Parser(in, sbmap); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
89 |
e = null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
90 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
91 |
fm.format("// remove non-roundtrip entries%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
92 |
fm.format(" b2cMap = b2cTable.toCharArray();%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
93 |
while ((e = p.next()) != null) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
94 |
fm.format(" b2cMap[%d] = UNMAPPABLE_DECODING;%n", |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
95 |
(e.bs>=0x80)?(e.bs-0x80):(e.bs+0x80)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
96 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
97 |
fm.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
98 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
99 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
100 |
// (3)finally the .c2b file which includes c->b non-roundtrip entries |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
101 |
f = new File(srcDir, clzName + ".c2b"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
102 |
if (f.exists()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
103 |
in = new FileInputStream(f); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
104 |
fm = new Formatter(c2bNRSB); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
105 |
p = new Parser(in, sbmap); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
106 |
e = null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
107 |
ArrayList<Entry> es = new ArrayList<Entry>(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
108 |
while ((e = p.next()) != null) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
109 |
if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
110 |
c2bOff += 0x100; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
111 |
c2bIndex[e.cp>>8] = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
112 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
113 |
es.add(e); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
114 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
115 |
fm.format("// non-roundtrip c2b only entries%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
116 |
if (es.size() < 100) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
117 |
fm.format(" c2bNR = new char[%d];%n", es.size() * 2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
118 |
int i = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
119 |
for (Entry entry: es) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
120 |
fm.format(" c2bNR[%d] = 0x%x; c2bNR[%d] = 0x%x;%n", |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
121 |
i++, entry.bs, i++, entry.cp); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
122 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
123 |
} else { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
124 |
char[] cc = new char[es.size() * 2]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
125 |
int i = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
126 |
for (Entry entry: es) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
127 |
cc[i++] = (char)entry.bs; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
128 |
cc[i++] = (char)entry.cp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
129 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
130 |
fm.format(" c2bNR = (%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
131 |
toString(cc, 0, i, fm, ").toCharArray();", false); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
132 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
133 |
fm.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
134 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
135 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
136 |
// (4)it's time to generate the source file |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
137 |
String b2c = b2cSB.toString(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
138 |
String b2cNR = b2cNRSB.toString(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
139 |
String c2bNR = c2bNRSB.toString(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
140 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
141 |
Scanner s = new Scanner(new File(srcDir, template)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
142 |
PrintStream out = new PrintStream(new FileOutputStream( |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
143 |
new File(dstDir, clzName + ".java"))); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
144 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
145 |
while (s.hasNextLine()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
146 |
String line = s.nextLine(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
147 |
int i = line.indexOf("$"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
148 |
if (i == -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
149 |
out.println(line); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
150 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
151 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
152 |
if (line.indexOf("$PACKAGE$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
153 |
line = line.replace("$PACKAGE$", pkgName); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
154 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
155 |
if (line.indexOf("$NAME_CLZ$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
156 |
line = line.replace("$NAME_CLZ$", clzName); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
157 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
158 |
if (line.indexOf("$NAME_CS$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
159 |
line = line.replace("$NAME_CS$", csName); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
160 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
161 |
if (line.indexOf("$NAME_ALIASES$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
162 |
if ("sun.nio.cs".equals(pkgName)) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
163 |
line = line.replace("$NAME_ALIASES$", |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
164 |
"StandardCharsets.aliases_" + clzName); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
165 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
166 |
line = line.replace("$NAME_ALIASES$", |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
167 |
"ExtendedCharsets.aliasesFor(\"" + csName + "\")"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
168 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
169 |
if (line.indexOf("$NAME_HIS$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
170 |
line = line.replace("$NAME_HIS$", hisName); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
171 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
172 |
if (line.indexOf("$CONTAINS$", i) != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
173 |
if (isASCII) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
174 |
line = " return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof " + clzName + "));"; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
175 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
176 |
line = " return (cs instanceof " + clzName + ");"; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
177 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
178 |
if (line.indexOf("$B2CTABLE$") != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
179 |
line = line.replace("$B2CTABLE$", b2c); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
180 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
181 |
if (line.indexOf("$C2BLENGTH$") != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
182 |
line = line.replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
183 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
184 |
if (line.indexOf("$NONROUNDTRIP_B2C$") != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
185 |
if (b2cNR.length() == 0) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
186 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
187 |
line = line.replace("$NONROUNDTRIP_B2C$", b2cNR); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
188 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
189 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
190 |
if (line.indexOf("$NONROUNDTRIP_C2B$") != -1) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
191 |
if (c2bNR.length() == 0) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
192 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
193 |
line = line.replace("$NONROUNDTRIP_C2B$", c2bNR); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
194 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
195 |
out.println(line); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
196 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
197 |
out.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
198 |
} |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
199 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
200 |
private static void toString(char[] sb, int off, int end, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
201 |
Formatter out, String closure, boolean comment) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
202 |
{ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
203 |
while (off < end) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
204 |
out.format(" \""); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
205 |
for (int j = 0; j < 8; j++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
206 |
if (off == end) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
207 |
break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
208 |
char c = sb[off++]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
209 |
switch (c) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
210 |
case '\b': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
211 |
out.format("\\b"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
212 |
case '\t': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
213 |
out.format("\\t"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
214 |
case '\n': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
215 |
out.format("\\n"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
216 |
case '\f': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
217 |
out.format("\\f"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
218 |
case '\r': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
219 |
out.format("\\r"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
220 |
case '\"': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
221 |
out.format("\\\""); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
222 |
case '\'': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
223 |
out.format("\\'"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
224 |
case '\\': |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
225 |
out.format("\\\\"); break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
226 |
default: |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
227 |
out.format("\\u%04X", c & 0xffff); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
228 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
229 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
230 |
if (comment) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
231 |
if (off == end) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
232 |
out.format("\" %s // 0x%02x - 0x%02x%n", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
233 |
closure, off-8, off-1); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
234 |
else |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
235 |
out.format("\" + // 0x%02x - 0x%02x%n", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
236 |
off-8, off-1); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
237 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
238 |
if (off == end) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
239 |
out.format("\"%s%n", closure); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
240 |
else |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
241 |
out.format("\" +%n"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
242 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
243 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
23010
diff
changeset
|
244 |
} |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
245 |
} |