ICU-2202 getLocale implementation for break iterator

X-SVN-Rev: 13780
This commit is contained in:
Vladimir Weinstein 2003-11-20 00:03:20 +00:00
parent 9f871e852f
commit 5fb5552a63
3 changed files with 59 additions and 16 deletions

View File

@ -400,7 +400,10 @@ BreakIterator::createInstance(const Locale& loc, UBreakIteratorType kind, UError
u_init(&status);
if (hasService()) {
return (BreakIterator*)gService->get(loc, kind, status);
Locale validLoc;
BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &validLoc, status);
uprv_strcpy(result->validLocale, validLoc.getName());
return result;
} else {
return makeInstance(loc, kind, status);
}
@ -441,18 +444,39 @@ BreakIterator::getAvailableLocales(void)
BreakIterator*
BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
{
BreakIterator *result = NULL;
switch (kind) {
case UBRK_CHARACTER: return BreakIterator::makeCharacterInstance(loc, status);
case UBRK_WORD: return BreakIterator::makeWordInstance(loc, status);
case UBRK_LINE: return BreakIterator::makeLineInstance(loc, status);
case UBRK_SENTENCE: return BreakIterator::makeSentenceInstance(loc, status);
case UBRK_TITLE: return BreakIterator::makeTitleInstance(loc, status);
case UBRK_CHARACTER:
result = BreakIterator::makeCharacterInstance(loc, status);
break;
case UBRK_WORD:
result = BreakIterator::makeWordInstance(loc, status);
break;
case UBRK_LINE:
result = BreakIterator::makeLineInstance(loc, status);
break;
case UBRK_SENTENCE:
result = BreakIterator::makeSentenceInstance(loc, status);
break;
case UBRK_TITLE:
result = BreakIterator::makeTitleInstance(loc, status);
break;
default:
if (U_SUCCESS(status)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
}
return NULL;
}
// this is more of a placeholder. All the break iterators have the same actual locale: root
// except the Thai one
ResourceBundle res(NULL, loc, status);
uprv_strcpy(result->validLocale, res.getLocale(ULOC_VALID_LOCALE, status).getName());
if(uprv_strcmp(loc.getLanguage(), "th") == 0) {
uprv_strcpy(result->actualLocale, "th");
} else {
uprv_strcpy(result->actualLocale, "root");
}
return result;
}
Locale
@ -460,17 +484,32 @@ BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const
{
switch(type) {
case ULOC_VALID_LOCALE:
#if 0
// TODO: need bufferClone problems fixed before this code can work.
return Locale(validLocale);
break;
case ULOC_ACTUAL_LOCALE:
return Locale(actualLocale);
break;
default:
status = U_UNSUPPORTED_ERROR;
return Locale("");
}
}
const char *
BreakIterator::getLocaleInternal(ULocDataLocaleType type, UErrorCode& status) const
{
switch(type) {
case ULOC_VALID_LOCALE:
// TODO: need bufferClone problems fixed before this code can work.
return validLocale;
break;
case ULOC_ACTUAL_LOCALE:
return actualLocale;
break;
#endif
default:
status = U_UNSUPPORTED_ERROR;
return Locale("");
return NULL;
}
}

View File

@ -270,7 +270,7 @@ ubrk_getLocaleByType(const UBreakIterator *bi,
ULocDataLocaleType type,
UErrorCode* status)
{
return (((BreakIterator *)bi)->getLocale(type, *status)).getName();
return ((BreakIterator *)bi)->getLocaleInternal(type, *status);
}

View File

@ -569,6 +569,13 @@ public:
*/
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
/** Get the locale for this break iterator object. You can choose between valid and actual locale.
* @param type type of the locale we're looking for (valid or actual)
* @param status error code for the operation
* @return the locale
* @internal
*/
virtual const char *getLocaleInternal(ULocDataLocaleType type, UErrorCode& status) const;
private:
static BreakIterator* makeCharacterInstance(const Locale& loc, UErrorCode& status);
static BreakIterator* makeWordInstance(const Locale& loc, UErrorCode& status);
@ -589,13 +596,10 @@ protected:
UBool fBufferClone;
/** @internal */
BreakIterator (const BreakIterator &other) : UObject(other), fBufferClone(FALSE) {}
/** @internal */
#if 0
// TODO: Can't do this, it breaks bufferClone, which does an object memcopy.
// Yuk.
Locale actualLocale;
Locale validLocale;
#endif
char actualLocale[50];
char validLocale[50];
private:
/**
* The assignment operator has no real implementation.