/** If true, do not accept grouping separators at all */
private final boolean groupingDisabled;
+ /** If true, do not accept fraction grouping separators */
+ private final boolean fractionGroupingDisabled;
+
/** If true, do not accept numbers in the fraction */
private final boolean integerOnly;
requireGroupingMatch = 0 != (parseFlags & ParsingUtils.PARSE_FLAG_STRICT_GROUPING_SIZE);
groupingDisabled = 0 != (parseFlags & ParsingUtils.PARSE_FLAG_GROUPING_DISABLED);
+ fractionGroupingDisabled = 0 != (parseFlags
+ & ParsingUtils.PARSE_FLAG_FRACTION_GROUPING_DISABLED);
integerOnly = 0 != (parseFlags & ParsingUtils.PARSE_FLAG_INTEGER_ONLY);
isScientific = 0 != (parseFlags & ParsingUtils.PARSE_FLAG_DECIMAL_SCIENTIFIC);
grouping1 = grouper.getPrimary();
}
}
+ if (fractionGroupingDisabled && seenDecimal) {
+ // Stop parsing here.
+ break;
+ }
+
seenGrouping = true;
if (!groupingStringMatch) {
actualGroupingString = UCharacter.toString(cp);
boolean isStrict = properties.getParseMode() == ParseMode.STRICT;
Grouper grouper = Grouper.defaults().withProperties(properties);
int parseFlags = 0;
+ // Fraction grouping is disabled by default because it has never been supported in DecimalFormat
+ parseFlags |= ParsingUtils.PARSE_FLAG_FRACTION_GROUPING_DISABLED;
if (!properties.getParseCaseSensitive()) {
parseFlags |= ParsingUtils.PARSE_FLAG_IGNORE_CASE;
}
public static final int PARSE_FLAG_USE_FULL_AFFIXES = 0x0100;
public static final int PARSE_FLAG_EXACT_AFFIX = 0x0200;
public static final int PARSE_FLAG_PLUS_SIGN_ALLOWED = 0x0400;
+ public static final int PARSE_FLAG_FRACTION_GROUPING_DISABLED = 0x0800;
public static void putLeadCodePoints(UnicodeSet input, UnicodeSet output) {
for (EntryRange range : input.ranges()) {
+3.52EE4 3.52
+1,234,567.8901 1234567.8901
+1,23,4567.8901 1234567.8901
-// P supports grouping separators in the fraction; none of the others do.
-+1,23,4567.89,01 1234567.8901 CJK
+// Fraction grouping is disabled by default
++1,23,4567.89,01 1234567.89
+1,23,456.78.9 123456.78
-+12.34,56 12.3456 CJK
++12.34,56 12.34
+79,,20,3 79203
+79 20 3 79203 K
// Parsing stops at comma as it is different from other separators
// Minimum grouping is not satisfied below, but that's ok
// because minimum grouping is optional.
+1,234.5 1234.5
-// Comma after decimal means a fractional grouping separator
-// P fails since it finds an invalid grouping size
-+1,23,456.78,9 123456.789 JKP
+// Comma after decimal means parse to a comma
++1,23,456.78,9 123456.78
// C and J fail upon seeing the second decimal point
+1,23,456.78.9 123456.78 CJ
+79 79
parse output breaks
123.456 123456
123,456 123.456
-// The separator after the comma can be inrepreted as a fractional grouping
-987,654.321 987.654321 CJK
-987,654 321 987.654321 CJK
+987,654.321 987.654
+987,654 321 987.654
987.654,321 987654.321
test select
test parse ignorables
set locale ar
// Note: Prefixes contain RLMs, as do some of the test cases.
-// P does not work on most of these right now.
set pattern x ab0c df
set negativePrefix y gh
set negativeSuffix i jk
"0,", // single zero before comma (not group separator) is not leading
"0.0", // single zero before decimal followed by digit is not leading
"0. ", // same as above before period (or decimal) is not leading
- "0.100,,5", // two commas stop parse of decimal
+ "0.100,5", // comma stops parse of decimal (no grouping)
+ "0.100,,5", // two commas also stops parse
".00", // leading decimal is ok, even with zeros
"1234567", // group separators are not required
"12345, ", // comma not followed by digit is not a group separator, but end of number
try {
Number n = nf.parse(defaultNonLong[i]);
if (n instanceof Long) {
- errln("FAIL: parse returned a Long or a BigDecimal");
+ errln("FAIL: parse returned a Long");
}
} catch (ParseException e) {
errln("parse of '" + defaultNonLong[i] + "' threw exception: " + e);
DecimalFormatSymbols(java.util.Locale.US));
String text = "1.222,111";
Number num = df.parse(text,new ParsePosition(0));
- if (!num.toString().equals("1.222111"))
+ if (!num.toString().equals("1.222"))
errln("\"" + text + "\" is parsed as " + num);
text = "1.222x111";
num = df.parse(text,new ParsePosition(0));