mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-23 07:00:13 +00:00
!808 改IsValidLocaleTag()稳定性问题
Merge pull request !808 from zhangdd_ewan/cherry-240828
This commit is contained in:
commit
74882127a2
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user