author | pliden |
Thu, 26 Sep 2019 13:56:58 +0200 | |
changeset 58355 | de246fd65587 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
5167
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21805
diff
changeset
|
2 |
* Copyright (c) 2008, 2013, 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.File; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
29 |
import java.io.InputStream; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
30 |
import java.io.InputStreamReader; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
31 |
import java.io.OutputStream; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
32 |
import java.io.BufferedReader; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
33 |
import java.io.IOException; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
34 |
import java.util.regex.Matcher; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
35 |
import java.util.regex.Pattern; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
36 |
import java.util.Scanner; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
37 |
import java.util.Formatter; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
38 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
39 |
public class Utils { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
40 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
41 |
public final static char UNMAPPABLE_DECODING = '\uFFFD'; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
42 |
public final static int UNMAPPABLE_ENCODING = 0xFFFD; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
43 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
44 |
public static class Entry { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
45 |
public int bs; //byte sequence reps |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
46 |
public int cp; //Unicode codepoint |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
47 |
public int cp2; //CC of composite |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
48 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
49 |
public Entry () {} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
50 |
public Entry (int bytes, int cp, int cp2) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
51 |
this.bs = bytes; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
52 |
this.cp = cp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
53 |
this.cp2 = cp2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
54 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
55 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
56 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
57 |
public static class Parser { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
58 |
static final Pattern basic = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:0x)?(\\p{XDigit}++)?\\s*+.*"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
59 |
static final int gBS = 1; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
60 |
static final int gCP = 2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
61 |
static final int gCP2 = 3; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
62 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
63 |
BufferedReader reader; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
64 |
boolean closed; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
65 |
Matcher matcher; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
66 |
int gbs, gcp, gcp2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
67 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
68 |
public Parser (InputStream in, Pattern p, int gbs, int gcp, int gcp2) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
69 |
throws IOException |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
70 |
{ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
71 |
this.reader = new BufferedReader(new InputStreamReader(in)); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
72 |
this.closed = false; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
73 |
this.matcher = p.matcher(""); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
74 |
this.gbs = gbs; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
75 |
this.gcp = gcp; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
76 |
this.gcp2 = gcp2; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
77 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
78 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
79 |
public Parser (InputStream in, Pattern p) throws IOException { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
80 |
this(in, p, gBS, gCP, gCP2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
81 |
} |
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 |
public Parser (InputStream in) throws IOException { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
84 |
this(in, basic, gBS, gCP, gCP2); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
85 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
86 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
87 |
protected boolean isDirective(String line) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
88 |
return line.startsWith("#"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
89 |
} |
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 |
protected Entry parse(Matcher matcher, Entry mapping) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
92 |
mapping.bs = Integer.parseInt(matcher.group(gbs), 16); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
93 |
mapping.cp = Integer.parseInt(matcher.group(gcp), 16); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
94 |
if (gcp2 <= matcher.groupCount() && |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
95 |
matcher.group(gcp2) != null) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
96 |
mapping.cp2 = Integer.parseInt(matcher.group(gcp2), 16); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
97 |
else |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
98 |
mapping.cp2 = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
99 |
return mapping; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
100 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
101 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
102 |
public Entry next() throws Exception { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
103 |
return next(new Entry()); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
104 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
105 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
106 |
// returns null and closes the input stream if the eof has beenreached. |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
107 |
public Entry next(Entry mapping) throws Exception { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
108 |
if (closed) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
109 |
return null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
110 |
String line; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
111 |
while ((line = reader.readLine()) != null) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
112 |
if (isDirective(line)) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
113 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
114 |
matcher.reset(line); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
115 |
if (!matcher.lookingAt()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
116 |
//System.out.println("Missed: " + line); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
117 |
continue; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
118 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
119 |
return parse(matcher, mapping); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
120 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
121 |
reader.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
122 |
closed = true; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
123 |
return null; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
124 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
125 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
126 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
127 |
public static class Output { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
128 |
private Formatter out; |
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 |
public Output(Formatter out) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
131 |
this.out = out; |
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 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
134 |
public void close() { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
135 |
out.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
136 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
137 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
138 |
private void toChar(String fmt, char c) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
139 |
switch (c) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
140 |
case '\b': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
141 |
out.format("\\b"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
142 |
case '\t': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
143 |
out.format("\\t"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
144 |
case '\n': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
145 |
out.format("\\n"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
146 |
case '\f': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
147 |
out.format("\\f"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
148 |
case '\r': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
149 |
out.format("\\r"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
150 |
case '\"': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
151 |
out.format("\\\""); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
152 |
case '\'': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
153 |
out.format("\\'"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
154 |
case '\\': |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
155 |
out.format("\\\\"); break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
156 |
default: |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
157 |
out.format(fmt, c & 0xffff); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
158 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
159 |
} |
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 |
public void format(String fmt, Object ... args) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
162 |
out.format(fmt, args); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
163 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
164 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
165 |
public void format(char[] cc, int off, int end, String closure) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
166 |
while (off < end) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
167 |
out.format(" \""); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
168 |
for (int j = 0; j < 8; j++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
169 |
if (off == end) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
170 |
break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
171 |
toChar("\\u%04X", cc[off++]); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
172 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
173 |
if (off == end) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
174 |
out.format("\" %s%n", closure); |
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 |
out.format("\" + %n"); |
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 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
179 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
180 |
public void format(char[] cc, String closure) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
181 |
format(cc, 0, cc.length, closure); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
182 |
} |
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 |
public void format(char[] db, int b1, int b2Min, int b2Max, |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
185 |
String closure) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
186 |
{ |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
187 |
char[] cc = new char[b2Max - b2Min + 1]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
188 |
int off = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
189 |
for (int b2 = b2Min; b2 <= b2Max; b2++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
190 |
cc[off++] = db[(b1 << 8) | b2]; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
191 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
192 |
format(cc, 0, cc.length, closure); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
193 |
} |
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 |
public void format(char[] date) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
196 |
int off = 0; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
197 |
int end = date.length; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
198 |
while (off < end) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
199 |
out.format(" "); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
200 |
for (int j = 0; j < 8 && off < end; j++) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
201 |
toChar("'\\u%04X',", date[off++]); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
202 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
203 |
out.format("%n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
204 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
205 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
206 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
207 |
|
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
208 |
public static String getCopyright(File f) throws IOException { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
209 |
Scanner s = new Scanner(f, "ISO-8859-1"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
210 |
StringBuilder sb = new StringBuilder(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
211 |
while (s.hasNextLine()) { |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
212 |
String ln = s.nextLine(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
213 |
sb.append(ln + "\n"); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
214 |
// assume we have the copyright as the first comment |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
215 |
if (ln.matches("^\\s\\*\\/$")) |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
216 |
break; |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
217 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
218 |
s.close(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
219 |
return sb.toString(); |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
220 |
} |
dbd299f8fdae
6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff
changeset
|
221 |
} |