177 char[] nr = sb.toString().toCharArray();
178 out = new Output(new Formatter(c2bNRSB));
179 out.format("String c2bNR =%n");
180 out.format(nr, 0, nr.length, ";");
181 out.close();
182 } else {
183 c2bNRSB.append("String c2bNR = null;");
184 }
185
186 // (4)it's time to generate the source file
187 String b2c = b2cSB.toString();
188 String b2cNR = b2cNRSB.toString();
189 String c2bNR = c2bNRSB.toString();
190
191 Scanner s = new Scanner(new File(srcDir, template));
192 PrintStream ops = new PrintStream(new FileOutputStream(
193 new File(dstDir, clzName + ".java")));
194 if (hisName == null)
195 hisName = "";
196
197 while (s.hasNextLine()) {
198 String line = s.nextLine();
199 if (line.indexOf("$") == -1) {
200 ops.println(line);
201 continue;
202 }
203 line = line.replace("$PACKAGE$" , pkgName)
204 .replace("$IMPLEMENTS$", (hisName == null)?
205 "" : "implements HistoricallyNamedCharset")
206 .replace("$NAME_CLZ$", clzName)
207 .replace("$NAME_ALIASES$",
208 "sun.nio.cs".equals(pkgName) ?
209 "StandardCharsets.aliases_" + clzName :
210 "ExtendedCharsets.aliasesFor(\"" + csName + "\")")
211 .replace("$NAME_CS$" , csName)
212 .replace("$CONTAINS$",
213 "MS932".equals(clzName)?
214 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof JIS_X_0201) || (cs instanceof " + clzName + "));":
215 (isASCII ?
216 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof " + clzName + "));":
217 "return (cs instanceof " + clzName + ");"))
218 .replace("$HISTORICALNAME$",
219 (hisName == null)? "" :
220 " public String historicalName() { return \"" + hisName + "\"; }")
221 .replace("$DECTYPE$", type)
222 .replace("$ENCTYPE$", type)
223 .replace("$B1MIN$" , "0x" + Integer.toString(b1Min, 16))
224 .replace("$B1MAX$" , "0x" + Integer.toString(b1Max, 16))
225 .replace("$B2MIN$" , "0x" + Integer.toString(b2Min, 16))
226 .replace("$B2MAX$" , "0x" + Integer.toString(b2Max, 16))
227 .replace("$B2C$", b2c)
228 .replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16))
229 .replace("$NONROUNDTRIP_B2C$", b2cNR)
230 .replace("$NONROUNDTRIP_C2B$", c2bNR);
231
232 ops.println(line);
233 }
234 ops.close();
235 }
236 }
|
177 char[] nr = sb.toString().toCharArray();
178 out = new Output(new Formatter(c2bNRSB));
179 out.format("String c2bNR =%n");
180 out.format(nr, 0, nr.length, ";");
181 out.close();
182 } else {
183 c2bNRSB.append("String c2bNR = null;");
184 }
185
186 // (4)it's time to generate the source file
187 String b2c = b2cSB.toString();
188 String b2cNR = b2cNRSB.toString();
189 String c2bNR = c2bNRSB.toString();
190
191 Scanner s = new Scanner(new File(srcDir, template));
192 PrintStream ops = new PrintStream(new FileOutputStream(
193 new File(dstDir, clzName + ".java")));
194 if (hisName == null)
195 hisName = "";
196
197 // (5) c2b replacement, only used for JIs0208/0212, which
198 // are two pure db charsets so default '3f' does not work
199 String c2bRepl = "";
200 if (clzName.startsWith("JIS_X_0208")) {
201 c2bRepl = "new byte[]{ (byte)0x21, (byte)0x29 },";
202 } else if (clzName.startsWith("JIS_X_0212")) {
203 c2bRepl = "new byte[]{ (byte)0x22, (byte)0x44 },";
204 }
205
206 while (s.hasNextLine()) {
207 String line = s.nextLine();
208 if (line.indexOf("$") == -1) {
209 ops.println(line);
210 continue;
211 }
212 line = line.replace("$PACKAGE$" , pkgName)
213 .replace("$IMPLEMENTS$", (hisName == null)?
214 "" : "implements HistoricallyNamedCharset")
215 .replace("$NAME_CLZ$", clzName)
216 .replace("$NAME_ALIASES$",
217 "sun.nio.cs".equals(pkgName) ?
218 "StandardCharsets.aliases_" + clzName :
219 "ExtendedCharsets.aliasesFor(\"" + csName + "\")")
220 .replace("$NAME_CS$" , csName)
221 .replace("$CONTAINS$",
222 "MS932".equals(clzName)?
223 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof JIS_X_0201) || (cs instanceof " + clzName + "));":
224 (isASCII ?
225 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof " + clzName + "));":
226 "return (cs instanceof " + clzName + ");"))
227 .replace("$HISTORICALNAME$",
228 (hisName == null)? "" :
229 " public String historicalName() { return \"" + hisName + "\"; }")
230 .replace("$DECTYPE$", type)
231 .replace("$ENCTYPE$", type)
232 .replace("$B1MIN$" , "0x" + Integer.toString(b1Min, 16))
233 .replace("$B1MAX$" , "0x" + Integer.toString(b1Max, 16))
234 .replace("$B2MIN$" , "0x" + Integer.toString(b2Min, 16))
235 .replace("$B2MAX$" , "0x" + Integer.toString(b2Max, 16))
236 .replace("$B2C$", b2c)
237 .replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16))
238 .replace("$NONROUNDTRIP_B2C$", b2cNR)
239 .replace("$NONROUNDTRIP_C2B$", c2bNR)
240 .replace("$ENC_REPLACEMENT$", c2bRepl);
241
242 ops.println(line);
243 }
244 ops.close();
245 }
246 }
|