ICU-7128 Added a configuration property com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing to disable extended separator character matching used by DecimalFormat. When the property is true, DecimalFormat uses only decimal/grouping separator characters during parse - this behavior is compatible with JDK.

X-SVN-Rev: 27270
This commit is contained in:
Yoshito Umaoka 2010-01-15 05:19:33 +00:00
parent 335af0d393
commit 727fdddbce
3 changed files with 38 additions and 3 deletions

View file

@ -1,6 +1,6 @@
#*
#*******************************************************************************
#* Copyright (C) 2008, International Business Machines Corporation and *
#* Copyright (C) 2008-2010, International Business Machines Corporation and *
#* others. All Rights Reserved. *
#*******************************************************************************
#* This is the properties contains ICU runtime configuration
@ -11,3 +11,13 @@
# factory method. [ ICU | JDK ]
#
com.ibm.icu.util.TimeZone.DefaultTimeZoneType = ICU
#
# By default, DecimalFormat uses some internal equivalent character
# data in addition to ones in DecimalFormatSymbols for parsing
# decimal/grouping separators. When this property is true,
# DecimalFormat uses separators configured by DecimalFormatSymbols only
# and does not try to find a match in the internal equivalent character
# data.
#
com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing = false

View file

@ -21,6 +21,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.ibm.icu.impl.ICUConfig;
import com.ibm.icu.impl.UCharacterProperty;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.lang.UCharacter;
@ -2148,8 +2149,12 @@ public class DecimalFormat extends NumberFormat {
int leadingZeroCount = 0;
// equivalent grouping and decimal support
UnicodeSet decimalEquiv = getEquivalentDecimals(decimal, strictParse);
UnicodeSet groupEquiv = strictParse ? strictDefaultGroupingSeparators : defaultGroupingSeparators;
boolean skipExtendedSeparatorParsing = ICUConfig.get("com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "false")
.equals("true");
UnicodeSet decimalEquiv = skipExtendedSeparatorParsing ? EMPTY_SET : getEquivalentDecimals(decimal, strictParse);
UnicodeSet groupEquiv = skipExtendedSeparatorParsing ? EMPTY_SET :
(strictParse ? strictDefaultGroupingSeparators : defaultGroupingSeparators);
// We have to track digitCount ourselves, because digits.count will
// pin when the maximum allowable digits is reached.

View file

@ -2587,5 +2587,25 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
expect(fmt, "2\uFF61345.67", 2345.67);
// Ticket#7218
//
// Lenient separator parsing is enabled by default.
// A space character below is interpreted as a
// group separator, even ',' is used as grouping
// separator in the symbols.
sym.setGroupingSeparator(',');
fmt.setDecimalFormatSymbols(sym);
expect(fmt, "12 345", 12345);
// When the property SkipExtendedSeparatorParsing is true,
// DecimalFormat does not use the extended equivalent separator
// data and only uses the one in DecimalFormatSymbols.
System.setProperty("com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "true");
expect(fmt, "23 456", 23);
// Set the configuration back to the default
System.setProperty("com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "false");
}
}