Skip to content

Commit

Permalink
ICU-22545 Fix addLikelySubtags for pseudo Locales
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Oct 31, 2023
1 parent 1bb711a commit fa6a466
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions icu4c/source/common/loclikelysubtags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,21 @@ LSR XLikelySubtags::makeMaximizedLsr(const char *language, const char *script, c
if (region[0] == 'X' && (c1 = region[1]) != 0 && region[2] == 0) {
switch (c1) {
case 'A':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_ACCENTS_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'B':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_BIDI_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'C':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_CRACKED_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
default: // normal locale
Expand Down
12 changes: 12 additions & 0 deletions icu4c/source/test/cintltst/cloctst.c
Original file line number Diff line number Diff line change
Expand Up @@ -3814,6 +3814,18 @@ const char* const basic_maximize_data[][2] = {
// ICU-22546
"zh_Hani",
"zh_Hani_CN" // If change, please also update common/unicode/uloc.h
}, {
// ICU-22545
"en_XA",
"en_XA"
}, {
// ICU-22545
"en_XB",
"en_XB"
}, {
// ICU-22545
"en_XC",
"en_XC"
}
};

Expand Down
15 changes: 15 additions & 0 deletions icu4c/source/test/intltest/loctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3881,6 +3881,21 @@ LocaleTest::TestAddLikelyAndMinimizeSubtags() {
"zh_Hani",
"zh_Hani_CN", // If change, please also update common/unicode/locid.h
"zh_Hani"
}, {
// ICU-22545
"en_XA",
"en_XA",
"en_XA",
}, {
// ICU-22545
"en_XB",
"en_XB",
"en_XB",
}, {
// ICU-22545
"en_XC",
"en_XC",
"en_XC",
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,18 @@ public void TestAddLikelySubtags() {
// ICU-22546
"zh_Hani",
"zh_Hani_CN" // If change, please also update ULocale.java
}, {
// ICU-22545
"en_XA",
"en_XA",
}, {
// ICU-22545
"en_XB",
"en_XB",
}, {
// ICU-22545
"en_XC",
"en_XC",
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,21 @@ private LSR makeMaximizedLsr(String language, String script, String region, Stri
if (region.length() == 2 && region.charAt(0) == 'X') {
switch (region.charAt(1)) {
case 'A':
if (returnInputIfUnmatch) {
return new LSR(language, script, region, LSR.EXPLICIT_LSR);
}
return new LSR(PSEUDO_ACCENTS_PREFIX + language,
PSEUDO_ACCENTS_PREFIX + script, region, LSR.EXPLICIT_LSR);
case 'B':
if (returnInputIfUnmatch) {
return new LSR(language, script, region, LSR.EXPLICIT_LSR);
}
return new LSR(PSEUDO_BIDI_PREFIX + language,
PSEUDO_BIDI_PREFIX + script, region, LSR.EXPLICIT_LSR);
case 'C':
if (returnInputIfUnmatch) {
return new LSR(language, script, region, LSR.EXPLICIT_LSR);
}
return new LSR(PSEUDO_CRACKED_PREFIX + language,
PSEUDO_CRACKED_PREFIX + script, region, LSR.EXPLICIT_LSR);
default: // normal locale
Expand Down

1 comment on commit fa6a466

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: fa6a466 Previous: 1bb711a Ratio
TestCharsetEncoderICU 0.9187016409434855 ns/iter 0.4337651675220494 ns/iter 2.12

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.