RFR: JDK-6285888: ChoiceFormat can support unescaped relational symbols in the Format segment
Naoto Sato
naoto at openjdk.org
Tue Jan 30 22:41:42 UTC 2024
On Tue, 30 Jan 2024 21:19:27 GMT, Justin Lu <jlu at openjdk.org> wrote:
> Please review this PR and [CSR](https://bugs.openjdk.org/browse/JDK-8314822) which allows for the _Format_ segment of a ChoiceFormat pattern to use the ChoiceFormat Relational symbols without the need to escape them using quotes. Previously, using a non escaped Relational symbol within a _Format_ segment would throw an IAE.
>
> Implementation wise, this can be achieved by adding an additional check of `part == 0` to the relational symbol conditional. This is safe to do, as any subsequent relational symbols should only come after a '|' is parsed, which sets part back to 0. This ensures that for the duration of `part = 1` (Format segment), the relational symbols can be used without syntactic meaning.
>
> For example, this change allows behavior such as: `new ChoiceFormat("1#The code is #7281")`. Previously, the workaround would have been new `ChoiceFormat("1#The code is '#'7281")` to achieve the same formatted behavior. Please see the CSR for more detail.
>
> Additionally, this change also includes an unrelated grouping of the ChoiceFormat examples under a single header: **Usage Information**.
src/java.base/share/classes/java/text/ChoiceFormat.java line 185:
> 183: * it must be single quoted. For example,
> 184: * {@code new ChoiceFormat("1# '#'1 ").format(1)} returns {@code " #1 "}.
> 185: * Use two single quotes in a row to produce a literal single quote. For example,
It sounds right to remove this restriction, but if we were to use `|` inside `Format`, shouldn't it still need to be single-quoted?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17640#discussion_r1472064667
More information about the core-libs-dev
mailing list