Skip to content

Commit

Permalink
ICU-22901 Move calls to uloc_getDefault() out of ulocimp_getSubtags().
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Nov 22, 2024
1 parent cd9fada commit 1dccc10
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions icu4c/source/common/locdispnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ _getDisplayNameForComponent(const char *locale,
return 0;
}

if (locale == nullptr) {
locale = uloc_getDefault();
}

localStatus = U_ZERO_ERROR;
icu::CharString localeBuffer = (*getter)(locale, localStatus);
if (U_FAILURE(localStatus)) {
Expand Down
6 changes: 4 additions & 2 deletions icu4c/source/common/loclikely.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ uloc_isRightToLeft(const char *locale) {
UErrorCode errorCode = U_ZERO_ERROR;
icu::CharString lang;
icu::CharString script;
ulocimp_getSubtags(locale, &lang, &script, nullptr, nullptr, nullptr, errorCode);
ulocimp_getSubtags(
locale == nullptr ? uloc_getDefault() : locale,
&lang, &script, nullptr, nullptr, nullptr, errorCode);
if (U_FAILURE(errorCode) || script.isEmpty()) {
// Fastpath: We know the likely scripts and their writing direction
// for some common languages.
Expand Down Expand Up @@ -430,7 +432,7 @@ ulocimp_getRegionForSupplementalData(const char *localeID, bool inferRegion,
icu::CharString rgBuf = GetRegionFromKey(localeID, "rg", status);
if (U_SUCCESS(status) && rgBuf.isEmpty()) {
// No valid rg keyword value, try for unicode_region_subtag
rgBuf = ulocimp_getRegion(localeID, status);
rgBuf = ulocimp_getRegion(localeID == nullptr ? uloc_getDefault() : localeID, status);
if (U_SUCCESS(status) && rgBuf.isEmpty() && inferRegion) {
// Second check for sd keyword value
rgBuf = GetRegionFromKey(localeID, "sd", status);
Expand Down
20 changes: 16 additions & 4 deletions icu4c/source/common/uloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,10 +1541,6 @@ ulocimp_getSubtags(

bool hasRegion = false;

if (localeID == nullptr) {
localeID = uloc_getDefault();
}

_getLanguage(localeID, language, &localeID, status);
if (U_FAILURE(status)) { return; }
U_ASSERT(localeID != nullptr);
Expand Down Expand Up @@ -1989,6 +1985,10 @@ uloc_getLanguage(const char* localeID,
int32_t languageCapacity,
UErrorCode* err)
{
if (localeID == nullptr) {
localeID = uloc_getDefault();
}

/* uloc_getLanguage will return a 2 character iso-639 code if one exists. *CWB*/
return ByteSinkUtil::viaByteSinkToTerminatedChars(
language, languageCapacity,
Expand All @@ -2011,6 +2011,10 @@ uloc_getScript(const char* localeID,
int32_t scriptCapacity,
UErrorCode* err)
{
if (localeID == nullptr) {
localeID = uloc_getDefault();
}

return ByteSinkUtil::viaByteSinkToTerminatedChars(
script, scriptCapacity,
[&](ByteSink& sink, UErrorCode& status) {
Expand All @@ -2032,6 +2036,10 @@ uloc_getCountry(const char* localeID,
int32_t countryCapacity,
UErrorCode* err)
{
if (localeID == nullptr) {
localeID = uloc_getDefault();
}

return ByteSinkUtil::viaByteSinkToTerminatedChars(
country, countryCapacity,
[&](ByteSink& sink, UErrorCode& status) {
Expand All @@ -2053,6 +2061,10 @@ uloc_getVariant(const char* localeID,
int32_t variantCapacity,
UErrorCode* err)
{
if (localeID == nullptr) {
localeID = uloc_getDefault();
}

return ByteSinkUtil::viaByteSinkToTerminatedChars(
variant, variantCapacity,
[&](ByteSink& sink, UErrorCode& status) {
Expand Down
3 changes: 3 additions & 0 deletions icu4c/source/common/uscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ getCodesFromLocale(const char *locale,
if (U_FAILURE(*err)) { return 0; }
icu::CharString lang;
icu::CharString script;
if (locale == nullptr) {
locale = uloc_getDefault();
}
ulocimp_getSubtags(locale, &lang, &script, nullptr, nullptr, nullptr, *err);
if (U_FAILURE(*err)) { return 0; }
// Multi-script languages, equivalent to the LocaleScript data
Expand Down

0 comments on commit 1dccc10

Please sign in to comment.