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


C++ Collator类代码示例

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


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

示例1: errln

// @bug 4124632
//
// Collator::getCollationKey was hanging on certain character sequences
//
void CollationRegressionTest::Test4124632(/* char* par */)
{
    UErrorCode status = U_ZERO_ERROR;
    Collator *coll = NULL;

    coll = Collator::createInstance(Locale::getJapan(), status);

    if (coll == NULL || U_FAILURE(status))
    {
        errln("Failed to create collator for Locale::JAPAN");
        delete coll;
        return;
    }

    static const UChar test[] = {0x41, 0x0308, 0x62, 0x63, 0};
    CollationKey key;

    coll->getCollationKey(test, key, status);

    if (key.isBogus() || U_FAILURE(status))
    {
        errln("CollationKey creation failed.");
    }

    delete coll;
}
开发者ID:Acorld,项目名称:WinObjC-Heading,代码行数:30,代码来源:regcoll.cpp

示例2: 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

示例3: el_GR

// @bug 4095316
//
void CollationRegressionTest::Test4095316(/* char* par */)
{
    UErrorCode status = U_ZERO_ERROR;
    Locale el_GR("el", "GR");
    Collator *c = Collator::createInstance(el_GR, status);

    if (c == NULL || U_FAILURE(status))
    {
        errln("Failed to create collator for el_GR locale");
        delete c;
        return;
    }
    // These now have tertiary differences in UCA
    //c->setStrength(Collator::TERTIARY);
    c->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, status);

    static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
    {
        {0x03D4, 0}, {0x3d, 0}, {0x03AB, 0}
    };

    compareArray(*c, tests, ARRAY_LENGTH(tests));

    delete c;
}
开发者ID:Acorld,项目名称:WinObjC-Heading,代码行数:27,代码来源:regcoll.cpp

示例4: ucol_safeClone

U_CAPI UCollator* U_EXPORT2
ucol_safeClone(const UCollator *coll, void * /*stackBuffer*/, int32_t * pBufferSize, UErrorCode *status)
{
    if (status == NULL || U_FAILURE(*status)){
        return NULL;
    }
    if (coll == NULL) {
       *status = U_ILLEGAL_ARGUMENT_ERROR;
        return NULL;
    }
    if (pBufferSize != NULL) {
        int32_t inputSize = *pBufferSize;
        *pBufferSize = 1;
        if (inputSize == 0) {
            return NULL;  // preflighting for deprecated functionality
        }
    }
    Collator *newColl = Collator::fromUCollator(coll)->clone();
    if (newColl == NULL) {
        *status = U_MEMORY_ALLOCATION_ERROR;
    } else {
        *status = U_SAFECLONE_ALLOCATED_WARNING;
    }
    return newColl->toUCollator();
}
开发者ID:GuillaumeSmaha,项目名称:stringi,代码行数:25,代码来源:ucol.cpp

示例5: el

// @bug 4092260
//
// Mu/micro conflict
// Micro symbol and greek lowercase letter Mu should sort identically
//
void CollationRegressionTest::Test4092260(/* char* par */)
{
    UErrorCode status = U_ZERO_ERROR;
    Locale el("el", "");
    Collator *c = NULL;

    c = Collator::createInstance(el, status);

    if (c == NULL || U_FAILURE(status))
    {
        errln("Failed to create collator for el locale.");
        delete c;
        return;
    }

    // These now have tertiary differences in UCA
    c->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, status);

    static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
    {
        {0x00B5, 0}, {0x3d, 0}, {0x03BC, 0}
    };

    compareArray(*c, tests, UPRV_LENGTHOF(tests));

    delete c;
}
开发者ID:MIPS,项目名称:external-icu,代码行数:32,代码来源:regcoll.cpp

示例6: RuleBasedCollator

Collator *
Collator::createInstance(const Locale &loc,
                         UVersionInfo version,
                         UErrorCode &status)
{
    Collator *collator;
    UVersionInfo info;
    
    collator=new RuleBasedCollator(loc, status);
    /* test for NULL */
    if (collator == 0) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return 0;
    }
    
    if(U_SUCCESS(status)) {
        collator->getVersion(info);
        if(0!=uprv_memcmp(version, info, sizeof(UVersionInfo))) {
            delete collator;
            status=U_MISSING_RESOURCE_ERROR;
            return 0;
        }
    }
    return collator;
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:25,代码来源:coll.cpp

示例7: l

// @bug 4139572
//
// getCollationKey throws exception for spanish text
// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6
//
void CollationRegressionTest::Test4139572(/* char* par */)
{
    //
    // Code pasted straight from the bug report
    // (and then translated to C++ ;-)
    //
    // create spanish locale and collator
    UErrorCode status = U_ZERO_ERROR;
    Locale l("es", "es");
    Collator *col = NULL;

    col = Collator::createInstance(l, status);

    if (col == NULL || U_FAILURE(status))
    {
        errln("Failed to create a collator for es_es locale.");
        delete col;
        return;
    }

    CollationKey key;

    // this spanish phrase kills it!
    col->getCollationKey("Nombre De Objeto", key, status);

    if (key.isBogus() || U_FAILURE(status))
    {
        errln("Error creating CollationKey for \"Nombre De Ojbeto\"");
    }

    delete col;
}
开发者ID:Acorld,项目名称:WinObjC-Heading,代码行数:37,代码来源:regcoll.cpp

示例8: source

void CollationRegressionTest::compareArray(Collator &c,
                                           const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN],
                                           int32_t testCount)
{
    int32_t i;
    Collator::EComparisonResult expectedResult = Collator::EQUAL;

    for (i = 0; i < testCount; i += 3)
    {
        UnicodeString source(tests[i]);
        UnicodeString comparison(tests[i + 1]);
        UnicodeString target(tests[i + 2]);

        if (comparison == "<")
        {
            expectedResult = Collator::LESS;
        }
        else if (comparison == ">")
        {
            expectedResult = Collator::GREATER;
        }
        else if (comparison == "=")
        {
            expectedResult = Collator::EQUAL;
        }
        else
        {
            UnicodeString bogus1("Bogus comparison string \"");
            UnicodeString bogus2("\"");
            errln(bogus1 + comparison + bogus2);
        }

        Collator::EComparisonResult compareResult = c.compare(source, target);

        CollationKey sourceKey, targetKey;
        UErrorCode status = U_ZERO_ERROR;

        c.getCollationKey(source, sourceKey, status);

        if (U_FAILURE(status))
        {
            errln("Couldn't get collationKey for source");
            continue;
        }

        c.getCollationKey(target, targetKey, status);

        if (U_FAILURE(status))
        {
            errln("Couldn't get collationKey for target");
            continue;
        }

        Collator::EComparisonResult keyResult = sourceKey.compareTo(targetKey);

        reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult );

    }
}
开发者ID:Acorld,项目名称:WinObjC-Heading,代码行数:59,代码来源:regcoll.cpp

示例9: init

void UCollationPCE::init(const Collator &coll)
{
    UErrorCode status = U_ZERO_ERROR;

    strength    = coll.getAttribute(UCOL_STRENGTH, status);
    toShift     = coll.getAttribute(UCOL_ALTERNATE_HANDLING, status) == UCOL_SHIFTED;
    isShifted   = FALSE;
    variableTop = coll.getVariableTop(status);
}
开发者ID:winlibs,项目名称:icu4c,代码行数:9,代码来源:ucoleitr.cpp

示例10: LOG_ERROR

void Utf8Helper::setCollatorLanguage (const string& lang) {
  UErrorCode status = U_ZERO_ERROR;

  if (_coll) {
    ULocDataLocaleType type = ULOC_ACTUAL_LOCALE;
    const Locale& locale = _coll->getLocale(type, status);

    if(U_FAILURE(status)) {
      LOG_ERROR("error in Collator::getLocale(...): %s", u_errorName(status));
      return;
    }
    if (lang == locale.getName()) {
      return;
    }
  }

  Collator* coll;
  if (lang == "") {
    // get default collator for empty language
    coll = Collator::createInstance(status);
  }
  else {
    Locale locale(lang.c_str());
    coll = Collator::createInstance(locale, status);
  }

  if(U_FAILURE(status)) {
    LOG_ERROR("error in Collator::createInstance(): %s", u_errorName(status));
    if (coll) {
      delete coll;
    }
    return;
  }

  // set the default attributes for sorting:
  coll->setAttribute(UCOL_CASE_FIRST, UCOL_UPPER_FIRST, status);  // A < a
  coll->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_OFF, status);  // no normalization
  coll->setAttribute(UCOL_STRENGTH, UCOL_IDENTICAL, status);      // UCOL_IDENTICAL, UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY

  if(U_FAILURE(status)) {
    LOG_ERROR("error in Collator::setAttribute(...): %s", u_errorName(status));
    delete coll;
    return;
  }

  if (_coll) {
    delete _coll;
  }

  _coll = coll;
}
开发者ID:bdacode,项目名称:ArangoDB,代码行数:51,代码来源:Utf8Helper.cpp

示例11: compareAtWithCollation

int ColumnString::compareAtWithCollation(size_t n, size_t m, const IColumn & rhs_, const Collator & collator) const
{
	const ColumnString & rhs = static_cast<const ColumnString &>(rhs_);

	return collator.compare(
		reinterpret_cast<const char *>(&chars[offsetAt(n)]), sizeAt(n),
		reinterpret_cast<const char *>(&rhs.chars[rhs.offsetAt(m)]), rhs.sizeAt(m));
}
开发者ID:jacktang,项目名称:ClickHouse,代码行数:8,代码来源:ColumnString.cpp

示例12: desiredLocale

UCollator* 
Collator::createUCollator(const char *loc,
                          UErrorCode *status)
{
    UCollator *result = 0;
    if (status && U_SUCCESS(*status) && hasService()) {
        Locale desiredLocale(loc);
        Collator *col = (Collator*)gService->get(desiredLocale, *status);
        if (col && col->getDynamicClassID() == RuleBasedCollator::getStaticClassID()) {
            RuleBasedCollator *rbc = (RuleBasedCollator *)col;
            if (!rbc->dataIsOwned) {
                result = ucol_safeClone(rbc->ucollator, NULL, NULL, status);
            } else {
                result = rbc->ucollator;
                rbc->ucollator = NULL; // to prevent free on delete
            }
        }
        delete col;
    }
    return result;
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:21,代码来源:coll.cpp

示例13: getKey

 virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const {
     UnicodeString ar;
     if (actualReturn == NULL) {
         actualReturn = &ar;
     }
     Collator* result = (Collator*)ICULocaleService::getKey(key, actualReturn, status);
     // Ugly Hack Alert! If the actualReturn length is zero, this
     // means we got a default object, not a "real" service-created
     // object.  We don't call setLocales() on a default object,
     // because that will overwrite its correct built-in locale
     // metadata (valid & actual) with our incorrect data (all we
     // have is the requested locale). (TODO remove in 3.0) [aliu]
     if (result && actualReturn->length() > 0) {
         const LocaleKey& lkey = (const LocaleKey&)key;
         Locale canonicalLocale("");
         Locale currentLocale("");
         
         LocaleUtility::initLocaleFromName(*actualReturn, currentLocale);
         result->setLocales(lkey.canonicalLocale(canonicalLocale), currentLocale, currentLocale);
     }
     return result;
 }
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:22,代码来源:coll.cpp

示例14: getBucketIndex

 int32_t getBucketIndex(const UnicodeString &name, const Collator &collatorPrimaryOnly,
                        UErrorCode &errorCode) {
     // binary search
     int32_t start = 0;
     int32_t limit = bucketList_->size();
     while ((start + 1) < limit) {
         int32_t i = (start + limit) / 2;
         const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, i);
         UCollationResult nameVsBucket =
             collatorPrimaryOnly.compare(name, bucket->lowerBoundary_, errorCode);
         if (nameVsBucket < 0) {
             limit = i;
         } else {
             start = i;
         }
     }
     const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, start);
     if (bucket->displayBucket_ != NULL) {
         bucket = bucket->displayBucket_;
     }
     return bucket->displayIndex_;
 }
开发者ID:DavidCai1993,项目名称:node,代码行数:22,代码来源:alphaindex.cpp

示例15: ucol_equals

UBool RuleBasedCollator::operator==(const Collator& that) const
{
  /* only checks for address equals here */
  if (Collator::operator==(that))
    return TRUE;

  if (getDynamicClassID() != that.getDynamicClassID())
    return FALSE;  /* not the same class */

  RuleBasedCollator& thatAlias = (RuleBasedCollator&)that;

  // weiv: use C function, commented code below is wrong
  return ucol_equals(this->ucollator, thatAlias.ucollator);
  /*
  synwee : orginal code does not check for data compatibility
  */
  /*
  if (ucollator != thatAlias.ucollator)
    return FALSE;

  return TRUE;
  */
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:23,代码来源:tblcoll.cpp


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