ICU-3837 Add UCONFIG_NO_SERVICE

X-SVN-Rev: 16033
This commit is contained in:
George Rhoten 2004-07-18 01:18:23 +00:00
parent 5ea493c577
commit 8967f503cc
3 changed files with 51 additions and 40 deletions

View File

@ -319,6 +319,7 @@ BreakIterator::~BreakIterator()
// Registration
//
//-------------------------------------------
#if !UCONFIG_NO_SERVICE
static ICULocaleService* gService = NULL;
@ -393,39 +394,6 @@ hasService(void)
// -------------------------------------
BreakIterator*
BreakIterator::createInstance(const Locale& loc, UBreakIteratorType kind, UErrorCode& status)
{
if (U_FAILURE(status)) {
return NULL;
}
u_init(&status);
if (hasService()) {
Locale actualLoc;
BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &actualLoc, status);
// TODO: The way the service code works in ICU 2.8 is that if
// there is a real registered break iterator, the actualLoc
// will be populated, but if the handleDefault path is taken
// (because nothing is registered that can handle the
// requested locale) then the actualLoc comes back empty. In
// that case, the returned object already has its actual/valid
// locale data populated (by makeInstance, which is what
// handleDefault calls), so we don't touch it. YES, A COMMENT
// THIS LONG is a sign of bad code -- so the action item is to
// revisit this in ICU 3.0 and clean it up/fix it/remove it.
if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) {
U_LOCALE_BASED(locBased, *result);
locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName());
}
return result;
} else {
return makeInstance(loc, kind, status);
}
}
// -------------------------------------
URegistryKey
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
{
@ -453,6 +421,44 @@ BreakIterator::getAvailableLocales(void)
{
return getService()->getAvailableLocales();
}
#endif /* UCONFIG_NO_SERVICE */
// -------------------------------------
BreakIterator*
BreakIterator::createInstance(const Locale& loc, UBreakIteratorType kind, UErrorCode& status)
{
if (U_FAILURE(status)) {
return NULL;
}
u_init(&status);
#if !UCONFIG_NO_SERVICE
if (hasService()) {
Locale actualLoc;
BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &actualLoc, status);
// TODO: The way the service code works in ICU 2.8 is that if
// there is a real registered break iterator, the actualLoc
// will be populated, but if the handleDefault path is taken
// (because nothing is registered that can handle the
// requested locale) then the actualLoc comes back empty. In
// that case, the returned object already has its actual/valid
// locale data populated (by makeInstance, which is what
// handleDefault calls), so we don't touch it. YES, A COMMENT
// THIS LONG is a sign of bad code -- so the action item is to
// revisit this in ICU 3.0 and clean it up/fix it/remove it.
if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) {
U_LOCALE_BASED(locBased, *result);
locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName());
}
return result;
}
else
#endif
{
return makeInstance(loc, kind, status);
}
}
// -------------------------------------
@ -519,10 +525,12 @@ U_NAMESPACE_END
* Release all static memory held by breakiterator.
*/
U_CFUNC UBool breakiterator_cleanup(void) {
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
gService = NULL;
}
#endif
return TRUE;
}

View File

@ -45,11 +45,13 @@ U_NAMESPACE_END
U_NAMESPACE_BEGIN
#if !UCONFIG_NO_SERVICE
/**
* Opaque type returned by registerInstance.
* @stable
*/
typedef const void* URegistryKey;
#endif
/**
* The BreakIterator class implements methods for finding the location
@ -473,7 +475,8 @@ public:
/**
* Get the set of Locales for which TextBoundaries are installed.
* <p><b>Note:</b> this will not return locales added through the register
* call.</p>
* call. To see the registered locales too, use the getAvailableLocales
* function that returns a StringEnumeration object </p>
* @param count the output parameter of number of elements in the locale list
* @return available locales
* @stable ICU 2.0
@ -533,6 +536,7 @@ public:
*/
inline UBool isBufferClone(void);
#if !UCONFIG_NO_SERVICE
/**
* Register a new break iterator of the indicated kind, to use in the given locale.
* The break iterator will be adopted. Clones of the iterator will be returned
@ -565,6 +569,7 @@ public:
* @stable ICU 2.4
*/
static StringEnumeration* getAvailableLocales(void);
#endif
/**
* Returns the locale for this break iterator. Two flavors are available: valid and

View File

@ -161,13 +161,11 @@
/*
* \def UCONFIG_NO_SERVICE
* This switch turns off service registration.
* note: NOT implemented in ICU 3.0.
* note: Change this back to a .doc comment when this is implemented!
*
* @internal ICU 3.0
* @draft ICU 3.2
*/
/* #ifndef UCONFIG_NO_SERVICE */
/* # define UCONFIG_NO_SERVICE 0 */
/* #endif */
#ifndef UCONFIG_NO_SERVICE
# define UCONFIG_NO_SERVICE 0
#endif
#endif