<i18n dev> RFR: 8041488: Locale-Dependent List Patterns [v7]
Joe Wang
joehw at openjdk.org
Thu Aug 10 00:03:58 UTC 2023
On Wed, 9 Aug 2023 00:46:58 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> Introducing a new formatting class for locale-dependent list patterns. The class is to provide the functionality from the Unicode Consortium's LDML specification for [list patterns](https://www.unicode.org/reports/tr35/tr35-general.html#ListPatterns). For example, given a list of String as "Monday", "Wednesday", "Friday", its `format` method would produce "Monday, Wednesday, and Friday" in US English. A CSR has also been drafted, and its draft javadoc can be viewed here: https://cr.openjdk.org/~naoto/JDK-8041488-ListPatterns-PR/api.00/java.base/java/text/ListFormat.html
>
> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>
> Small cleanup
src/java.base/share/classes/java/text/ListFormat.java line 58:
> 56: * .format(List.of("Foo", "Bar", "Baz"))
> 57: * }
> 58: * This will produce the concatenated list string, "Foo, Bar, and Baz" as seen in
With this sample code, if the Style is changed to SHORT, it would produce the same string. Would it be better to use the weekdays instead of Foo, Bar and Baz (as in the Unicode spec)? Esp. with the UNIT type, those examples explained it better, e.g. NARROW produces 3′ 7″.
Also, if the instance is of STANDARD/SHORT, does it format List.of("January", "February", "March") and return "Jan., Feb., and Mar.", or 3 feet, 7 inches to 3 ft, 7 in? The format method states simply "Returns the string that consists of the input strings, concatenated with the patterns of this ListFormat." I wonder if it'd be helpful to explain a bit more or add one more sample.
src/java.base/share/classes/java/text/ListFormat.java line 71:
> 69: * <tr><th scope="row" style="text-align:left">STANDARD</th>
> 70: * <td>Foo, Bar, and Baz</td>
> 71: * <td>Foo, Bar, & Baz</td>
Is "&" a typo? It's still "and" in the Unicode spec's "standard-short" format, e.g. "Jan., Feb., and Mar."
src/java.base/share/classes/java/text/ListFormat.java line 408:
> 406: var em = endPattern.matcher(source);
> 407: Object parsed = null;
> 408: if (sm.find(parsePos.index) && em.find(parsePos.index)) {
Would it be better to call getIndex() instead? (same below)
test/jdk/java/text/Format/ListFormat/TestListFormat.java line 157:
> 155: "foo, bar, baz", true),
> 156: arguments(Locale.US, ListFormat.Type.OR, ListFormat.Style.NARROW,
> 157: "foo, bar, or baz", true),
Same as in the ListFormat class, the expected results are the same "foo, bar, or baz" when different Styles are specified.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15130#discussion_r1289362909
PR Review Comment: https://git.openjdk.org/jdk/pull/15130#discussion_r1289364452
PR Review Comment: https://git.openjdk.org/jdk/pull/15130#discussion_r1289352495
PR Review Comment: https://git.openjdk.org/jdk/pull/15130#discussion_r1289365866
More information about the i18n-dev
mailing list