1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-01-18 00:23:29 +00:00
|
|
|
******************************************************************************
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (C) 1996-2003, International Business Machines Corporation and *
|
2001-01-18 00:23:29 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2001-01-30 18:52:58 +00:00
|
|
|
* File coll.cpp
|
|
|
|
*
|
|
|
|
* Created by: Helena Shih
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 2/5/97 aliu Modified createDefault to load collation data from
|
|
|
|
* binary files when possible. Added related methods
|
|
|
|
* createCollationFromFile, chopLocale, createPathName.
|
|
|
|
* 2/11/97 aliu Added methods addToCache, findInCache, which implement
|
|
|
|
* a Collation cache. Modified createDefault to look in
|
|
|
|
* cache first, and also to store newly created Collation
|
|
|
|
* objects in the cache. Modified to not use gLocPath.
|
|
|
|
* 2/12/97 aliu Modified to create objects from RuleBasedCollator cache.
|
|
|
|
* Moved cache out of Collation class.
|
|
|
|
* 2/13/97 aliu Moved several methods out of this class and into
|
|
|
|
* RuleBasedCollator, with modifications. Modified
|
|
|
|
* createDefault() to call new RuleBasedCollator(Locale&)
|
|
|
|
* constructor. General clean up and documentation.
|
|
|
|
* 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
|
|
|
|
* constructor.
|
|
|
|
* 05/06/97 helena Added memory allocation error detection.
|
|
|
|
* 05/08/97 helena Added createInstance().
|
|
|
|
* 6/20/97 helena Java class name change.
|
|
|
|
* 04/23/99 stephen Removed EDecompositionMode, merged with
|
|
|
|
* Normalizer::EMode
|
|
|
|
* 11/23/9 srl Inlining of some critical functions
|
|
|
|
* 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
#include "unicode/coll.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/tblcoll.h"
|
2000-06-03 04:37:12 +00:00
|
|
|
#include "cmemory.h"
|
2003-04-28 21:13:14 +00:00
|
|
|
#include "mutex.h"
|
|
|
|
#include "iculserv.h"
|
2003-05-13 23:12:37 +00:00
|
|
|
#include "ucln_in.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
2001-02-14 17:48:23 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
//
|
|
|
|
// Registration
|
|
|
|
//
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
|
|
|
|
UBool
|
|
|
|
CollatorFactory::visible(void) const {
|
2003-08-29 18:03:00 +00:00
|
|
|
return TRUE;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
CollatorFactory::getDisplayName(const Locale& objectLocale,
|
|
|
|
const Locale& displayLocale,
|
|
|
|
UnicodeString& result)
|
|
|
|
{
|
|
|
|
return objectLocale.getDisplayName(displayLocale, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
class ICUCollatorFactory : public ICUResourceBundleFactory {
|
2003-08-29 18:03:00 +00:00
|
|
|
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
|
2003-04-28 21:13:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UObject*
|
2003-05-19 17:04:05 +00:00
|
|
|
ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const {
|
2003-04-28 21:13:14 +00:00
|
|
|
if (handlesKey(key, status)) {
|
|
|
|
const LocaleKey& lkey = (const LocaleKey&)key;
|
|
|
|
Locale loc;
|
|
|
|
// make sure the requested locale is correct
|
|
|
|
// default LocaleFactory uses currentLocale since that's the one vetted by handlesKey
|
|
|
|
// but for ICU rb resources we use the actual one since it will fallback again
|
|
|
|
lkey.canonicalLocale(loc);
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
return Collator::makeInstance(loc, status);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
class ICUCollatorService : public ICULocaleService {
|
2003-08-29 18:03:00 +00:00
|
|
|
public:
|
2003-04-28 21:13:14 +00:00
|
|
|
ICUCollatorService()
|
|
|
|
: ICULocaleService("Collator")
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
registerFactory(new ICUCollatorFactory(), status);
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual UObject* cloneInstance(UObject* instance) const {
|
|
|
|
return ((Collator*)instance)->clone();
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const {
|
|
|
|
LocaleKey& lkey = (LocaleKey&)key;
|
2003-08-29 18:03:00 +00:00
|
|
|
if (actualID) {
|
|
|
|
lkey.canonicalID(*actualID);
|
|
|
|
}
|
2003-04-28 21:13:14 +00:00
|
|
|
Locale loc;
|
|
|
|
lkey.canonicalLocale(loc);
|
|
|
|
return Collator::makeInstance(loc, status);
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
if (result) {
|
|
|
|
const LocaleKey& lkey = (const LocaleKey&)key;
|
|
|
|
Locale canonicalLocale;
|
|
|
|
Locale currentLocale;
|
|
|
|
|
|
|
|
result->setLocales(lkey.canonicalLocale(canonicalLocale),
|
|
|
|
LocaleUtility::initLocaleFromName(*actualReturn, currentLocale));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2003-05-02 22:17:14 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual UBool isDefault() const {
|
|
|
|
return countFactories() == 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
class ICUCollatorService;
|
|
|
|
|
|
|
|
static ICULocaleService* gService = NULL;
|
|
|
|
|
|
|
|
static ICULocaleService*
|
|
|
|
getService(void)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UBool needInit;
|
|
|
|
{
|
|
|
|
Mutex mutex;
|
|
|
|
needInit = (UBool)(gService == NULL);
|
2003-05-13 23:12:37 +00:00
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
if(needInit) {
|
|
|
|
ICULocaleService *newservice = new ICUCollatorService();
|
|
|
|
if(newservice) {
|
|
|
|
Mutex mutex;
|
|
|
|
if(gService == NULL) {
|
|
|
|
gService = newservice;
|
|
|
|
newservice = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(newservice) {
|
|
|
|
delete newservice;
|
|
|
|
} else {
|
|
|
|
ucln_i18n_registerCleanup();
|
|
|
|
}
|
2003-06-06 22:01:28 +00:00
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
return gService;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
static UBool
|
|
|
|
hasService(void)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
Mutex mutex;
|
|
|
|
return gService != NULL;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 17:31:45 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
UCollator*
|
|
|
|
Collator::createUCollator(const char *loc,
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode *status)
|
2003-05-08 17:31:45 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
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;
|
2003-05-08 17:31:45 +00:00
|
|
|
}
|
2003-04-28 21:13:14 +00:00
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
// Collator public methods -----------------------------------------------
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
Collator* Collator::createInstance(UErrorCode& success)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
if (U_FAILURE(success))
|
|
|
|
return 0;
|
|
|
|
return createInstance(Locale::getDefault(), success);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
Collator* Collator::createInstance(const Locale& desiredLocale,
|
|
|
|
UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hasService()) {
|
|
|
|
return (Collator*)gService->get(desiredLocale, status);
|
|
|
|
}
|
|
|
|
return makeInstance(desiredLocale, status);
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Collator* Collator::makeInstance(const Locale& desiredLocale,
|
|
|
|
UErrorCode& status)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
// A bit of explanation is required here. Although in the current
|
|
|
|
// implementation
|
|
|
|
// Collator::createInstance() is just turning around and calling
|
|
|
|
// RuleBasedCollator(Locale&), this will not necessarily always be the
|
|
|
|
// case. For example, suppose we modify this code to handle a
|
|
|
|
// non-table-based Collator, such as that for Thai. In this case,
|
|
|
|
// createInstance() will have to be modified to somehow determine this fact
|
|
|
|
// (perhaps a field in the resource bundle). Then it can construct the
|
|
|
|
// non-table-based Collator in some other way, when it sees that it needs
|
|
|
|
// to.
|
|
|
|
// The specific caution is this: RuleBasedCollator(Locale&) will ALWAYS
|
|
|
|
// return a valid collation object, if the system if functioning properly.
|
|
|
|
// The reason is that it will fall back, use the default locale, and even
|
|
|
|
// use the built-in default collation rules. THEREFORE, createInstance()
|
|
|
|
// should in general ONLY CALL RuleBasedCollator(Locale&) IF IT KNOWS IN
|
|
|
|
// ADVANCE that the given locale's collation is properly implemented as a
|
|
|
|
// RuleBasedCollator.
|
|
|
|
// Currently, we don't do this...we always return a RuleBasedCollator,
|
|
|
|
// whether it is strictly correct to do so or not, without checking, because
|
|
|
|
// we currently have no way of checking.
|
|
|
|
|
|
|
|
RuleBasedCollator* collation = new RuleBasedCollator(desiredLocale,
|
|
|
|
status);
|
|
|
|
/* test for NULL */
|
|
|
|
if (collation == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
delete collation;
|
|
|
|
collation = 0;
|
|
|
|
}
|
|
|
|
return collation;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// !!! dlf the following is obsolete, ignore registration for this
|
|
|
|
|
2001-03-14 00:23:47 +00:00
|
|
|
Collator *
|
|
|
|
Collator::createInstance(const Locale &loc,
|
|
|
|
UVersionInfo version,
|
2003-08-29 18:03:00 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-03-14 00:23:47 +00:00
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
return collator;
|
2001-03-14 00:23:47 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 23:23:52 +00:00
|
|
|
// implement deprecated, previously abstract method
|
|
|
|
Collator::EComparisonResult Collator::compare(const UnicodeString& source,
|
|
|
|
const UnicodeString& target) const
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (Collator::EComparisonResult)compare(source, target, ec);
|
2003-05-01 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// implement deprecated, previously abstract method
|
|
|
|
Collator::EComparisonResult Collator::compare(const UnicodeString& source,
|
|
|
|
const UnicodeString& target,
|
|
|
|
int32_t length) const
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (Collator::EComparisonResult)compare(source, target, length, ec);
|
2003-05-01 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// implement deprecated, previously abstract method
|
|
|
|
Collator::EComparisonResult Collator::compare(const UChar* source, int32_t sourceLength,
|
|
|
|
const UChar* target, int32_t targetLength)
|
|
|
|
const
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (Collator::EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
|
2003-05-01 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
UBool Collator::equals(const UnicodeString& source,
|
2003-08-29 18:03:00 +00:00
|
|
|
const UnicodeString& target) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (compare(source, target, ec) == UCOL_EQUAL);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
UBool Collator::greaterOrEqual(const UnicodeString& source,
|
2003-08-29 18:03:00 +00:00
|
|
|
const UnicodeString& target) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (compare(source, target, ec) != UCOL_LESS);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
UBool Collator::greater(const UnicodeString& source,
|
2003-08-29 18:03:00 +00:00
|
|
|
const UnicodeString& target) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
return (compare(source, target, ec) == UCOL_GREATER);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// this API ignores registered collators, since it returns an
|
|
|
|
// array of indefinite lifetime
|
2001-01-18 00:23:29 +00:00
|
|
|
const Locale* Collator::getAvailableLocales(int32_t& count)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
return Locale::getAvailableLocales(count);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
UnicodeString& Collator::getDisplayName(const Locale& objectLocale,
|
2003-08-29 18:03:00 +00:00
|
|
|
const Locale& displayLocale,
|
|
|
|
UnicodeString& name)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
if (hasService()) {
|
|
|
|
return gService->getDisplayName(objectLocale.getName(), name, displayLocale);
|
|
|
|
}
|
|
|
|
return objectLocale.getDisplayName(displayLocale, name);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
UnicodeString& Collator::getDisplayName(const Locale& objectLocale,
|
2003-08-29 18:03:00 +00:00
|
|
|
UnicodeString& name)
|
2001-01-18 00:23:29 +00:00
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
return getDisplayName(objectLocale, Locale::getDefault(), name);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-02-28 20:01:48 +00:00
|
|
|
/* This is useless information */
|
|
|
|
/*void Collator::getVersion(UVersionInfo versionInfo) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
if (versionInfo!=NULL)
|
|
|
|
uprv_memcpy(versionInfo, fVersion, U_MAX_VERSION_LENGTH);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-02-28 20:01:48 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
// UCollator protected constructor destructor ----------------------------
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
* Constructor is different from the old default Collator constructor.
|
|
|
|
* The task for determing the default collation strength and normalization mode
|
|
|
|
* is left to the child class.
|
|
|
|
*/
|
|
|
|
Collator::Collator()
|
2003-08-29 18:03:00 +00:00
|
|
|
: UObject()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* Empty constructor, does not handle the arguments.
|
|
|
|
* This constructor is done for backward compatibility with 1.7 and 1.8.
|
|
|
|
* The task for handling the argument collation strength and normalization
|
|
|
|
* mode is left to the child class.
|
|
|
|
* @param collationStrength collation strength
|
2002-11-21 22:52:46 +00:00
|
|
|
* @param decompositionMode
|
|
|
|
* @deprecated 2.4 use the default constructor instead
|
2001-01-18 00:23:29 +00:00
|
|
|
*/
|
2002-11-21 22:52:46 +00:00
|
|
|
Collator::Collator(UCollationStrength, UNormalizationMode )
|
2003-08-29 18:03:00 +00:00
|
|
|
: UObject()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
Collator::~Collator()
|
|
|
|
{
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-07-02 23:58:34 +00:00
|
|
|
Collator::Collator(const Collator &other)
|
|
|
|
: UObject(other)
|
2000-06-03 04:18:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-08-29 18:03:00 +00:00
|
|
|
UBool Collator::operator==(const Collator& other) const
|
|
|
|
{
|
|
|
|
return (UBool)(this == &other);
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool Collator::operator!=(const Collator& other) const
|
|
|
|
{
|
|
|
|
return (UBool)!(*this == other);
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:08 +00:00
|
|
|
int32_t Collator::getBound(const uint8_t *source,
|
2003-08-29 18:03:00 +00:00
|
|
|
int32_t sourceLength,
|
|
|
|
UColBoundMode boundType,
|
|
|
|
uint32_t noOfLevels,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode &status)
|
|
|
|
{
|
|
|
|
return ucol_getBound(source, sourceLength, boundType, noOfLevels, result, resultLength, &status);
|
2002-03-21 21:21:08 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
void
|
2003-05-19 17:04:05 +00:00
|
|
|
Collator::setLocales(const Locale& /* requestedLocale */, const Locale& /* validLocale */) {
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2003-08-29 18:03:00 +00:00
|
|
|
UnicodeSet *Collator::getTailoredSet(UErrorCode &status) const
|
|
|
|
{
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// everything can be changed
|
|
|
|
return new UnicodeSet(0, 0x10FFFF);
|
|
|
|
}
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
URegistryKey
|
|
|
|
Collator::registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status)
|
|
|
|
{
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return getService()->registerInstance(toAdopt, locale, status);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
class CFactory : public LocaleKeyFactory {
|
|
|
|
private:
|
|
|
|
CollatorFactory* _delegate;
|
|
|
|
Hashtable* _ids;
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
public:
|
2003-05-08 22:21:05 +00:00
|
|
|
CFactory(CollatorFactory* delegate, UErrorCode& status)
|
2003-04-28 21:13:14 +00:00
|
|
|
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
|
|
|
|
, _delegate(delegate)
|
|
|
|
, _ids(NULL)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
int32_t count = 0;
|
|
|
|
_ids = new Hashtable(status);
|
|
|
|
if (_ids) {
|
|
|
|
const UnicodeString * idlist = _delegate->getSupportedIDs(count, status);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
_ids->put(idlist[i], (void*)this, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
delete _ids;
|
|
|
|
_ids = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual ~CFactory()
|
|
|
|
{
|
|
|
|
delete _delegate;
|
|
|
|
delete _ids;
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
|
2003-08-29 18:03:00 +00:00
|
|
|
|
|
|
|
protected:
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
|
|
|
|
{
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
return _ids;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
virtual UnicodeString&
|
|
|
|
getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
UObject*
|
2003-05-19 17:04:05 +00:00
|
|
|
CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const
|
2003-04-28 21:13:14 +00:00
|
|
|
{
|
|
|
|
if (handlesKey(key, status)) {
|
|
|
|
const LocaleKey& lkey = (const LocaleKey&)key;
|
|
|
|
Locale validLoc;
|
|
|
|
lkey.currentLocale(validLoc);
|
2003-08-29 18:03:00 +00:00
|
|
|
return _delegate->createCollator(validLoc);
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
CFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const
|
|
|
|
{
|
|
|
|
if ((_coverage & 0x1) == 0) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const Hashtable* ids = getSupportedIDs(status);
|
|
|
|
if (ids && (ids->get(id) != NULL)) {
|
|
|
|
Locale loc;
|
|
|
|
LocaleUtility::initLocaleFromName(id, loc);
|
|
|
|
return _delegate->getDisplayName(loc, locale, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.setToBogus();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
URegistryKey
|
|
|
|
Collator::registerFactory(CollatorFactory* toAdopt, UErrorCode& status)
|
|
|
|
{
|
|
|
|
if (U_SUCCESS(status)) {
|
2003-05-08 22:21:05 +00:00
|
|
|
CFactory* f = new CFactory(toAdopt, status);
|
2003-04-28 21:13:14 +00:00
|
|
|
if (f) {
|
|
|
|
return getService()->registerFactory(f, status);
|
|
|
|
}
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
UBool
|
|
|
|
Collator::unregister(URegistryKey key, UErrorCode& status)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (hasService()) {
|
|
|
|
return gService->unregister(key, status);
|
|
|
|
}
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
2003-08-29 18:03:00 +00:00
|
|
|
return FALSE;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
StringEnumeration*
|
|
|
|
Collator::getAvailableLocales(void)
|
|
|
|
{
|
2003-08-29 18:03:00 +00:00
|
|
|
return getService()->getAvailableLocales();
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
2002-03-21 21:21:08 +00:00
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
// UCollator private data members ----------------------------------------
|
|
|
|
|
2002-02-28 20:01:48 +00:00
|
|
|
/* This is useless information */
|
|
|
|
/*const UVersionInfo Collator::fVersion = {1, 1, 0, 0};*/
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2003-04-28 21:13:14 +00:00
|
|
|
// defined in ucln_cmn.h
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all static memory held by collator.
|
|
|
|
*/
|
|
|
|
U_CFUNC UBool collator_cleanup(void) {
|
2003-08-29 18:03:00 +00:00
|
|
|
if (gService) {
|
|
|
|
delete gService;
|
|
|
|
gService = NULL;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-04-28 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
/* eof */
|