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; }
// @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; }
// @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; }