!808 改IsValidLocaleTag()稳定性问题

Merge pull request !808 from zhangdd_ewan/cherry-240828
This commit is contained in:
openharmony_ci 2024-08-28 11:46:48 +00:00 committed by Gitee
commit 74882127a2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -107,7 +107,7 @@ bool IsValidLocaleTag(icu::Locale &locale)
{
static std::unordered_set<std::string> allValidLocalesLanguageTag;
GetAllValidLocalesTag(allValidLocalesLanguageTag);
std::string languageTag = locale.getLanguage();
std::string languageTag = locale.getLanguage() == nullptr ? "" : locale.getLanguage();
if (allValidLocalesLanguageTag.find(languageTag) == allValidLocalesLanguageTag.end()) {
HILOG_ERROR_I18N("GetTimePeriodName does not support this languageTag: %{public}s", languageTag.c_str());
return false;
@ -124,7 +124,10 @@ void GetAllValidLocalesTag(std::unordered_set<std::string>& allValidLocalesLangu
int32_t validCount = 1;
const icu::Locale *validLocales = icu::Locale::getAvailableLocales(validCount);
for (int i = 0; i < validCount; i++) {
allValidLocalesLanguageTag.insert(validLocales[i].getLanguage());
const char* language = validLocales[i].getLanguage();
if (language != nullptr) {
allValidLocalesLanguageTag.insert(language);
}
}
init = true;
}