1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 1996-2014, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ******************************************************************************
13 * Created by: Helena Shih
15 * Modification History:
17 * Date Name Description
18 * 2/5/97 aliu Modified createDefault to load collation data from
19 * binary files when possible. Added related methods
20 * createCollationFromFile, chopLocale, createPathName.
21 * 2/11/97 aliu Added methods addToCache, findInCache, which implement
22 * a Collation cache. Modified createDefault to look in
23 * cache first, and also to store newly created Collation
24 * objects in the cache. Modified to not use gLocPath.
25 * 2/12/97 aliu Modified to create objects from RuleBasedCollator cache.
26 * Moved cache out of Collation class.
27 * 2/13/97 aliu Moved several methods out of this class and into
28 * RuleBasedCollator, with modifications. Modified
29 * createDefault() to call new RuleBasedCollator(Locale&)
30 * constructor. General clean up and documentation.
31 * 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
33 * 05/06/97 helena Added memory allocation error detection.
34 * 05/08/97 helena Added createInstance().
35 * 6/20/97 helena Java class name change.
36 * 04/23/99 stephen Removed EDecompositionMode, merged with
38 * 11/23/9 srl Inlining of some critical functions
39 * 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
40 * 2012-2014 markus Rewritten in C++ again.
43 #include "utypeinfo.h" // for 'typeid' to work
45 #include "unicode/utypes.h"
47 #if !UCONFIG_NO_COLLATION
49 #include "unicode/coll.h"
50 #include "unicode/tblcoll.h"
51 #include "collationdata.h"
52 #include "collationroot.h"
53 #include "collationtailoring.h"
64 static icu::Locale* availableLocaleList = NULL;
65 static int32_t availableLocaleListCount;
66 static icu::ICULocaleService* gService = NULL;
67 static icu::UInitOnce gServiceInitOnce = U_INITONCE_INITIALIZER;
68 static icu::UInitOnce gAvailableLocaleListInitOnce;
71 * Release all static memory held by collator.
74 static UBool U_CALLCONV collator_cleanup(void) {
75 #if !UCONFIG_NO_SERVICE
80 gServiceInitOnce.reset();
82 if (availableLocaleList) {
83 delete []availableLocaleList;
84 availableLocaleList = NULL;
86 availableLocaleListCount = 0;
87 gAvailableLocaleListInitOnce.reset();
95 #if !UCONFIG_NO_SERVICE
97 // ------------------------------------------
102 //-------------------------------------------
104 CollatorFactory::~CollatorFactory() {}
106 //-------------------------------------------
109 CollatorFactory::visible(void) const {
113 //-------------------------------------------
116 CollatorFactory::getDisplayName(const Locale& objectLocale,
117 const Locale& displayLocale,
118 UnicodeString& result)
120 return objectLocale.getDisplayName(displayLocale, result);
123 // -------------------------------------
125 class ICUCollatorFactory : public ICUResourceBundleFactory {
127 ICUCollatorFactory() : ICUResourceBundleFactory(UnicodeString(U_ICUDATA_COLL, -1, US_INV)) { }
128 virtual ~ICUCollatorFactory();
130 virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
133 ICUCollatorFactory::~ICUCollatorFactory() {}
136 ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const {
137 if (handlesKey(key, status)) {
138 const LocaleKey& lkey = (const LocaleKey&)key;
140 // make sure the requested locale is correct
141 // default LocaleFactory uses currentLocale since that's the one vetted by handlesKey
142 // but for ICU rb resources we use the actual one since it will fallback again
143 lkey.canonicalLocale(loc);
145 return Collator::makeInstance(loc, status);
150 // -------------------------------------
152 class ICUCollatorService : public ICULocaleService {
155 : ICULocaleService(UNICODE_STRING_SIMPLE("Collator"))
157 UErrorCode status = U_ZERO_ERROR;
158 registerFactory(new ICUCollatorFactory(), status);
161 virtual ~ICUCollatorService();
163 virtual UObject* cloneInstance(UObject* instance) const {
164 return ((Collator*)instance)->clone();
167 virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const {
168 LocaleKey& lkey = (LocaleKey&)key;
170 // Ugly Hack Alert! We return an empty actualID to signal
171 // to callers that this is a default object, not a "real"
172 // service-created object. (TODO remove in 3.0) [aliu]
173 actualID->truncate(0);
176 lkey.canonicalLocale(loc);
177 return Collator::makeInstance(loc, status);
180 virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const {
182 if (actualReturn == NULL) {
185 return (Collator*)ICULocaleService::getKey(key, actualReturn, status);
188 virtual UBool isDefault() const {
189 return countFactories() == 1;
193 ICUCollatorService::~ICUCollatorService() {}
195 // -------------------------------------
197 static void U_CALLCONV initService() {
198 gService = new ICUCollatorService();
199 ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup);
203 static ICULocaleService*
206 umtx_initOnce(gServiceInitOnce, &initService);
210 // -------------------------------------
215 UBool retVal = !gServiceInitOnce.isReset() && (getService() != NULL);
219 #endif /* UCONFIG_NO_SERVICE */
221 static void U_CALLCONV
222 initAvailableLocaleList(UErrorCode &status) {
223 U_ASSERT(availableLocaleListCount == 0);
224 U_ASSERT(availableLocaleList == NULL);
225 // for now, there is a hardcoded list, so just walk through that list and set it up.
226 UResourceBundle *index = NULL;
227 UResourceBundle installed;
230 ures_initStackObject(&installed);
231 index = ures_openDirect(U_ICUDATA_COLL, "res_index", &status);
232 ures_getByKey(index, "InstalledLocales", &installed, &status);
234 if(U_SUCCESS(status)) {
235 availableLocaleListCount = ures_getSize(&installed);
236 availableLocaleList = new Locale[availableLocaleListCount];
238 if (availableLocaleList != NULL) {
239 ures_resetIterator(&installed);
240 while(ures_hasNext(&installed)) {
241 const char *tempKey = NULL;
242 ures_getNextString(&installed, NULL, &tempKey, &status);
243 availableLocaleList[i++] = Locale(tempKey);
246 U_ASSERT(availableLocaleListCount == i);
247 ures_close(&installed);
250 ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup);
253 static UBool isAvailableLocaleListInitialized(UErrorCode &status) {
254 umtx_initOnce(gAvailableLocaleListInitOnce, &initAvailableLocaleList, status);
255 return U_SUCCESS(status);
259 // Collator public methods -----------------------------------------------
263 static const struct {
266 } collAttributes[] = {
267 { "colStrength", UCOL_STRENGTH },
268 { "colBackwards", UCOL_FRENCH_COLLATION },
269 { "colCaseLevel", UCOL_CASE_LEVEL },
270 { "colCaseFirst", UCOL_CASE_FIRST },
271 { "colAlternate", UCOL_ALTERNATE_HANDLING },
272 { "colNormalization", UCOL_NORMALIZATION_MODE },
273 { "colNumeric", UCOL_NUMERIC_COLLATION }
276 static const struct {
278 UColAttributeValue value;
279 } collAttributeValues[] = {
280 { "primary", UCOL_PRIMARY },
281 { "secondary", UCOL_SECONDARY },
282 { "tertiary", UCOL_TERTIARY },
283 { "quaternary", UCOL_QUATERNARY },
284 // Note: Not supporting typo "quarternary" because it was never supported in locale IDs.
285 { "identical", UCOL_IDENTICAL },
288 { "shifted", UCOL_SHIFTED },
289 { "non-ignorable", UCOL_NON_IGNORABLE },
290 { "lower", UCOL_LOWER_FIRST },
291 { "upper", UCOL_UPPER_FIRST }
294 static const char *collReorderCodes[UCOL_REORDER_CODE_LIMIT - UCOL_REORDER_CODE_FIRST] = {
295 "space", "punct", "symbol", "currency", "digit"
298 int32_t getReorderCode(const char *s) {
299 for (int32_t i = 0; i < UPRV_LENGTHOF(collReorderCodes); ++i) {
300 if (uprv_stricmp(s, collReorderCodes[i]) == 0) {
301 return UCOL_REORDER_CODE_FIRST + i;
304 // Not supporting "others" = UCOL_REORDER_CODE_OTHERS
305 // as a synonym for Zzzz = USCRIPT_UNKNOWN for now:
306 // Avoid introducing synonyms/aliases.
311 * Sets collation attributes according to locale keywords. See
312 * http://www.unicode.org/reports/tr35/tr35-collation.html#Collation_Settings
314 * Using "alias" keywords and values where defined:
315 * http://www.unicode.org/reports/tr35/tr35.html#Old_Locale_Extension_Syntax
316 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml
318 void setAttributesFromKeywords(const Locale &loc, Collator &coll, UErrorCode &errorCode) {
319 if (U_FAILURE(errorCode)) {
322 if (uprv_strcmp(loc.getName(), loc.getBaseName()) == 0) {
326 char value[1024]; // The reordering value could be long.
327 // Check for collation keywords that were already deprecated
328 // before any were supported in createInstance() (except for "collation").
329 int32_t length = loc.getKeywordValue("colHiraganaQuaternary", value, UPRV_LENGTHOF(value), errorCode);
330 if (U_FAILURE(errorCode)) {
331 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
335 errorCode = U_UNSUPPORTED_ERROR;
338 length = loc.getKeywordValue("variableTop", value, UPRV_LENGTHOF(value), errorCode);
339 if (U_FAILURE(errorCode)) {
340 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
344 errorCode = U_UNSUPPORTED_ERROR;
347 // Parse known collation keywords, ignore others.
348 if (errorCode == U_STRING_NOT_TERMINATED_WARNING) {
349 errorCode = U_ZERO_ERROR;
351 for (int32_t i = 0; i < UPRV_LENGTHOF(collAttributes); ++i) {
352 length = loc.getKeywordValue(collAttributes[i].name, value, UPRV_LENGTHOF(value), errorCode);
353 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
354 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
357 if (length == 0) { continue; }
358 for (int32_t j = 0;; ++j) {
359 if (j == UPRV_LENGTHOF(collAttributeValues)) {
360 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
363 if (uprv_stricmp(value, collAttributeValues[j].name) == 0) {
364 coll.setAttribute(collAttributes[i].attr, collAttributeValues[j].value, errorCode);
369 length = loc.getKeywordValue("colReorder", value, UPRV_LENGTHOF(value), errorCode);
370 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
371 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
375 int32_t codes[USCRIPT_CODE_LIMIT + UCOL_REORDER_CODE_LIMIT - UCOL_REORDER_CODE_FIRST];
376 int32_t codesLength = 0;
377 char *scriptName = value;
379 if (codesLength == UPRV_LENGTHOF(codes)) {
380 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
383 char *limit = scriptName;
385 while ((c = *limit) != 0 && c != '-') { ++limit; }
388 if ((limit - scriptName) == 4) {
389 // Strict parsing, accept only 4-letter script codes, not long names.
390 code = u_getPropertyValueEnum(UCHAR_SCRIPT, scriptName);
392 code = getReorderCode(scriptName);
395 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
398 codes[codesLength++] = code;
399 if (c == 0) { break; }
400 scriptName = limit + 1;
402 coll.setReorderCodes(codes, codesLength, errorCode);
404 length = loc.getKeywordValue("kv", value, UPRV_LENGTHOF(value), errorCode);
405 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
406 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
410 int32_t code = getReorderCode(value);
412 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
415 coll.setMaxVariable((UColReorderCode)code, errorCode);
417 if (U_FAILURE(errorCode)) {
418 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
424 Collator* U_EXPORT2 Collator::createInstance(UErrorCode& success)
426 return createInstance(Locale::getDefault(), success);
429 Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
432 if (U_FAILURE(status))
434 if (desiredLocale.isBogus()) {
435 // Locale constructed from malformed locale ID or language tag.
436 status = U_ILLEGAL_ARGUMENT_ERROR;
441 #if !UCONFIG_NO_SERVICE
444 coll = (Collator*)gService->get(desiredLocale, &actualLoc, status);
448 coll = makeInstance(desiredLocale, status);
450 setAttributesFromKeywords(desiredLocale, *coll, status);
451 if (U_FAILURE(status)) {
459 Collator* Collator::makeInstance(const Locale& desiredLocale, UErrorCode& status) {
460 const CollationCacheEntry *entry = CollationLoader::loadTailoring(desiredLocale, status);
461 if (U_SUCCESS(status)) {
462 Collator *result = new RuleBasedCollator(entry);
463 if (result != NULL) {
464 // Both the unified cache's get() and the RBC constructor
465 // did addRef(). Undo one of them.
469 status = U_MEMORY_ALLOCATION_ERROR;
472 // Undo the addRef() from the cache.get().
479 Collator::safeClone() const {
483 // implement deprecated, previously abstract method
484 Collator::EComparisonResult Collator::compare(const UnicodeString& source,
485 const UnicodeString& target) const
487 UErrorCode ec = U_ZERO_ERROR;
488 return (EComparisonResult)compare(source, target, ec);
491 // implement deprecated, previously abstract method
492 Collator::EComparisonResult Collator::compare(const UnicodeString& source,
493 const UnicodeString& target,
494 int32_t length) const
496 UErrorCode ec = U_ZERO_ERROR;
497 return (EComparisonResult)compare(source, target, length, ec);
500 // implement deprecated, previously abstract method
501 Collator::EComparisonResult Collator::compare(const UChar* source, int32_t sourceLength,
502 const UChar* target, int32_t targetLength)
505 UErrorCode ec = U_ZERO_ERROR;
506 return (EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
509 UCollationResult Collator::compare(UCharIterator &/*sIter*/,
510 UCharIterator &/*tIter*/,
511 UErrorCode &status) const {
512 if(U_SUCCESS(status)) {
513 // Not implemented in the base class.
514 status = U_UNSUPPORTED_ERROR;
519 UCollationResult Collator::compareUTF8(const StringPiece &source,
520 const StringPiece &target,
521 UErrorCode &status) const {
522 if(U_FAILURE(status)) {
525 UCharIterator sIter, tIter;
526 uiter_setUTF8(&sIter, source.data(), source.length());
527 uiter_setUTF8(&tIter, target.data(), target.length());
528 return compare(sIter, tIter, status);
531 UBool Collator::equals(const UnicodeString& source,
532 const UnicodeString& target) const
534 UErrorCode ec = U_ZERO_ERROR;
535 return (compare(source, target, ec) == UCOL_EQUAL);
538 UBool Collator::greaterOrEqual(const UnicodeString& source,
539 const UnicodeString& target) const
541 UErrorCode ec = U_ZERO_ERROR;
542 return (compare(source, target, ec) != UCOL_LESS);
545 UBool Collator::greater(const UnicodeString& source,
546 const UnicodeString& target) const
548 UErrorCode ec = U_ZERO_ERROR;
549 return (compare(source, target, ec) == UCOL_GREATER);
552 // this API ignores registered collators, since it returns an
553 // array of indefinite lifetime
554 const Locale* U_EXPORT2 Collator::getAvailableLocales(int32_t& count)
556 UErrorCode status = U_ZERO_ERROR;
557 Locale *result = NULL;
559 if (isAvailableLocaleListInitialized(status))
561 result = availableLocaleList;
562 count = availableLocaleListCount;
567 UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale,
568 const Locale& displayLocale,
571 #if !UCONFIG_NO_SERVICE
573 UnicodeString locNameStr;
574 LocaleUtility::initNameFromLocale(objectLocale, locNameStr);
575 return gService->getDisplayName(locNameStr, name, displayLocale);
578 return objectLocale.getDisplayName(displayLocale, name);
581 UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale,
584 return getDisplayName(objectLocale, Locale::getDefault(), name);
587 /* This is useless information */
588 /*void Collator::getVersion(UVersionInfo versionInfo) const
590 if (versionInfo!=NULL)
591 uprv_memcpy(versionInfo, fVersion, U_MAX_VERSION_LENGTH);
595 // UCollator protected constructor destructor ----------------------------
598 * Default constructor.
599 * Constructor is different from the old default Collator constructor.
600 * The task for determing the default collation strength and normalization mode
601 * is left to the child class.
610 * Empty constructor, does not handle the arguments.
611 * This constructor is done for backward compatibility with 1.7 and 1.8.
612 * The task for handling the argument collation strength and normalization
613 * mode is left to the child class.
614 * @param collationStrength collation strength
615 * @param decompositionMode
616 * @deprecated 2.4 use the default constructor instead
618 Collator::Collator(UCollationStrength, UNormalizationMode )
623 Collator::~Collator()
627 Collator::Collator(const Collator &other)
632 UBool Collator::operator==(const Collator& other) const
634 // Subclasses: Call this method and then add more specific checks.
635 return typeid(*this) == typeid(other);
638 UBool Collator::operator!=(const Collator& other) const
640 return (UBool)!(*this == other);
643 int32_t U_EXPORT2 Collator::getBound(const uint8_t *source,
644 int32_t sourceLength,
645 UColBoundMode boundType,
648 int32_t resultLength,
651 return ucol_getBound(source, sourceLength, boundType, noOfLevels, result, resultLength, &status);
655 Collator::setLocales(const Locale& /* requestedLocale */, const Locale& /* validLocale */, const Locale& /*actualLocale*/) {
658 UnicodeSet *Collator::getTailoredSet(UErrorCode &status) const
660 if(U_FAILURE(status)) {
663 // everything can be changed
664 return new UnicodeSet(0, 0x10FFFF);
667 // -------------------------------------
669 #if !UCONFIG_NO_SERVICE
670 URegistryKey U_EXPORT2
671 Collator::registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status)
673 if (U_SUCCESS(status)) {
674 // Set the collator locales while registering so that createInstance()
675 // need not guess whether the collator's locales are already set properly
676 // (as they are by the data loader).
677 toAdopt->setLocales(locale, locale, locale);
678 return getService()->registerInstance(toAdopt, locale, status);
683 // -------------------------------------
685 class CFactory : public LocaleKeyFactory {
687 CollatorFactory* _delegate;
691 CFactory(CollatorFactory* delegate, UErrorCode& status)
692 : LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
693 , _delegate(delegate)
696 if (U_SUCCESS(status)) {
698 _ids = new Hashtable(status);
700 const UnicodeString * idlist = _delegate->getSupportedIDs(count, status);
701 for (int i = 0; i < count; ++i) {
702 _ids->put(idlist[i], (void*)this, status);
703 if (U_FAILURE(status)) {
710 status = U_MEMORY_ALLOCATION_ERROR;
717 virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
720 virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
722 if (U_SUCCESS(status)) {
728 virtual UnicodeString&
729 getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
732 CFactory::~CFactory()
739 CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const
741 if (handlesKey(key, status)) {
742 const LocaleKey& lkey = (const LocaleKey&)key;
744 lkey.currentLocale(validLoc);
745 return _delegate->createCollator(validLoc);
751 CFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const
753 if ((_coverage & 0x1) == 0) {
754 UErrorCode status = U_ZERO_ERROR;
755 const Hashtable* ids = getSupportedIDs(status);
756 if (ids && (ids->get(id) != NULL)) {
758 LocaleUtility::initLocaleFromName(id, loc);
759 return _delegate->getDisplayName(loc, locale, result);
766 URegistryKey U_EXPORT2
767 Collator::registerFactory(CollatorFactory* toAdopt, UErrorCode& status)
769 if (U_SUCCESS(status)) {
770 CFactory* f = new CFactory(toAdopt, status);
772 return getService()->registerFactory(f, status);
774 status = U_MEMORY_ALLOCATION_ERROR;
779 // -------------------------------------
782 Collator::unregister(URegistryKey key, UErrorCode& status)
784 if (U_SUCCESS(status)) {
786 return gService->unregister(key, status);
788 status = U_ILLEGAL_ARGUMENT_ERROR;
792 #endif /* UCONFIG_NO_SERVICE */
794 class CollationLocaleListEnumeration : public StringEnumeration {
798 static UClassID U_EXPORT2 getStaticClassID(void);
799 virtual UClassID getDynamicClassID(void) const;
801 CollationLocaleListEnumeration()
804 // The global variables should already be initialized.
805 //isAvailableLocaleListInitialized(status);
808 virtual ~CollationLocaleListEnumeration();
810 virtual StringEnumeration * clone() const
812 CollationLocaleListEnumeration *result = new CollationLocaleListEnumeration();
814 result->index = index;
819 virtual int32_t count(UErrorCode &/*status*/) const {
820 return availableLocaleListCount;
823 virtual const char* next(int32_t* resultLength, UErrorCode& /*status*/) {
825 if(index < availableLocaleListCount) {
826 result = availableLocaleList[index++].getName();
827 if(resultLength != NULL) {
828 *resultLength = (int32_t)uprv_strlen(result);
831 if(resultLength != NULL) {
839 virtual const UnicodeString* snext(UErrorCode& status) {
840 int32_t resultLength = 0;
841 const char *s = next(&resultLength, status);
842 return setChars(s, resultLength, status);
845 virtual void reset(UErrorCode& /*status*/) {
850 CollationLocaleListEnumeration::~CollationLocaleListEnumeration() {}
852 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollationLocaleListEnumeration)
855 // -------------------------------------
857 StringEnumeration* U_EXPORT2
858 Collator::getAvailableLocales(void)
860 #if !UCONFIG_NO_SERVICE
862 return getService()->getAvailableLocales();
864 #endif /* UCONFIG_NO_SERVICE */
865 UErrorCode status = U_ZERO_ERROR;
866 if (isAvailableLocaleListInitialized(status)) {
867 return new CollationLocaleListEnumeration();
872 StringEnumeration* U_EXPORT2
873 Collator::getKeywords(UErrorCode& status) {
874 return UStringEnumeration::fromUEnumeration(
875 ucol_getKeywords(&status), status);
878 StringEnumeration* U_EXPORT2
879 Collator::getKeywordValues(const char *keyword, UErrorCode& status) {
880 return UStringEnumeration::fromUEnumeration(
881 ucol_getKeywordValues(keyword, &status), status);
884 StringEnumeration* U_EXPORT2
885 Collator::getKeywordValuesForLocale(const char* key, const Locale& locale,
886 UBool commonlyUsed, UErrorCode& status) {
887 return UStringEnumeration::fromUEnumeration(
888 ucol_getKeywordValuesForLocale(
889 key, locale.getName(), commonlyUsed, &status),
894 Collator::getFunctionalEquivalent(const char* keyword, const Locale& locale,
895 UBool& isAvailable, UErrorCode& status) {
896 // This is a wrapper over ucol_getFunctionalEquivalent
897 char loc[ULOC_FULLNAME_CAPACITY];
898 /*int32_t len =*/ ucol_getFunctionalEquivalent(loc, sizeof(loc),
899 keyword, locale.getName(), &isAvailable, &status);
900 if (U_FAILURE(status)) {
903 return Locale::createFromName(loc);
906 Collator::ECollationStrength
907 Collator::getStrength(void) const {
908 UErrorCode intStatus = U_ZERO_ERROR;
909 return (ECollationStrength)getAttribute(UCOL_STRENGTH, intStatus);
913 Collator::setStrength(ECollationStrength newStrength) {
914 UErrorCode intStatus = U_ZERO_ERROR;
915 setAttribute(UCOL_STRENGTH, (UColAttributeValue)newStrength, intStatus);
919 Collator::setMaxVariable(UColReorderCode /*group*/, UErrorCode &errorCode) {
920 if (U_SUCCESS(errorCode)) {
921 errorCode = U_UNSUPPORTED_ERROR;
927 Collator::getMaxVariable() const {
928 return UCOL_REORDER_CODE_PUNCTUATION;
932 Collator::getReorderCodes(int32_t* /* dest*/,
933 int32_t /* destCapacity*/,
934 UErrorCode& status) const
936 if (U_SUCCESS(status)) {
937 status = U_UNSUPPORTED_ERROR;
943 Collator::setReorderCodes(const int32_t* /* reorderCodes */,
944 int32_t /* reorderCodesLength */,
947 if (U_SUCCESS(status)) {
948 status = U_UNSUPPORTED_ERROR;
953 Collator::getEquivalentReorderCodes(int32_t reorderCode,
954 int32_t *dest, int32_t capacity,
955 UErrorCode &errorCode) {
956 if(U_FAILURE(errorCode)) { return 0; }
957 if(capacity < 0 || (dest == NULL && capacity > 0)) {
958 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
961 const CollationData *baseData = CollationRoot::getData(errorCode);
962 if(U_FAILURE(errorCode)) { return 0; }
963 return baseData->getEquivalentScripts(reorderCode, dest, capacity, errorCode);
967 Collator::internalGetShortDefinitionString(const char * /*locale*/,
969 int32_t /*capacity*/,
970 UErrorCode &status) const {
971 if(U_SUCCESS(status)) {
972 status = U_UNSUPPORTED_ERROR; /* Shouldn't happen, internal function */
978 Collator::internalCompareUTF8(const char *left, int32_t leftLength,
979 const char *right, int32_t rightLength,
980 UErrorCode &errorCode) const {
981 if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
982 if((left == NULL && leftLength != 0) || (right == NULL && rightLength != 0)) {
983 errorCode = U_ILLEGAL_ARGUMENT_ERROR;
987 StringPiece(left, (leftLength < 0) ? uprv_strlen(left) : leftLength),
988 StringPiece(right, (rightLength < 0) ? uprv_strlen(right) : rightLength),
993 Collator::internalNextSortKeyPart(UCharIterator * /*iter*/, uint32_t /*state*/[2],
994 uint8_t * /*dest*/, int32_t /*count*/, UErrorCode &errorCode) const {
995 if (U_SUCCESS(errorCode)) {
996 errorCode = U_UNSUPPORTED_ERROR;
1001 // UCollator private data members ----------------------------------------
1003 /* This is useless information */
1004 /*const UVersionInfo Collator::fVersion = {1, 1, 0, 0};*/
1006 // -------------------------------------
1010 #endif /* #if !UCONFIG_NO_COLLATION */