45 import java.nio.charset.UnsupportedCharsetException; |
45 import java.nio.charset.UnsupportedCharsetException; |
46 import java.text.DateFormatSymbols; |
46 import java.text.DateFormatSymbols; |
47 import java.text.DecimalFormat; |
47 import java.text.DecimalFormat; |
48 import java.text.DecimalFormatSymbols; |
48 import java.text.DecimalFormatSymbols; |
49 import java.text.NumberFormat; |
49 import java.text.NumberFormat; |
|
50 import java.text.spi.NumberFormatProvider; |
50 import java.util.regex.Matcher; |
51 import java.util.regex.Matcher; |
51 import java.util.regex.Pattern; |
52 import java.util.regex.Pattern; |
52 import java.util.Objects; |
53 import java.util.Objects; |
53 |
54 |
54 import java.time.DateTimeException; |
55 import java.time.DateTimeException; |
60 import java.time.temporal.TemporalQueries; |
61 import java.time.temporal.TemporalQueries; |
61 import java.time.temporal.UnsupportedTemporalTypeException; |
62 import java.time.temporal.UnsupportedTemporalTypeException; |
62 |
63 |
63 import jdk.internal.math.DoubleConsts; |
64 import jdk.internal.math.DoubleConsts; |
64 import jdk.internal.math.FormattedFloatingDecimal; |
65 import jdk.internal.math.FormattedFloatingDecimal; |
|
66 import sun.util.locale.provider.LocaleProviderAdapter; |
|
67 import sun.util.locale.provider.ResourceBundleBasedAdapter; |
65 |
68 |
66 /** |
69 /** |
67 * An interpreter for printf-style format strings. This class provides support |
70 * An interpreter for printf-style format strings. This class provides support |
68 * for layout justification and alignment, common formats for numeric, string, |
71 * for layout justification and alignment, common formats for numeric, string, |
69 * and date/time data, and locale-specific output. Common Java types such as |
72 * and date/time data, and locale-specific output. Common Java types such as |
4474 grpSep = ','; |
4477 grpSep = ','; |
4475 grpSize = 3; |
4478 grpSize = 3; |
4476 } else { |
4479 } else { |
4477 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l); |
4480 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l); |
4478 grpSep = dfs.getGroupingSeparator(); |
4481 grpSep = dfs.getGroupingSeparator(); |
4479 DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l); |
4482 DecimalFormat df = null; |
|
4483 NumberFormat nf = NumberFormat.getNumberInstance(l); |
|
4484 if (nf instanceof DecimalFormat) { |
|
4485 df = (DecimalFormat) nf; |
|
4486 } else { |
|
4487 |
|
4488 // Use DecimalFormat constructor to obtain the instance, |
|
4489 // in case NumberFormat.getNumberInstance(l) |
|
4490 // returns instance other than DecimalFormat |
|
4491 LocaleProviderAdapter adapter = LocaleProviderAdapter |
|
4492 .getAdapter(NumberFormatProvider.class, l); |
|
4493 if (!(adapter instanceof ResourceBundleBasedAdapter)) { |
|
4494 adapter = LocaleProviderAdapter.getResourceBundleBased(); |
|
4495 } |
|
4496 String[] all = adapter.getLocaleResources(l) |
|
4497 .getNumberPatterns(); |
|
4498 df = new DecimalFormat(all[0], dfs); |
|
4499 } |
4480 grpSize = df.getGroupingSize(); |
4500 grpSize = df.getGroupingSize(); |
|
4501 // Some locales do not use grouping (the number |
|
4502 // pattern for these locales does not contain group, e.g. |
|
4503 // ("#0.###")), but specify a grouping separator. |
|
4504 // To avoid unnecessary identification of the position of |
|
4505 // grouping separator, reset its value with null character |
|
4506 if (!df.isGroupingUsed() || grpSize == 0) { |
|
4507 grpSep = '\0'; |
|
4508 } |
4481 } |
4509 } |
4482 } |
4510 } |
4483 |
4511 |
4484 // localize the digits inserting group separators as necessary |
4512 // localize the digits inserting group separators as necessary |
4485 for (int j = offset; j < len; j++) { |
4513 for (int j = offset; j < len; j++) { |