ICU-1949 StringEnumeration changes and some cleanup

X-SVN-Rev: 10341
This commit is contained in:
Doug Felt 2002-11-22 18:20:28 +00:00
parent 391ae83bc5
commit d6a9220d93
3 changed files with 79 additions and 29 deletions

View File

@ -369,6 +369,7 @@ LocaleKeyFactory::getSupportedIDs(UErrorCode& status) const {
return NULL;
}
#ifdef SERVICE_DEBUG
UnicodeString&
LocaleKeyFactory::debug(UnicodeString& result) const
{
@ -385,6 +386,7 @@ LocaleKeyFactory::debugClass(UnicodeString& result) const
{
return result.append("LocaleKeyFactory");
}
#endif
const char LocaleKeyFactory::fgClassID = 0;
@ -393,24 +395,12 @@ const char LocaleKeyFactory::fgClassID = 0;
*/
SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
const Locale& locale,
const UnicodeString& locale,
int32_t kind,
int32_t coverage)
: LocaleKeyFactory(coverage)
, _obj(objToAdopt)
, _id(locale.getName())
, _kind(kind)
{
}
SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
const Locale& locale,
int32_t kind,
int32_t coverage,
const UnicodeString& name)
: LocaleKeyFactory(coverage, name)
, _obj(objToAdopt)
, _id(locale.getName())
, _id(locale)
, _kind(kind)
{
}
@ -443,7 +433,8 @@ SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status)
}
}
UnicodeString&
#ifdef SERVICE_DEBUG
UnicodeString&
SimpleLocaleKeyFactory::debug(UnicodeString& result) const
{
LocaleKeyFactory::debug(result);
@ -459,6 +450,7 @@ SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
{
return result.append("SimpleLocaleKeyFactory");
}
#endif
const char SimpleLocaleKeyFactory::fgClassID = 0;
@ -496,6 +488,7 @@ ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t kind, const IC
return NULL;
}
#ifdef SERVICE_DEBUG
UnicodeString&
ICUResourceBundleFactory::debug(UnicodeString& result) const
{
@ -509,6 +502,7 @@ ICUResourceBundleFactory::debugClass(UnicodeString& result) const
{
return result.append("ICUResourceBundleFactory");
}
#endif
const char ICUResourceBundleFactory::fgClassID = '\0';
@ -597,6 +591,32 @@ ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, in
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status)
{
ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale.getName(), kind, coverage);
if (factory != NULL) {
return registerFactory(factory, status);
}
delete objToAdopt;
return NULL;
}
#if 0
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UErrorCode& status)
{
return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY, LocaleKeyFactory::VISIBLE, status);
}
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status)
{
return registerInstance(objToAdopt, locale, LocaleKey::KIND_ANY,
visible ? LocaleKeyFactory::VISIBLE : LocaleKeyFactory::INVISIBLE,
status);
}
URegistryKey
ICULocaleService::registerInstance(UObject* objToAdopt, const UnicodeString& locale, int32_t kind, int32_t coverage, UErrorCode& status)
{
ICUServiceFactory * factory = new SimpleLocaleKeyFactory(objToAdopt, locale, kind, coverage);
if (factory != NULL) {
@ -605,6 +625,7 @@ ICULocaleService::registerInstance(UObject* objToAdopt, const Locale& locale, in
delete objToAdopt;
return NULL;
}
#endif
class ServiceEnumeration : public StringEnumeration {
private:
@ -646,7 +667,7 @@ public:
return upToDate(status) ? _ids.size() : 0;
}
const char* next(UErrorCode& status) {
const char* next(int32_t* resultLength, UErrorCode& status) {
const UnicodeString* us = snext(status);
if (us) {
while (TRUE) {
@ -656,6 +677,9 @@ public:
status = U_ZERO_ERROR;
} else if (U_SUCCESS(status)) {
((char*)_bufp)[newlen] = 0;
if (resultLength) {
resultLength[0] = newlen;
}
return (const char*)_bufp;
} else {
break;
@ -665,7 +689,7 @@ public:
return NULL;
}
const UChar* unext(UErrorCode& status) {
const UChar* unext(int32_t* resultLength, UErrorCode& status) {
const UnicodeString* us = snext(status);
if (us) {
while (TRUE) {
@ -674,6 +698,9 @@ public:
resizeBuffer((newlen + 1) * sizeof(UChar));
} else if (U_SUCCESS(status)) {
((UChar*)_bufp)[newlen] = 0;
if (resultLength) {
resultLength[0] = newlen;
}
return (const UChar*)_bufp;
} else {
break;

View File

@ -283,9 +283,11 @@ protected:
return (UClassID)&fgClassID;
}
#ifdef SERVICE_DEBUG
public:
virtual UnicodeString& debug(UnicodeString& result) const;
virtual UnicodeString& debugClass(UnicodeString& result) const;
#endif
private:
static const char fgClassID;
@ -307,16 +309,10 @@ class U_COMMON_API SimpleLocaleKeyFactory : public LocaleKeyFactory {
public:
SimpleLocaleKeyFactory(UObject* objToAdopt,
const Locale& locale,
const UnicodeString& locale,
int32_t kind,
int32_t coverage);
SimpleLocaleKeyFactory(UObject* objToAdopt,
const Locale& locale,
int32_t kind,
int32_t coverage,
const UnicodeString& name);
/**
* Override of superclass method. Returns the service object if kind/locale match. Service is not used.
*/
@ -340,9 +336,11 @@ class U_COMMON_API SimpleLocaleKeyFactory : public LocaleKeyFactory {
return (UClassID)&fgClassID;
}
#ifdef SERVICE_DEBUG
public:
virtual UnicodeString& debug(UnicodeString& result) const;
virtual UnicodeString& debugClass(UnicodeString& result) const;
#endif
private:
static const char fgClassID;
@ -400,9 +398,11 @@ protected:
return (UClassID)&fgClassID;
}
#ifdef SERVICE_DEBUG
public:
virtual UnicodeString& debug(UnicodeString& result) const;
virtual UnicodeString& debugClass(UnicodeString& result) const;
#endif
private:
static const char fgClassID;
@ -493,6 +493,29 @@ class U_COMMON_API ICULocaleService : public ICUService
*/
virtual URegistryKey registerInstance(UObject* objToAdopt, const Locale& locale, int32_t kind, int32_t coverage, UErrorCode& status);
#if 0
// Since both UnicodeString and Locale have constructors that take const char*, adding a public
// method that takes UnicodeString causes ambiguity at call sites that use const char*.
// We really need a flag that is understood by all compilers that will suppress the warning about
// hidden overrides.
/**
* (Stop compiler from complaining about hidden overrides.)
*/
URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& locale, UErrorCode& status);
/**
* (Stop compiler from complaining about hidden overrides.)
*/
URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& locale, UBool visible, UErrorCode& status);
/**
* Since the factory ultimately needs a UnicodeString, and we needed to add other overrides that take a
* UnicodeString as well, we'll vector all the overrides through this call.
*/
virtual URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& locale, int32_t kind, int32_t coverage, UErrorCode& status);
#endif
/**
* Convenience method for callers using locales. This returns the standard
* service ID enumeration.

View File

@ -30,7 +30,7 @@ class ICUNSubclass : public ICUNotifier {
// return l instanceof MyListener;
}
void notifyListener(const EventListener& l) const {
void notifyListener(EventListener& l) const {
}
};
@ -42,7 +42,7 @@ class LKFSubclass : public LocaleKeyFactory {
}
protected:
const Hashtable* getSupportedIDs(void) const {
const Hashtable* getSupportedIDs(UErrorCode& status) const {
// return Collections.EMPTY_SET;
return NULL;
}
@ -103,9 +103,9 @@ class TestIntegerService : public ICUService {
return LocaleKey::createWithCanonicalFallback(id, NULL, status); // no fallback locale
}
virtual ICUServiceFactory* createSimpleFactory(UObject* obj, const UnicodeString& id, UBool visible)
virtual ICUServiceFactory* createSimpleFactory(UObject* obj, const UnicodeString& id, UBool visible, UErrorCode& status)
{
if (obj && obj->getDynamicClassID() == Integer::getStaticClassID()) {
if (U_SUCCESS(status) && obj && obj->getDynamicClassID() == Integer::getStaticClassID()) {
return new SimpleFactory((Integer*)obj, id, visible);
}
return NULL;
@ -1150,7 +1150,7 @@ void ICUServiceTest::testLocale() {
logln("locales: ");
{
const char* p;
while (p = locales->next(status)) {
while (p = locales->next(NULL, status)) {
logln(p);
}
}