当前位置: 首页>>代码示例>>C++>>正文


C++ Locale::getName方法代码示例

本文整理汇总了C++中Locale::getName方法的典型用法代码示例。如果您正苦于以下问题:C++ Locale::getName方法的具体用法?C++ Locale::getName怎么用?C++ Locale::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Locale的用法示例。


在下文中一共展示了Locale::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestSeparateTree

void CollationServiceTest::TestSeparateTree() {
    UErrorCode ec = U_ZERO_ERROR;
    StringEnumeration *iter = Collator::getKeywords(ec);
    if (!assertTrue("getKeywords != NULL", iter!=NULL)) return;
    if (!assertSuccess("getKeywords", ec)) return;
    checkStringEnumeration("getKeywords", *iter, KW, KW_COUNT);
    delete iter;

    iter = Collator::getKeywordValues(KW[0], ec);
    if (!assertTrue("getKeywordValues != NULL", iter!=NULL, FALSE, TRUE)) return;
    if (!assertSuccess("getKeywordValues", ec)) return;
    checkStringEnumeration("getKeywordValues", *iter, KWVAL, KWVAL_COUNT);
    delete iter;

    UBool isAvailable;
    Locale equiv = Collator::getFunctionalEquivalent("collation",
                                                     Locale::createFromName("de"),
                                                     isAvailable, ec);
    assertSuccess("getFunctionalEquivalent", ec);
    assertEquals("getFunctionalEquivalent(de)", "de", equiv.getName());
    assertTrue("getFunctionalEquivalent(de).isAvailable==TRUE",
               isAvailable == TRUE);

    equiv = Collator::getFunctionalEquivalent("collation",
                                              Locale::createFromName("de_DE"),
                                              isAvailable, ec);
    assertSuccess("getFunctionalEquivalent", ec);
    assertEquals("getFunctionalEquivalent(de_DE)", "de", equiv.getName());
    assertTrue("getFunctionalEquivalent(de_DE).isAvailable==TRUE",
               isAvailable == TRUE);
}
开发者ID:ACSOP,项目名称:android_external_icu4c,代码行数:31,代码来源:svccoll.cpp

示例2: rb

void 
ResourceBundleTest::TestGetLocaleByType(void) 
{
    const struct {
        const char *requestedLocale;
        const char *resourceKey;
        const char *validLocale;
        const char *actualLocale;
    } test[] = {
        { "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" },
        { "te_IN_BLAH", "string_only_in_te", "te_IN", "te" },
        { "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" },
        { "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" },
        { "[email protected]=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" },
        { "[email protected]=thai;collation=phonebook", "array_2d_only_in_te", "te_IN", "te" }
    };
    
    UErrorCode status = U_ZERO_ERROR;
    
    const char* testdatapath = loadTestData(status);
    int32_t i = 0;
    Locale locale;
    
    if(U_FAILURE(status))
    {
        dataerrln("Could not load testdata.dat %s\n", u_errorName(status));
        return;
    }
    
    for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) {
        ResourceBundle rb(testdatapath, test[i].requestedLocale, status);
        if(U_FAILURE(status))
        {
            err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status));
            status = U_ZERO_ERROR;
            continue;
        }
        
        ResourceBundle res = rb.get(test[i].resourceKey, status);
        if(U_FAILURE(status))
        {
            err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status));
            status = U_ZERO_ERROR;
            continue;
        }
        
        locale = res.getLocale(ULOC_REQUESTED_LOCALE, status);
        if(locale != Locale::getDefault()) {
            err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
        }
        locale = res.getLocale(ULOC_VALID_LOCALE, status);
        if(strcmp(locale.getName(), test[i].validLocale) != 0) {
            err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
        }
        locale = res.getLocale(ULOC_ACTUAL_LOCALE, status);
        if(strcmp(locale.getName(), test[i].actualLocale) != 0) {
            err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName());
        }
    }
}
开发者ID:LittoCats,项目名称:OT_4010D,代码行数:60,代码来源:restest.cpp

示例3: create

  virtual UObject* create(const ICUServiceKey& key, const ICUService* /*service*/, UErrorCode& status) const  {

  LocaleKey &lkey = (LocaleKey&)key;
  Locale loc;
  lkey.currentLocale(loc);

#ifdef U_DEBUG_CALSVC
  fprintf(stderr, "DefaultCalendar factory %p: looking up %s\n", 
          this, (const char*)loc.getName());
#endif

  UErrorCode resStatus = U_ZERO_ERROR;

  UResourceBundle *rb = ures_open(NULL, (const char*)loc.getName(), &resStatus);

#ifdef U_DEBUG_CALSVC
  fprintf(stderr, "... ures_open -> %s\n", u_errorName(resStatus));
#endif
  if(U_FAILURE(resStatus) || 
     (resStatus == U_USING_DEFAULT_WARNING) || (resStatus==U_USING_FALLBACK_WARNING)) { //Don't want to handle fallback data.
    ures_close(rb);
    status = resStatus; // propagate err back to caller
#ifdef U_DEBUG_CALSVC
    fprintf(stderr, "... exitting (NULL)\n");
#endif

    return NULL;
  }

  int32_t len = 0;

  UnicodeString myString = ures_getUnicodeStringByKey(rb, Calendar::kDefaultCalendar, &status);

#ifdef U_DEBUG_CALSVC
  UErrorCode debugStatus = U_ZERO_ERROR;
  const UChar *defCal = ures_getStringByKey(rb, Calendar::kDefaultCalendar, &len,  &debugStatus);
  fprintf(stderr, "... get string(%d) -> %s\n", len, u_errorName(debugStatus));
#endif

  ures_close(rb);
  
   if(U_FAILURE(status)) {
    return NULL;
  }
 

#ifdef U_DEBUG_CALSVC
   {
     char defCalStr[200];
     if(len > 199) {
       len = 199;
     }
     u_UCharsToChars(defCal, defCalStr, len);
     defCalStr[len]=0;
     fprintf(stderr, "DefaultCalendarFactory: looked up %s, got DefaultCalendar= %s\n",  (const char*)loc.getName(), defCalStr);
   }
#endif

   return myString.clone();
 }
开发者ID:gitpan,项目名称:ponie,代码行数:60,代码来源:calendar.cpp

示例4:

bool L10n::SaveLocale(const Locale& locale) const
{
	if (!ValidateLocale(locale))
		return false;

	g_ConfigDB.SetValueString(CFG_USER, "locale", locale.getName());
	g_ConfigDB.WriteValueToFile(CFG_USER, "locale", locale.getName());
	return true;
}
开发者ID:krichter722,项目名称:0ad,代码行数:9,代码来源:L10n.cpp

示例5: tr

void
WelcomeDialog::slotLocaleChanged()
{
    bool firstTime = (_locale->count() == 0);
    int index = _locale->currentItem();
    QString systemLocaleName = systemLocale.getName();

    // Set default locale for ICU
    if (!firstTime) {
        Locale locale = _locales[index];
        UErrorCode status = U_ZERO_ERROR;
        Locale::setDefault(locale, status);
        if (U_FAILURE(status)) {
            QString msg = tr("Failed setting locale to %1")
                          .arg(locale.getName());
            QMessageBox::critical(this, tr("Error"), msg);
        }
    }

    _locale->clear();
    for (int32_t i = 0; i < _localesCnt; ++i) {
        UnicodeString uname;
        _locales[i].getDisplayName(uname);

        QString name = convertToQt(uname);
        _locale->insertItem(name);

        if (firstTime && _locales[i].getName() == systemLocaleName) {
            firstTime = false;
            index = _locale->count() - 1;
        }
    }

    QString localeMsg = tr("Select the locale you are using.  This will "
                           "control the language\nused for messages "
                           "and the format of dates, money, ...\n\n");

    QString serverMsg = tr("Select the server to connect to.  The "
                           "default is \"localhost\"\nwhich will connect "
                           "to a server on your own computer.\n\n");

    _locale->setCurrentItem(index);
    _localeBox->setTitle(tr("Locale"));
    _localeMsg->setText(localeMsg);
    _localeLabel->setText(tr("Locale:"));
    _serverBox->setTitle(tr("Server"));
    _serverMsg->setText(serverMsg);
    _serverLabel->setText(tr("Server:"));
    _ok->setText(tr("OK"));
    _cancel->setText(tr("Cancel"));
}
开发者ID:cwarden,项目名称:quasar,代码行数:51,代码来源:welcome_dialog.cpp

示例6: nullTerminatedPath

void 
ResourceBundle::constructForLocale(const UnicodeString& path,
                                   const Locale& locale,
                                   UErrorCode& error)
{
    if (path.isEmpty()) {
        fResource = ures_open(NULL, locale.getName(), &error);
    }
    else {
        UnicodeString nullTerminatedPath(path);
        nullTerminatedPath.append((UChar)0);
        fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error);
    }
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:14,代码来源:resbund_cnv.cpp

示例7: SearchIterator

StringSearch::StringSearch(const UnicodeString &pattern,
                           const UnicodeString &text,
                           const Locale        &locale,
                                 BreakIterator *breakiter,
                                 UErrorCode    &status) :
                           SearchIterator(text, breakiter),
                           m_pattern_(pattern)
{
    if (U_FAILURE(status)) {
        m_strsrch_ = NULL;
        return;
    }

    m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(),
                              m_text_.getBuffer(), m_text_.length(),
                              locale.getName(), (UBreakIterator *)breakiter,
                              &status);
    uprv_free(m_search_);
    m_search_ = NULL;

    if (U_SUCCESS(status)) {
        // m_search_ has been created by the base SearchIterator class
        m_search_        = m_strsrch_->search;
    }
}
开发者ID:icu-project,项目名称:icu4c,代码行数:25,代码来源:stsearch.cpp

示例8: populate

void CompactData::populate(const Locale &locale, const char *nsName, CompactStyle compactStyle,
                           CompactType compactType, UErrorCode &status) {
    CompactDataSink sink(*this);
    LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &status));
    if (U_FAILURE(status)) { return; }

    bool nsIsLatn = strcmp(nsName, "latn") == 0;
    bool compactIsShort = compactStyle == CompactStyle::UNUM_SHORT;

    // Fall back to latn numbering system and/or short compact style.
    CharString resourceKey;
    getResourceBundleKey(nsName, compactStyle, compactType, resourceKey, status);
    UErrorCode localStatus = U_ZERO_ERROR;
    ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
    if (isEmpty && !nsIsLatn) {
        getResourceBundleKey("latn", compactStyle, compactType, resourceKey, status);
        localStatus = U_ZERO_ERROR;
        ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
    }
    if (isEmpty && !compactIsShort) {
        getResourceBundleKey(nsName, CompactStyle::UNUM_SHORT, compactType, resourceKey, status);
        localStatus = U_ZERO_ERROR;
        ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
    }
    if (isEmpty && !nsIsLatn && !compactIsShort) {
        getResourceBundleKey("latn", CompactStyle::UNUM_SHORT, compactType, resourceKey, status);
        localStatus = U_ZERO_ERROR;
        ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
    }

    // The last fallback should be guaranteed to return data.
    if (isEmpty) {
        status = U_INTERNAL_PROGRAM_ERROR;
    }
}
开发者ID:winlibs,项目名称:icu4c,代码行数:35,代码来源:number_compact.cpp

示例9: createInstanceByName

NumberingSystem* U_EXPORT2
NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) {

    char buffer[ULOC_KEYWORDS_CAPACITY];
    int32_t count = inLocale.getKeywordValue("numbers",buffer, sizeof(buffer),status);
    if ( count > 0 ) { // @numbers keyword was specified in the locale
        buffer[count] = '\0'; // Make sure it is null terminated.
        return NumberingSystem::createInstanceByName(buffer,status);
    } else { // Find the default numbering system for this locale.
        LocalUResourceBundlePointer resource(ures_open(NULL, inLocale.getName(), &status));
        if (U_FAILURE(status)) {
            status = U_USING_FALLBACK_WARNING;
            NumberingSystem *ns = new NumberingSystem();
            return ns;
        } 
        const UChar *defaultNSName =
            ures_getStringByKeyWithFallback(resource.getAlias(), gDefaultNumberingSystem, &count, &status);
        if (U_FAILURE(status)) {
               return NULL;
        }
        if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // Default numbering system found
           u_UCharsToChars(defaultNSName,buffer,count); 
           buffer[count] = '\0'; // Make sure it is null terminated.
           return NumberingSystem::createInstanceByName(buffer,status);
        } else {
            status = U_USING_FALLBACK_WARNING;
            NumberingSystem *ns = new NumberingSystem();
            return ns;
        }
        
    }
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:32,代码来源:numsys.cpp

示例10: SearchIterator

StringSearch::StringSearch(const UnicodeString     &pattern, 
                                 CharacterIterator &text,
                           const Locale            &locale, 
                                 BreakIterator     *breakiter,
                                 UErrorCode        &status) :
                           SearchIterator(text, breakiter), 
                           m_collator_(),
                           m_pattern_(pattern)
{
    if (U_FAILURE(status)) {
        m_strsrch_ = NULL;
        return;
    }
    m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(), 
                              m_text_.getBuffer(), m_text_.length(), 
                              locale.getName(), (UBreakIterator *)breakiter, 
                              &status);
    uprv_free(m_search_);
    m_search_ = NULL;

    if (U_SUCCESS(status)) {
              int32_t  length;
        const UChar   *rules = ucol_getRules(m_strsrch_->collator, &length);
        m_collation_rules_.setTo(rules, length);
        m_collator_.setUCollator((UCollator *)m_strsrch_->collator,
                                 &m_collation_rules_);
        // m_search_ has been created by the base SearchIterator class
        m_search_ = m_strsrch_->search;
    }
}
开发者ID:gitpan,项目名称:ponie,代码行数:30,代码来源:stsearch.cpp

示例11: create

GLUE_SYM ( DateFormat ) :: create(UDateFormatStyle  timeStyle,
                                                    UDateFormatStyle  dateStyle,
                                                    const char        *locale,
                                                    const UChar       *tzID,
                                                    int32_t           tzIDLength,
                                                    const UChar       *pattern,
                                                    int32_t           patternLength,
                                                    UErrorCode        *status,
                                  const Locale &loc, const char */*ver*/) {
  // TODO: save version
  //char locBuf[200];
  //char kwvBuf[200];
  UDateFormat * uc =  OICU_udat_open( timeStyle, dateStyle, locale,
                                      tzID,
                                      tzIDLength,
                                      pattern,
                                      patternLength,
                                      status);
    if(U_FAILURE(*status)) return NULL; // TODO: ERR?
    DateFormat *c =  new GLUE_SYM( DateFormat ) ( uc );
#if DATE_FE_DEBUG
    fprintf(stderr, "VCF " ICUGLUE_VER_STR " udat_open=%s ->> %p\n", loc.getName(), (void*)c);
#endif
    return c;
}
开发者ID:icu-project,项目名称:icu-tools,代码行数:25,代码来源:date_fe.cpp

示例12: PHP_FUNCTION

U_CFUNC PHP_FUNCTION(breakiter_get_locale)
{
	zend_long	locale_type;
	BREAKITER_METHOD_INIT_VARS;
	object = getThis();

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &locale_type) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"breakiter_get_locale: bad arguments", 0);
		RETURN_FALSE;
	}

	if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"breakiter_get_locale: invalid locale type", 0);
		RETURN_FALSE;
	}

	BREAKITER_METHOD_FETCH_OBJECT;

	Locale locale = bio->biter->getLocale((ULocDataLocaleType)locale_type,
		BREAKITER_ERROR_CODE(bio));
	INTL_METHOD_CHECK_STATUS(bio,
		"breakiter_get_locale: Call to ICU method has failed");

	RETURN_STRING(locale.getName());
}
开发者ID:13572293130,项目名称:php-src,代码行数:27,代码来源:breakiterator_methods.cpp

示例13: PHP_FUNCTION

U_CFUNC PHP_FUNCTION(intlcal_get_locale)
{
	zend_long	locale_type;
	CALENDAR_METHOD_INIT_VARS;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
			"Ol", &object, Calendar_ce_ptr, &locale_type) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_get_locale: bad arguments", 0 TSRMLS_CC);
		RETURN_FALSE;
	}

	if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intlcal_get_locale: invalid locale type", 0 TSRMLS_CC);
		RETURN_FALSE;
	}

	CALENDAR_METHOD_FETCH_OBJECT;

	Locale locale = co->ucal->getLocale((ULocDataLocaleType)locale_type,
		CALENDAR_ERROR_CODE(co));
	INTL_METHOD_CHECK_STATUS(co,
		"intlcal_get_locale: Call to ICU method has failed");

	RETURN_STRING(locale.getName());
}
开发者ID:forgotting,项目名称:php-src,代码行数:27,代码来源:calendar_methods.cpp

示例14: makeInstance

Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
                                   UErrorCode& status)
{
    if (U_FAILURE(status)) 
        return 0;
    
#if !UCONFIG_NO_SERVICE
    if (hasService()) {
        Locale actualLoc;
        Collator *result =
            (Collator*)gService->get(desiredLocale, &actualLoc, status);
        // Ugly Hack Alert! If the returned locale is empty (not root,
        // but empty -- getName() == "") then that means the service
        // returned a default object, not a "real" service object.  In
        // that case, the locale metadata (valid & actual) is setup
        // correctly already, and we don't want to overwrite it. (TODO
        // remove in 3.0) [aliu]
        if (*actualLoc.getName() != 0) {
            result->setLocales(desiredLocale, actualLoc, actualLoc);
        }
        return result;
    }
#endif
    return makeInstance(desiredLocale, status);
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:25,代码来源:coll.cpp

示例15: lock

U_CDECL_END

U_NAMESPACE_BEGIN

Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
    // Synchronize this entire function.
    Mutex lock(&gDefaultLocaleMutex);

    UBool canonicalize = FALSE;

    // If given a NULL string for the locale id, grab the default
    //   name from the system.
    //   (Different from most other locale APIs, where a null name means use
    //    the current ICU default locale.)
    if (id == NULL) {
        id = uprv_getDefaultLocaleID();   // This function not thread safe? TODO: verify.
        canonicalize = TRUE; // always canonicalize host ID
    }

    char localeNameBuf[512];

    if (canonicalize) {
        uloc_canonicalize(id, localeNameBuf, sizeof(localeNameBuf)-1, &status);
    } else {
        uloc_getName(id, localeNameBuf, sizeof(localeNameBuf)-1, &status);
    }
    localeNameBuf[sizeof(localeNameBuf)-1] = 0;  // Force null termination in event of
                                                 //   a long name filling the buffer.
                                                 //   (long names are truncated.)
                                                 //
    if (U_FAILURE(status)) {
        return gDefaultLocale;
    }

    if (gDefaultLocalesHashT == NULL) {
        gDefaultLocalesHashT = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
        if (U_FAILURE(status)) {
            return gDefaultLocale;
        }
        uhash_setValueDeleter(gDefaultLocalesHashT, deleteLocale);
        ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
    }

    Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf);
    if (newDefault == NULL) {
        newDefault = new Locale(Locale::eBOGUS);
        if (newDefault == NULL) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return gDefaultLocale;
        }
        newDefault->init(localeNameBuf, FALSE);
        uhash_put(gDefaultLocalesHashT, (char*) newDefault->getName(), newDefault, &status);
        if (U_FAILURE(status)) {
            return gDefaultLocale;
        }
    }
    gDefaultLocale = newDefault;
    return gDefaultLocale;
}
开发者ID:winlibs,项目名称:icu4c,代码行数:59,代码来源:locid.cpp


注:本文中的Locale::getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。