diff --git a/icu4c/source/common/loclikely.cpp b/icu4c/source/common/loclikely.cpp index 737899e5b7a..f87fd8dd61c 100644 --- a/icu4c/source/common/loclikely.cpp +++ b/icu4c/source/common/loclikely.cpp @@ -300,6 +300,9 @@ ulocimp_addLikelySubtags(const char* localeID, icu::ByteSink& sink, UErrorCode& status) { if (U_FAILURE(status)) { return; } + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } icu::CharString localeBuffer = ulocimp_canonicalize(localeID, status); _uloc_addLikelySubtags(localeBuffer.data(), sink, status); } @@ -334,6 +337,9 @@ ulocimp_minimizeSubtags(const char* localeID, bool favorScript, UErrorCode& status) { if (U_FAILURE(status)) { return; } + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } icu::CharString localeBuffer = ulocimp_canonicalize(localeID, status); _uloc_minimizeSubtags(localeBuffer.data(), sink, favorScript, status); } diff --git a/icu4c/source/common/locresdata.cpp b/icu4c/source/common/locresdata.cpp index 725e6609159..ba7163fa2db 100644 --- a/icu4c/source/common/locresdata.cpp +++ b/icu4c/source/common/locresdata.cpp @@ -161,6 +161,9 @@ _uloc_getOrientationHelper(const char* localeId, if (U_FAILURE(status)) { return result; } + if (localeId == nullptr) { + localeId = uloc_getDefault(); + } icu::CharString localeBuffer = ulocimp_canonicalize(localeId, status); if (U_FAILURE(status)) { return result; } diff --git a/icu4c/source/common/ucurr.cpp b/icu4c/source/common/ucurr.cpp index db40f492c4c..cccf1130ae8 100644 --- a/icu4c/source/common/ucurr.cpp +++ b/icu4c/source/common/ucurr.cpp @@ -678,6 +678,9 @@ ucurr_getName(const char16_t* currency, // this function. UErrorCode ec2 = U_ZERO_ERROR; + if (locale == nullptr) { + locale = uloc_getDefault(); + } CharString loc = ulocimp_getName(locale, ec2); if (U_FAILURE(ec2)) { *ec = U_ILLEGAL_ARGUMENT_ERROR; @@ -776,6 +779,9 @@ ucurr_getPluralName(const char16_t* currency, // this function. UErrorCode ec2 = U_ZERO_ERROR; + if (locale == nullptr) { + locale = uloc_getDefault(); + } CharString loc = ulocimp_getName(locale, ec2); if (U_FAILURE(ec2)) { *ec = U_ILLEGAL_ARGUMENT_ERROR; @@ -969,6 +975,9 @@ collectCurrencyNames(const char* locale, // Look up the Currencies resource for the given locale. UErrorCode ec2 = U_ZERO_ERROR; + if (locale == nullptr) { + locale = uloc_getDefault(); + } CharString loc = ulocimp_getName(locale, ec2); if (U_FAILURE(ec2)) { ec = U_ILLEGAL_ARGUMENT_ERROR; diff --git a/icu4c/source/common/uloc.cpp b/icu4c/source/common/uloc.cpp index 65a953da2cb..c69b021c94e 100644 --- a/icu4c/source/common/uloc.cpp +++ b/icu4c/source/common/uloc.cpp @@ -1824,9 +1824,6 @@ _canonicalize(const char* localeID, tempBuffer = ulocimp_forLanguageTag(localeIDPtr, -1, nullptr, err); tmpLocaleID = U_SUCCESS(err) && !tempBuffer.isEmpty() ? tempBuffer.data() : localeIDPtr; } else { - if (localeID==nullptr) { - localeID=uloc_getDefault(); - } tmpLocaleID=localeID; } @@ -2126,6 +2123,9 @@ uloc_getName(const char* localeID, int32_t nameCapacity, UErrorCode* err) { + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } return ByteSinkUtil::viaByteSinkToTerminatedChars( name, nameCapacity, [&](ByteSink& sink, UErrorCode& status) { @@ -2159,6 +2159,9 @@ uloc_getBaseName(const char* localeID, int32_t nameCapacity, UErrorCode* err) { + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } return ByteSinkUtil::viaByteSinkToTerminatedChars( name, nameCapacity, [&](ByteSink& sink, UErrorCode& status) { @@ -2192,6 +2195,9 @@ uloc_canonicalize(const char* localeID, int32_t nameCapacity, UErrorCode* err) { + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } return ByteSinkUtil::viaByteSinkToTerminatedChars( name, nameCapacity, [&](ByteSink& sink, UErrorCode& status) { diff --git a/icu4c/source/common/uloc_tag.cpp b/icu4c/source/common/uloc_tag.cpp index 4a5a83a6c54..b2e9946f48a 100644 --- a/icu4c/source/common/uloc_tag.cpp +++ b/icu4c/source/common/uloc_tag.cpp @@ -2596,6 +2596,9 @@ ulocimp_toLanguageTag(const char* localeID, bool hadPosix = false; const char* pKeywordStart; + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } /* Note: uloc_canonicalize returns "en_US_POSIX" for input locale ID "". See #6835 */ icu::CharString canonical = ulocimp_canonicalize(localeID, tmpStatus); if (U_FAILURE(tmpStatus)) { diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp index 812e0dab9a3..afda2770fd3 100644 --- a/icu4c/source/common/uresbund.cpp +++ b/icu4c/source/common/uresbund.cpp @@ -2716,6 +2716,9 @@ ures_openWithType(UResourceBundle *r, const char* path, const char* localeID, UResourceDataEntry *entry; if(openType != URES_OPEN_DIRECT) { + if (localeID == nullptr) { + localeID = uloc_getDefault(); + } /* first "canonicalize" the locale ID */ CharString canonLocaleID = ulocimp_getBaseName(localeID, *status); if(U_FAILURE(*status)) { @@ -3080,6 +3083,9 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, kwVal.clear(); } } + if (locid == nullptr) { + locid = uloc_getDefault(); + } CharString base = ulocimp_getBaseName(locid, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "getFunctionalEquivalent: \"%s\" [%s=%s] in %s - %s\n",