<i18n dev> Integrated: 8327640: Allow NumberFormat strict parsing
Justin Lu
jlu at openjdk.org
Tue Apr 16 16:21:06 UTC 2024
On Mon, 18 Mar 2024 06:24:54 GMT, Justin Lu <jlu at openjdk.org> wrote:
> Please review this PR and associated [CSR](https://bugs.openjdk.org/browse/JDK-8327703) which introduces strict parsing for NumberFormat.
>
> The concrete subclasses that will utilize this leniency value are `DecimalFormat` and `CompactNumberFormat`. Strict leniency allows for parsing to be used as an input validation technique for localized formatted numbers. The default leniency mode will remain lenient, and can only be set to strict through an intentional `setLenient(boolean)` method call. Leniency operates differently based off the values returned by `isGroupingUsed()`, `getGroupingSize()`, and `isParseIntegerOnly()`.
>
> Below is an example of the change, the CSR can be viewed for further detail.
>
>
> DecimalFormat fmt = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
> fmt.parse("1,,,0,,,00,.23Zabced45"); // returns 1000.23
> fmt.setLenient(false);
> fmt.parse("1,,,0,,,00,.23Zabced45"); // Now throws a ParseException
> fmt.setGroupingSize(2);
> fmt.parse("12,34,567"); // throws ParseException
> fmt.setParseIntegerOnly(true)
> fmt.parse("12,34.56"); // throws ParseException
> fmt.parse("12,34"); // successfully returns the Number 1234
>
>
> The associated tests are all localized, and the data is converted properly during runtime.
This pull request has now been integrated.
Changeset: 941bee19
Author: Justin Lu <jlu at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/941bee197ff679e9b8755cad117f5172e3508ef2
Stats: 1603 lines in 12 files changed: 1499 ins; 33 del; 71 mod
8327640: Allow NumberFormat strict parsing
Reviewed-by: naoto
-------------
PR: https://git.openjdk.org/jdk/pull/18339
More information about the i18n-dev
mailing list