ICU-3549 add getKeywords, getKeywordValues, and getFunctionalEquivalent

X-SVN-Rev: 15041
This commit is contained in:
Alan Liu 2004-04-24 02:57:18 +00:00
parent fae4de96cb
commit a22e089d93
2 changed files with 80 additions and 0 deletions

View file

@ -43,9 +43,11 @@
#include "unicode/coll.h"
#include "unicode/tblcoll.h"
#include "ucol_imp.h"
#include "cmemory.h"
#include "mutex.h"
#include "iculserv.h"
#include "ustrenum.h"
#include "ucln_in.h"
U_NAMESPACE_BEGIN
@ -79,6 +81,9 @@ CollatorFactory::getDisplayName(const Locale& objectLocale,
// -------------------------------------
class ICUCollatorFactory : public ICUResourceBundleFactory {
public:
ICUCollatorFactory(): ICUResourceBundleFactory(UnicodeString(U_ICUDATA_COLL, (char*)NULL)) { }
protected:
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
};
@ -597,6 +602,41 @@ Collator::getAvailableLocales(void)
return getService()->getAvailableLocales();
}
StringEnumeration*
Collator::getKeywords(UErrorCode& status) {
// This is a wrapper over ucol_getKeywords
UEnumeration* uenum = ucol_getKeywords(&status);
if (U_FAILURE(status)) {
uenum_close(uenum);
return NULL;
}
return new UStringEnumeration(uenum);
}
StringEnumeration*
Collator::getKeywordValues(const char *keyword, UErrorCode& status) {
// This is a wrapper over ucol_getKeywordValues
UEnumeration* uenum = ucol_getKeywordValues(keyword, &status);
if (U_FAILURE(status)) {
uenum_close(uenum);
return NULL;
}
return new UStringEnumeration(uenum);
}
Locale
Collator::getFunctionalEquivalent(const Locale& locale, UBool& isAvailable,
UErrorCode& status) {
// This is a wrapper over ucol_getFunctionalEquivalent
char loc[ULOC_FULLNAME_CAPACITY];
int32_t len = ucol_getFunctionalEquivalent(loc, sizeof(loc),
locale.getName(), &isAvailable, &status);
if (U_FAILURE(status)) {
*loc = 0; // root
}
return Locale::createFromName(loc);
}
// UCollator private data members ----------------------------------------
/* This is useless information */

View file

@ -612,6 +612,46 @@ public:
*/
static StringEnumeration* getAvailableLocales(void);
/**
* Create a string enumerator of all keywords that are relevant to
* collation. At this point, the only recognized keyword for this
* service is "collation".
* @param status input-output error code
* @return a string enumeration over locale strings. The caller is
* responsible for closing the result.
* @draft ICU 3.0
*/
static StringEnumeration* getKeywords(UErrorCode& status);
/**
* Given a keyword, create a string enumeration of all possible values
* for that keyword.
* @param keyword a particular keyword as enumerated by
* ucol_getKeywords. If any other keyword is passed in, status is set
* to U_ILLEGAL_ARGUMENT_ERROR.
* @param status input-output error code
* @return a string enumeration over collation keyword values, or NULL
* upon error. The caller is responsible for deleting the result.
* @draft ICU 3.0
*/
static StringEnumeration* getKeywordValues(const char *keyword, UErrorCode& status);
/**
* Return a functionally equivalent collation locale for the given
* requested locale.
* @param locale the requested locale
* @param isAvailable reference to a fillin parameter that
* indicates whether the requested locale was 'available' to the
* collation service. A locale is defined as 'available' if it
* physically exists within the collation locale data.
* @param status reference to input-output error code
* @return the functionally equivalent collation locale, or the root
* locale upon error.
* @draft ICU 3.0
*/
static Locale getFunctionalEquivalent(const Locale& locale, UBool& isAvailable,
UErrorCode& status);
/**
* Register a new Collator. The collator will be adopted.
* @param toAdopt the Collator instance to be adopted