mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-11897 Changing kPatternSeparatorSymbol to be a constant ";" and not loaded from data.
X-SVN-Rev: 41380
This commit is contained in:
parent
d1507a5a2a
commit
955e0d9319
6 changed files with 72 additions and 32 deletions
|
@ -66,7 +66,7 @@ static const UChar INTL_CURRENCY_SYMBOL_STR[] = {0xa4, 0xa4, 0};
|
|||
static const char *gNumberElementKeys[DecimalFormatSymbols::kFormatSymbolCount] = {
|
||||
"decimal",
|
||||
"group",
|
||||
"list",
|
||||
NULL, /* #11897: the <list> symbol is NOT the pattern separator symbol */
|
||||
"percentSign",
|
||||
NULL, /* Native zero digit is deprecated from CLDR - get it from the numbering system */
|
||||
NULL, /* Pattern digit character is deprecated from CLDR - use # by default always */
|
||||
|
|
|
@ -9285,14 +9285,31 @@ void NumberFormatTest::TestParseNaN() {
|
|||
void NumberFormatTest::Test11897_LocalizedPatternSeparator() {
|
||||
IcuTestErrorCode status(*this, "Test11897_LocalizedPatternSeparator");
|
||||
|
||||
DecimalFormatSymbols dfs("en", status);
|
||||
dfs.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, u"!", FALSE);
|
||||
DecimalFormat df(u"0", dfs, status);
|
||||
df.applyPattern("a0;b0", status); // should not throw
|
||||
UnicodeString result;
|
||||
assertEquals("should apply the normal pattern", df.getNegativePrefix(result.remove()), "b");
|
||||
df.applyLocalizedPattern(u"c0!d0", status); // should not throw
|
||||
assertEquals("should apply the localized pattern", df.getNegativePrefix(result.remove()), "d");
|
||||
// In a locale with a different <list> symbol, like arabic,
|
||||
// kPatternSeparatorSymbol should still be ';'
|
||||
{
|
||||
DecimalFormatSymbols dfs("ar", status);
|
||||
assertEquals("pattern separator symbol should be ;",
|
||||
u";",
|
||||
dfs.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol));
|
||||
}
|
||||
|
||||
// However, the custom symbol should be used in localized notation
|
||||
// when set manually via API
|
||||
{
|
||||
DecimalFormatSymbols dfs("en", status);
|
||||
dfs.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, u"!", FALSE);
|
||||
DecimalFormat df(u"0", dfs, status);
|
||||
df.applyPattern("a0;b0", status); // should not throw
|
||||
UnicodeString result;
|
||||
assertEquals("should apply the normal pattern",
|
||||
df.getNegativePrefix(result.remove()),
|
||||
"b");
|
||||
df.applyLocalizedPattern(u"c0!d0", status); // should not throw
|
||||
assertEquals("should apply the localized pattern",
|
||||
df.getNegativePrefix(result.remove()),
|
||||
"d");
|
||||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::Test13055_PercentageRounding() {
|
||||
|
|
|
@ -692,7 +692,7 @@ sl #.##0;#.##0− #,##0;#,##0- K
|
|||
// JDK does not have data for "×10^" in this locale
|
||||
en_SE 0,00×10^0;0,00×10^0- 0.00E0;0.00E0- K
|
||||
// JDK does not seem to transform the digits in localized patterns
|
||||
ar_SA #\u066C##\u0660\u066B\u0660\u0660\u061Ba# #,##0.00;a#,##0.00 K
|
||||
ar_SA #\u066C##\u0660\u066B\u0660\u0660;a# #,##0.00;a#,##0.00 K
|
||||
|
||||
test toPattern
|
||||
set locale en
|
||||
|
|
|
@ -1272,7 +1272,6 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
private static final String[] SYMBOL_KEYS = {
|
||||
"decimal",
|
||||
"group",
|
||||
"list",
|
||||
"percentSign",
|
||||
"minusSign",
|
||||
"plusSign",
|
||||
|
@ -1310,7 +1309,6 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
private static final String[] SYMBOL_DEFAULTS = new String[] {
|
||||
String.valueOf(DEF_DECIMAL_SEPARATOR), // decimal
|
||||
String.valueOf(DEF_GROUPING_SEPARATOR), // group
|
||||
";", // list
|
||||
String.valueOf(DEF_PERCENT), // percentSign
|
||||
String.valueOf(DEF_MINUS_SIGN), // minusSign
|
||||
String.valueOf(DEF_PLUS_SIGN), // plusSign
|
||||
|
@ -1381,21 +1379,18 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
// Copy data from the numberElements map into instance fields
|
||||
setDecimalSeparatorString(numberElements[0]);
|
||||
setGroupingSeparatorString(numberElements[1]);
|
||||
|
||||
// See CLDR #9781
|
||||
// assert numberElements[2].length() == 1;
|
||||
patternSeparator = numberElements[2].charAt(0);
|
||||
|
||||
setPercentString(numberElements[3]);
|
||||
setMinusSignString(numberElements[4]);
|
||||
setPlusSignString(numberElements[5]);
|
||||
setExponentSeparator(numberElements[6]);
|
||||
setPerMillString(numberElements[7]);
|
||||
setInfinity(numberElements[8]);
|
||||
setNaN(numberElements[9]);
|
||||
setMonetaryDecimalSeparatorString(numberElements[10]);
|
||||
setMonetaryGroupingSeparatorString(numberElements[11]);
|
||||
setExponentMultiplicationSign(numberElements[12]);
|
||||
// #11897: pattern separator is always ';', not from data
|
||||
patternSeparator = ';';
|
||||
setPercentString(numberElements[2]);
|
||||
setMinusSignString(numberElements[3]);
|
||||
setPlusSignString(numberElements[4]);
|
||||
setExponentSeparator(numberElements[5]);
|
||||
setPerMillString(numberElements[6]);
|
||||
setInfinity(numberElements[7]);
|
||||
setNaN(numberElements[8]);
|
||||
setMonetaryDecimalSeparatorString(numberElements[9]);
|
||||
setMonetaryGroupingSeparatorString(numberElements[10]);
|
||||
setExponentMultiplicationSign(numberElements[11]);
|
||||
|
||||
digit = '#'; // Localized pattern character no longer in CLDR
|
||||
padEscape = '*';
|
||||
|
@ -1488,11 +1483,11 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
|||
|
||||
// If monetary decimal or grouping were not explicitly set, then set them to be the same as
|
||||
// their non-monetary counterparts.
|
||||
if (numberElements[10] == null) {
|
||||
numberElements[10] = numberElements[0];
|
||||
if (numberElements[9] == null) {
|
||||
numberElements[9] = numberElements[0];
|
||||
}
|
||||
if (numberElements[11] == null) {
|
||||
numberElements[11] = numberElements[1];
|
||||
if (numberElements[10] == null) {
|
||||
numberElements[10] = numberElements[1];
|
||||
}
|
||||
|
||||
return new CacheData(validLocale, digits, numberElements);
|
||||
|
|
|
@ -683,7 +683,7 @@ sl #.##0;#.##0− #,##0;#,##0- K
|
|||
// JDK does not have data for "×10^" in this locale
|
||||
en_SE 0,00×10^0;0,00×10^0- 0.00E0;0.00E0- K
|
||||
// JDK does not seem to transform the digits in localized patterns
|
||||
ar_SA #\u066C##\u0660\u066B\u0660\u0660\u061Ba# #,##0.00;a#,##0.00 K
|
||||
ar_SA #\u066C##\u0660\u066B\u0660\u0660;a# #,##0.00;a#,##0.00 K
|
||||
|
||||
test toPattern
|
||||
set locale en
|
||||
|
|
|
@ -5243,6 +5243,34 @@ public class NumberFormatTest extends TestFmwk {
|
|||
assertNotEquals("df2 != df1", df2, df1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test11897_LocalizedPatternSeparator() {
|
||||
// In a locale with a different <list> symbol, like arabic,
|
||||
// kPatternSeparatorSymbol should still be ';'
|
||||
{
|
||||
DecimalFormatSymbols dfs = new DecimalFormatSymbols(new ULocale("ar"));
|
||||
assertEquals("pattern separator symbol should be ;",
|
||||
';',
|
||||
dfs.getPatternSeparator());
|
||||
}
|
||||
|
||||
// However, the custom symbol should be used in localized notation
|
||||
// when set manually via API
|
||||
{
|
||||
DecimalFormatSymbols dfs = new DecimalFormatSymbols(new ULocale("en"));
|
||||
dfs.setPatternSeparator('!');
|
||||
DecimalFormat df = new DecimalFormat("0", dfs);
|
||||
df.applyPattern("a0;b0"); // should not throw
|
||||
assertEquals("should apply the normal pattern",
|
||||
df.getNegativePrefix(),
|
||||
"b");
|
||||
df.applyLocalizedPattern("c0!d0"); // should not throw
|
||||
assertEquals("should apply the localized pattern",
|
||||
df.getNegativePrefix(),
|
||||
"d");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test13055() {
|
||||
DecimalFormat df = (DecimalFormat) NumberFormat.getPercentInstance();
|
||||
|
|
Loading…
Add table
Reference in a new issue