On Tue, 2 May 2023 21:42:09 GMT, Justin Lu <[email protected]> wrote:
>> Please review this PR which adds the method `caseFoldLanguageTag(String
>> languageTag)` to java.util.Locale.
>>
>> This method case folds a language tag to adhere to _[section 2.1.1.
>> Formatting of Language Tags of
>> RFC5646](https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1)_. This
>> format is defined as _"All subtags, including extension and private use
>> subtags, use lowercase letters with two exceptions: two-letter and
>> four-letter subtags that neither appear at the start of the tag nor occur
>> after singletons. Such two-letter subtags are all uppercase ... and
>> four-letter subtags are titlecase."_.
>>
>>
>> In order to match the behavior of existing language tag related Locale
>> methods, this method matches the 2.1.1 RFC5646 specification with the
>> following **exceptions**:
>> - Will not case fold variant subtags
>> - Will not case fold private use subtags prefixed by "lvariant"
>>
>> As an example,
>> `caseFoldLanguageTag("ja-kana-jp-x-lvariant-Oracle-JDK-Standard-Edition")`
>> returns _"ja-Kana-JP-x-lvariant-Oracle-JDK-Standard-Edition"_. Further
>> examples can be seen in the test file.
>
> Justin Lu has updated the pull request incrementally with four additional
> commits since the last revision:
>
> - Review comment: Replace wellFormed with parseSts to pass errorMsg to
> exception
> - Review comment: Adjust method names
> - Review comment: Use assertThrows and correct IAE to ILE
> - Review comment: improve legacy_tags id
src/java.base/share/classes/sun/util/locale/LanguageTag.java line 34:
> 32: package sun.util.locale;
> 33:
> 34: import java.util.*;
Wild card imports are discouraged. It may be useful to update your ide settings
to avoid automatic conversions.
src/java.base/share/classes/sun/util/locale/LanguageTag.java line 423:
> 421: }
> 422: // Non-legacy tags
> 423: StringBuilder bldr = new StringBuilder();
Presize the StringBuilder with the current length to avoid a reallocation.
src/java.base/share/classes/sun/util/locale/LanguageTag.java line 429:
> 427: boolean privUseVarFound = false;
> 428: for (int i = 0; i < subtags.length; i++) {
> 429: if (privUseVarFound) {
The following block of code might be easier to read if subtags[i] was put in a
local.
src/java.base/share/classes/sun/util/locale/LanguageTag.java line 446:
> 444: } else if (subtags[i].equals(PRIVUSE_VARIANT_PREFIX)) {
> 445: privUseVarFound = true;
> 446: }
These flags can become true but inside the loop cannot become false again.
Is that correct? For example, I think there can be multiple extension
singletons.
test/jdk/java/util/Locale/CaseFoldLanguageTagTest.java line 75:
> 73:
> 74: private static Stream<Arguments> wellFormedTags() {
> 75: return Stream.of(
There are no test cases with multiple singleton extensions either as valid or
invalid tests.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13679#discussion_r1184028514
PR Review Comment: https://git.openjdk.org/jdk/pull/13679#discussion_r1184130544
PR Review Comment: https://git.openjdk.org/jdk/pull/13679#discussion_r1184133074
PR Review Comment: https://git.openjdk.org/jdk/pull/13679#discussion_r1184143730
PR Review Comment: https://git.openjdk.org/jdk/pull/13679#discussion_r1184159147