changeset 1716:b892d2903724

backporting
author bachmann
date Wed, 30 Mar 2011 08:28:55 +0000
parents 039e19436f73
children a33bffac30e3
files make/tools/src/build/tools/charsetmapping/Formatter.java make/tools/src/build/tools/charsetmapping/GenerateDBCS.java
diffstat 2 files changed, 49 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/make/tools/src/build/tools/charsetmapping/Formatter.java	Wed Mar 30 08:11:35 2011 +0000
+++ b/make/tools/src/build/tools/charsetmapping/Formatter.java	Wed Mar 30 08:28:55 2011 +0000
@@ -3859,7 +3859,7 @@
                 // Calendar.AM = 0, Calendar.PM = 1, LocaleElements defines upper
                 String[] ampm = { "AM", "PM" };
                 if (l != null && l != Locale.US) {
-                    DateFormatSymbols dfs = DateFormatSymbols.getInstance(l);
+                    java.text.DateFormatSymbols dfs = new java.text.DateFormatSymbols(l);
                     ampm = dfs.getAmPmStrings();
                 }
                 String s = ampm[t.get(Calendar.AM_PM)];
@@ -3893,9 +3893,9 @@
                 break;
             }
             case DateTime.ZONE:        { // 'Z' (symbol)
-                TimeZone tz = t.getTimeZone();
+                java.util.TimeZone tz = t.getTimeZone();
                 sb.append(tz.getDisplayName((t.get(Calendar.DST_OFFSET) != 0),
-                                           TimeZone.SHORT,
+                                           java.util.TimeZone.SHORT,
                                             (l == null) ? Locale.US : l));
                 break;
             }
@@ -3905,7 +3905,7 @@
             case DateTime.NAME_OF_DAY:          { // 'A'
                 int i = t.get(Calendar.DAY_OF_WEEK);
                 Locale lt = ((l == null) ? Locale.US : l);
-                DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
+                java.text.DateFormatSymbols dfs = new java.text.DateFormatSymbols(lt);
                 if (c == DateTime.NAME_OF_DAY)
                     sb.append(dfs.getWeekdays()[i]);
                 else
@@ -3917,7 +3917,7 @@
             case DateTime.NAME_OF_MONTH:        { // 'B'
                 int i = t.get(Calendar.MONTH);
                 Locale lt = ((l == null) ? Locale.US : l);
-                DateFormatSymbols dfs = DateFormatSymbols.getInstance(lt);
+                java.text.DateFormatSymbols dfs = new java.text.DateFormatSymbols(lt);
                 if (c == DateTime.NAME_OF_MONTH)
                     sb.append(dfs.getMonths()[i]);
                 else
@@ -4032,7 +4032,7 @@
 
         private char getZero(Locale l) {
             if ((l != null) &&  !l.equals(locale())) {
-                DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
+                java.text.DecimalFormatSymbols dfs = new java.text.DecimalFormatSymbols(l);
                 return dfs.getZeroDigit();
             }
             return zero;
@@ -4074,7 +4074,7 @@
                 if (l == null || l.equals(Locale.US)) {
                     decSep  = '.';
                 } else {
-                    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
+	                java.text.DecimalFormatSymbols dfs = new java.text.DecimalFormatSymbols(l);
                     decSep  = dfs.getDecimalSeparator();
                 }
             }
@@ -4084,7 +4084,7 @@
                     grpSep = ',';
                     grpSize = 3;
                 } else {
-                    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
+	                java.text.DecimalFormatSymbols dfs = new java.text.DecimalFormatSymbols(l);
                     grpSep = dfs.getGroupingSeparator();
                     DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
                     grpSize = df.getGroupingSize();
--- a/make/tools/src/build/tools/charsetmapping/GenerateDBCS.java	Wed Mar 30 08:11:35 2011 +0000
+++ b/make/tools/src/build/tools/charsetmapping/GenerateDBCS.java	Wed Mar 30 08:28:55 2011 +0000
@@ -247,37 +247,57 @@
                 out.println(line);
                 continue;
             }
-            line = line.replace("$PACKAGE$" , pkgName)
-                       .replace("$IMPLEMENTS$", (hisName == null)?
-                                "" : "implements HistoricallyNamedCharset")
-                       .replace("$NAME_CLZ$", clzName)
-                       .replace("$NAME_ALIASES$",
+            line = replace(line, "$PACKAGE$" , pkgName);
+            line = replace(line, "$IMPLEMENTS$", (hisName == null)?
+                                "" : "implements HistoricallyNamedCharset");
+            line = replace(line, "$NAME_CLZ$", clzName);
+            line = replace(line, "$NAME_ALIASES$",
                                 "sun.nio.cs".equals(pkgName) ?
                                 "StandardCharsets.aliases_" + clzName :
-                                "ExtendedCharsets.aliasesFor(\"" + csName + "\")")
-                       .replace("$NAME_CS$" , csName)
-                       .replace("$CONTAINS$",
+                                "ExtendedCharsets.aliasesFor(\"" + csName + "\")");
+            line = replace(line, "$NAME_CS$" , csName);
+            line = replace(line, "$CONTAINS$",
                                 "MS932".equals(clzName)?
                                 "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof JIS_X_0201) || (cs instanceof " + clzName + "));":
                                 (isASCII ?
                                  "return ((cs.name().equals(\"US-ASCII\")) || (cs instanceof " + clzName + "));":
-                                 "return (cs instanceof " + clzName + ");"))
-                       .replace("$HISTORICALNAME$",
+                                 "return (cs instanceof " + clzName + ");"));
+            line = replace(line, "$HISTORICALNAME$",
                                 (hisName == null)? "" :
-                                "    public String historicalName() { return \"" + hisName + "\"; }")
-                       .replace("$DECTYPE$", type)
-                       .replace("$ENCTYPE$", type)
-                       .replace("$B1MIN$"   , "0x" + Integer.toString(b1Min, 16))
-                       .replace("$B1MAX$"   , "0x" + Integer.toString(b1Max, 16))
-                       .replace("$B2MIN$"   , "0x" + Integer.toString(b2Min, 16))
-                       .replace("$B2MAX$"   , "0x" + Integer.toString(b2Max, 16))
-                       .replace("$B2C$", b2c)
-                       .replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16))
-                       .replace("$NONROUNDTRIP_B2C$", b2cNR)
-                       .replace("$NONROUNDTRIP_C2B$", c2bNR);
+                                "    public String historicalName() { return \"" + hisName + "\"; }");
+            line = replace(line, "$DECTYPE$", type);
+            line = replace(line, "$ENCTYPE$", type);
+            line = replace(line, "$B1MIN$"   , "0x" + Integer.toString(b1Min, 16));
+            line = replace(line, "$B1MAX$"   , "0x" + Integer.toString(b1Max, 16));
+            line = replace(line, "$B2MIN$"   , "0x" + Integer.toString(b2Min, 16));
+            line = replace(line, "$B2MAX$"   , "0x" + Integer.toString(b2Max, 16));
+            line = replace(line, "$B2C$", b2c);
+            line = replace(line, "$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16));
+            line = replace(line, "$NONROUNDTRIP_B2C$", b2cNR);
+            line = replace(line, "$NONROUNDTRIP_C2B$", c2bNR);
 
             out.println(line);
         }
         out.close();
     }
+    
+    	/**
+     * Replaces each substring of this string that matches the literal target
+     * sequence with the specified literal replacement sequence. The
+     * replacement proceeds from the beginning of the string to the end, for
+     * example, replacing "aa" with "b" in the string "aaa" will result in
+     * "ba" rather than "ab".
+     *
+     * @param  target The sequence of char values to be replaced
+     * @param  replacement The replacement sequence of char values
+     * @return  The resulting string
+     * @throws NullPointerException if <code>target</code> or
+     *         <code>replacement</code> is <code>null</code>.
+     * @since 1.5
+     */
+    public static String replace(String source, CharSequence target, CharSequence replacement) {
+        return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
+            source).replaceAll(Matcher.quoteReplacement(replacement.toString()));
+    }
+
 }