本文整理汇总了C++中Locale::setToBogus方法的典型用法代码示例。如果您正苦于以下问题:C++ Locale::setToBogus方法的具体用法?C++ Locale::setToBogus怎么用?C++ Locale::setToBogus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::setToBogus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Locale
/* static */ Locale
ICUUtils::BCP47CodeToLocale(const nsAString& aBCP47Code)
{
MOZ_ASSERT(!aBCP47Code.IsEmpty(), "Don't pass an empty BCP 47 code");
Locale locale;
locale.setToBogus();
// BCP47 codes are guaranteed to be ASCII, so lossy conversion is okay
NS_LossyConvertUTF16toASCII bcp47code(aBCP47Code);
UErrorCode status = U_ZERO_ERROR;
int32_t needed;
char localeID[256];
needed = uloc_forLanguageTag(bcp47code.get(), localeID,
PR_ARRAY_SIZE(localeID) - 1, nullptr,
&status);
MOZ_ASSERT(needed < int32_t(PR_ARRAY_SIZE(localeID)) - 1,
"Need a bigger buffer");
if (needed <= 0 || U_FAILURE(status)) {
return locale;
}
char lang[64];
needed = uloc_getLanguage(localeID, lang, PR_ARRAY_SIZE(lang) - 1,
&status);
MOZ_ASSERT(needed < int32_t(PR_ARRAY_SIZE(lang)) - 1,
"Need a bigger buffer");
if (needed <= 0 || U_FAILURE(status)) {
return locale;
}
char country[64];
needed = uloc_getCountry(localeID, country, PR_ARRAY_SIZE(country) - 1,
&status);
MOZ_ASSERT(needed < int32_t(PR_ARRAY_SIZE(country)) - 1,
"Need a bigger buffer");
if (needed > 0 && U_SUCCESS(status)) {
locale = Locale(lang, country);
}
if (locale.isBogus()) {
// Using the country resulted in a bogus Locale, so try with only the lang
locale = Locale(lang);
}
return locale;
}