本文整理汇总了C++中Locale::getVariant方法的典型用法代码示例。如果您正苦于以下问题:C++ Locale::getVariant方法的具体用法?C++ Locale::getVariant怎么用?C++ Locale::getVariant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::getVariant方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBundle
ResourceBundlePtr ResourceBundle::getBundle(const String& baseName,
const Locale& locale)
{
String bundleName;
istream * bundleStream;
PropertyResourceBundlePtr resourceBundle, previous;
std::vector<String> bundlesNames;
if (!locale.getVariant().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage() + _T("_") +
locale.getCountry() + _T("_") +
locale.getVariant());
}
if (!locale.getCountry().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage() + _T("_") +
locale.getCountry());
}
if (!locale.getLanguage().empty())
{
bundlesNames.push_back(baseName + _T("_") +
locale.getLanguage());
}
bundlesNames.push_back(baseName);
for (std::vector<String>::iterator it = bundlesNames.begin();
it != bundlesNames.end(); it++)
{
bundleName = *it;
PropertyResourceBundlePtr current;
try
{
const Class& classObj = Loader::loadClass(bundleName);
current = classObj.newInstance();
}
catch(ClassNotFoundException&)
{
current = 0;
}
if (current == 0)
{
bundleStream =
Loader::getResourceAsStream(bundleName + _T(".properties"));
if (bundleStream == 0)
{
continue;
}
}
try
{
current = new PropertyResourceBundle(*bundleStream);
}
catch(Exception&)
{
delete bundleStream;
bundleStream = 0;
throw;
}
delete bundleStream;
bundleStream = 0;
if (resourceBundle == 0)
{
resourceBundle = current;
previous = current;
}
else
{
previous->setParent(current);
previous = current;
}
}
if (resourceBundle == 0)
{
throw MissingResourceException();
}
return resourceBundle;
}
示例2: adjustForUsageAndContext
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
if (locale.isBogus()) {
result.setToBogus();
return result;
}
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp, TRUE));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp, TRUE));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp, TRUE));
}
resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen);
resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen);
LocalPointer<StringEnumeration> e(locale.createKeywords(status));
if (e.isValid() && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
if (U_FAILURE(status)) {
return result;
}
keyDisplayName(key, temp, TRUE);
temp.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp.findAndReplace(formatCloseParen, formatReplaceCloseParen);
keyValueDisplayName(key, value, temp2, TRUE);
temp2.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp2.findAndReplace(formatCloseParen, formatReplaceCloseParen);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
keyTypeFormat.format(temp, temp2, temp3, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
}
//.........这里部分代码省略.........
示例3: ncat
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
StringEnumeration *e = NULL;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp));
}
e = locale.createKeywords(status);
if (e && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
keyDisplayName(key, temp);
keyValueDisplayName(key, value, temp2);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
Formattable data[] = {
temp,
temp2
};
FieldPosition fpos;
status = U_ZERO_ERROR;
keyTypeFormat->format(data, 2, temp3, fpos, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
delete e;
}
if (!resultRemainder.isEmpty()) {
Formattable data[] = {
resultName,
resultRemainder
//.........这里部分代码省略.........