1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
2004-05-18 22:01:41 +00:00
|
|
|
* Copyright (C) 1997-2004, International Business Machines Corporation and *
|
1999-11-22 20:25:35 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File TXTBDRY.CPP
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/18/97 aliu Converted from OpenClass. Added DONE.
|
2000-01-14 00:13:59 +00:00
|
|
|
* 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods.
|
1999-08-16 21:50:52 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// This file was generated from the java source file BreakIterator.java
|
|
|
|
// *****************************************************************************
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
|
2000-01-10 21:21:52 +00:00
|
|
|
#include "unicode/dbbi.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/brkiter.h"
|
2000-01-08 02:05:05 +00:00
|
|
|
#include "unicode/udata.h"
|
2004-09-03 15:17:54 +00:00
|
|
|
#include "unicode/ures.h"
|
2000-04-15 21:23:28 +00:00
|
|
|
#include "cstring.h"
|
2002-11-08 18:07:48 +00:00
|
|
|
#include "mutex.h"
|
|
|
|
#include "iculserv.h"
|
2004-01-20 23:06:38 +00:00
|
|
|
#include "locbased.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// class BreakIterator
|
2002-08-01 16:17:41 +00:00
|
|
|
// This class implements methods for finding the location of boundaries in text.
|
1999-08-16 21:50:52 +00:00
|
|
|
// Instances of BreakIterator maintain a current position and scan over text
|
|
|
|
// returning the index of characters where boundaries occur.
|
|
|
|
// *****************************************************************************
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
const int32_t BreakIterator::DONE = (int32_t)-1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// Creates a break iterator for word breaks.
|
2004-08-24 17:21:14 +00:00
|
|
|
BreakIterator* U_EXPORT2
|
2000-01-14 00:13:59 +00:00
|
|
|
BreakIterator::createWordInstance(const Locale& key, UErrorCode& status)
|
2002-11-08 00:22:18 +00:00
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
return createInstance(key, UBRK_WORD, status);
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeWordInstance(const Locale& key, UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
// WARNING: This routine is currently written specifically to handle only the
|
|
|
|
// default rules files and the alternate rules files for Thai. This function
|
|
|
|
// will have to be made fully general at some time in the future!
|
|
|
|
BreakIterator* result = NULL;
|
|
|
|
const char* filename = "word";
|
|
|
|
|
2001-10-09 22:57:29 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
2002-08-08 00:39:13 +00:00
|
|
|
|
2000-04-15 21:23:28 +00:00
|
|
|
if (!uprv_strcmp(key.getLanguage(), "th"))
|
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
filename = "word_th";
|
|
|
|
}
|
|
|
|
|
2000-01-14 00:13:59 +00:00
|
|
|
UDataMemory* file = udata_open(NULL, "brk", filename, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// The UDataMemory is adopted by the break iterator.
|
2000-01-08 02:05:05 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
if(!uprv_strcmp(filename, "word_th")) {
|
|
|
|
filename = "thaidict.brk";
|
|
|
|
result = new DictionaryBasedBreakIterator(file, filename, status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
|
|
|
}
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
|
|
if (result != NULL) {
|
|
|
|
delete result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2003-09-09 23:51:17 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// Creates a break iterator for line breaks.
|
2004-08-24 17:21:14 +00:00
|
|
|
BreakIterator* U_EXPORT2
|
2000-01-14 00:13:59 +00:00
|
|
|
BreakIterator::createLineInstance(const Locale& key, UErrorCode& status)
|
2002-11-08 00:22:18 +00:00
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
return createInstance(key, UBRK_LINE, status);
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeLineInstance(const Locale& key, UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
// WARNING: This routine is currently written specifically to handle only the
|
|
|
|
// default rules files and the alternate rules files for Thai. This function
|
|
|
|
// will have to be made fully general at some time in the future!
|
|
|
|
BreakIterator* result = NULL;
|
|
|
|
const char* filename = "line";
|
|
|
|
|
2001-10-09 22:57:29 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
2002-08-08 00:39:13 +00:00
|
|
|
|
2000-04-15 21:23:28 +00:00
|
|
|
if (!uprv_strcmp(key.getLanguage(), "th"))
|
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
filename = "line_th";
|
|
|
|
}
|
|
|
|
|
2000-01-14 00:13:59 +00:00
|
|
|
UDataMemory* file = udata_open(NULL, "brk", filename, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
2000-01-08 02:05:05 +00:00
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
// The UDataMemory is adopted by the break iterator.
|
2000-06-26 22:46:15 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
if (!uprv_strcmp(key.getLanguage(), "th")) {
|
|
|
|
filename = "thaidict.brk";
|
|
|
|
result = new DictionaryBasedBreakIterator(file, filename, status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
|
|
|
}
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
|
|
if (result != NULL) {
|
|
|
|
delete result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2000-01-08 02:05:05 +00:00
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// Creates a break iterator for character breaks.
|
2004-08-24 17:21:14 +00:00
|
|
|
BreakIterator* U_EXPORT2
|
2002-11-08 00:22:18 +00:00
|
|
|
BreakIterator::createCharacterInstance(const Locale& key, UErrorCode& status)
|
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
return createInstance(key, UBRK_CHARACTER, status);
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeCharacterInstance(const Locale& /* key */, UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
// WARNING: This routine is currently written specifically to handle only the
|
|
|
|
// default rules files and the alternate rules files for Thai. This function
|
|
|
|
// will have to be made fully general at some time in the future!
|
|
|
|
BreakIterator* result = NULL;
|
2001-10-09 22:57:29 +00:00
|
|
|
static const char filename[] = "char";
|
2000-01-08 02:05:05 +00:00
|
|
|
|
2001-10-09 22:57:29 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
2000-01-14 00:13:59 +00:00
|
|
|
UDataMemory* file = udata_open(NULL, "brk", filename, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
2000-01-08 02:05:05 +00:00
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
// The UDataMemory is adopted by the break iterator.
|
2000-06-26 22:46:15 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
2003-09-09 23:51:17 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
|
|
if (result != NULL) {
|
|
|
|
delete result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2000-01-08 02:05:05 +00:00
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// Creates a break iterator for sentence breaks.
|
2004-08-24 17:21:14 +00:00
|
|
|
BreakIterator* U_EXPORT2
|
2002-11-08 00:22:18 +00:00
|
|
|
BreakIterator::createSentenceInstance(const Locale& key, UErrorCode& status)
|
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
return createInstance(key, UBRK_SENTENCE, status);
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeSentenceInstance(const Locale& /*key */, UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-01-08 02:05:05 +00:00
|
|
|
// WARNING: This routine is currently written specifically to handle only the
|
|
|
|
// default rules files and the alternate rules files for Thai. This function
|
|
|
|
// will have to be made fully general at some time in the future!
|
|
|
|
BreakIterator* result = NULL;
|
2001-10-09 22:57:29 +00:00
|
|
|
static const char filename[] = "sent";
|
2000-01-08 02:05:05 +00:00
|
|
|
|
2001-10-09 22:57:29 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
2000-01-14 00:13:59 +00:00
|
|
|
UDataMemory* file = udata_open(NULL, "brk", filename, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// The UDataMemory is adopted by the break iterator.
|
2000-01-08 02:05:05 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
|
|
if (result != NULL) {
|
|
|
|
delete result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2001-10-09 22:57:29 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// Creates a break iterator for title casing breaks.
|
2004-08-24 17:21:14 +00:00
|
|
|
BreakIterator* U_EXPORT2
|
2002-11-08 00:22:18 +00:00
|
|
|
BreakIterator::createTitleInstance(const Locale& key, UErrorCode& status)
|
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
return createInstance(key, UBRK_TITLE, status);
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeTitleInstance(const Locale& /* key */, UErrorCode& status)
|
2002-02-28 01:28:04 +00:00
|
|
|
{
|
|
|
|
// WARNING: This routine is currently written specifically to handle only the
|
2002-08-01 16:17:41 +00:00
|
|
|
// default rules files. This function will have to be made fully general
|
2002-02-28 01:28:04 +00:00
|
|
|
// at some time in the future!
|
|
|
|
BreakIterator* result = NULL;
|
|
|
|
static const char filename[] = "title";
|
|
|
|
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
|
|
|
UDataMemory* file = udata_open(NULL, "brk", filename, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// The UDataMemory is adopted by the break iterator.
|
2002-02-28 01:28:04 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
2003-09-09 23:51:17 +00:00
|
|
|
if (U_FAILURE(status)) { // Sometimes redundant check, but simple.
|
|
|
|
if (result != NULL) {
|
|
|
|
delete result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2002-02-28 01:28:04 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2002-11-08 00:22:18 +00:00
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// Gets all the available locales that has localized text boundary data.
|
2004-08-24 17:21:14 +00:00
|
|
|
const Locale* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator::getAvailableLocales(int32_t& count)
|
|
|
|
{
|
|
|
|
return Locale::getAvailableLocales(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Gets the objectLocale display name in the default locale language.
|
2004-08-24 17:21:14 +00:00
|
|
|
UnicodeString& U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator::getDisplayName(const Locale& objectLocale,
|
|
|
|
UnicodeString& name)
|
|
|
|
{
|
|
|
|
return objectLocale.getDisplayName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Gets the objectLocale display name in the displayLocale language.
|
2004-08-24 17:21:14 +00:00
|
|
|
UnicodeString& U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator::getDisplayName(const Locale& objectLocale,
|
|
|
|
const Locale& displayLocale,
|
|
|
|
UnicodeString& name)
|
|
|
|
{
|
|
|
|
return objectLocale.getDisplayName(displayLocale, name);
|
|
|
|
}
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
//
|
|
|
|
// Default constructor and destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------
|
2002-11-08 00:22:18 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator::BreakIterator()
|
|
|
|
{
|
2001-02-21 23:40:41 +00:00
|
|
|
fBufferClone = FALSE;
|
2004-01-20 23:06:38 +00:00
|
|
|
*validLocale = *actualLocale = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator::~BreakIterator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-08 00:22:18 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
//
|
|
|
|
// Registration
|
|
|
|
//
|
|
|
|
//-------------------------------------------
|
2004-07-18 01:18:23 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2002-11-08 00:22:18 +00:00
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
static ICULocaleService* gService = NULL;
|
2002-11-08 00:22:18 +00:00
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
// -------------------------------------
|
2002-11-08 00:22:18 +00:00
|
|
|
|
|
|
|
class ICUBreakIteratorFactory : public ICUResourceBundleFactory {
|
|
|
|
protected:
|
2004-01-14 18:03:50 +00:00
|
|
|
virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* /*service*/, UErrorCode& status) const {
|
|
|
|
return BreakIterator::makeInstance(loc, kind, status);
|
|
|
|
}
|
2002-11-08 00:22:18 +00:00
|
|
|
};
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
2002-11-08 00:22:18 +00:00
|
|
|
class ICUBreakIteratorService : public ICULocaleService {
|
|
|
|
public:
|
2004-01-14 18:03:50 +00:00
|
|
|
ICUBreakIteratorService()
|
2004-08-26 22:51:40 +00:00
|
|
|
: ICULocaleService(UNICODE_STRING("Break Iterator", 14))
|
2004-01-14 18:03:50 +00:00
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
registerFactory(new ICUBreakIteratorFactory(), status);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UObject* cloneInstance(UObject* instance) const {
|
|
|
|
return ((BreakIterator*)instance)->clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* /*actualID*/, UErrorCode& status) const {
|
|
|
|
LocaleKey& lkey = (LocaleKey&)key;
|
|
|
|
int32_t kind = lkey.kind();
|
|
|
|
Locale loc;
|
|
|
|
lkey.currentLocale(loc);
|
|
|
|
return BreakIterator::makeInstance(loc, kind, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UBool isDefault() const {
|
|
|
|
return countFactories() == 1;
|
|
|
|
}
|
2002-11-08 00:22:18 +00:00
|
|
|
};
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
static ICULocaleService*
|
|
|
|
getService(void)
|
2002-11-08 00:22:18 +00:00
|
|
|
{
|
2003-06-10 21:36:36 +00:00
|
|
|
UBool needsInit;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
needsInit = (UBool)(gService == NULL);
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
if (needsInit) {
|
|
|
|
ICULocaleService *tService = new ICUBreakIteratorService();
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if (gService == NULL) {
|
|
|
|
gService = tService;
|
|
|
|
tService = NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
delete tService;
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
2003-06-10 21:36:36 +00:00
|
|
|
return gService;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
static UBool
|
|
|
|
hasService(void)
|
|
|
|
{
|
2004-01-14 18:03:50 +00:00
|
|
|
Mutex mutex;
|
|
|
|
return gService != NULL;
|
2002-11-08 18:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
URegistryKey U_EXPORT2
|
2004-07-18 01:18:23 +00:00
|
|
|
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
|
|
|
|
{
|
|
|
|
return getService()->registerInstance(toAdopt, locale, kind, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
UBool U_EXPORT2
|
2004-07-18 01:18:23 +00:00
|
|
|
BreakIterator::unregister(URegistryKey key, UErrorCode& status)
|
|
|
|
{
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (hasService()) {
|
|
|
|
return gService->unregister(key, status);
|
|
|
|
}
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
StringEnumeration* U_EXPORT2
|
2004-07-18 01:18:23 +00:00
|
|
|
BreakIterator::getAvailableLocales(void)
|
|
|
|
{
|
|
|
|
return getService()->getAvailableLocales();
|
|
|
|
}
|
|
|
|
#endif /* UCONFIG_NO_SERVICE */
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
BreakIterator*
|
2002-11-14 17:47:49 +00:00
|
|
|
BreakIterator::createInstance(const Locale& loc, UBreakIteratorType kind, UErrorCode& status)
|
2002-11-08 18:07:48 +00:00
|
|
|
{
|
2003-06-10 21:36:36 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-08-22 23:26:53 +00:00
|
|
|
u_init(&status);
|
2004-07-18 01:18:23 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2003-06-10 21:36:36 +00:00
|
|
|
if (hasService()) {
|
2004-01-22 22:43:07 +00:00
|
|
|
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.
|
2004-05-18 00:47:29 +00:00
|
|
|
if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) {
|
2004-01-22 22:43:07 +00:00
|
|
|
U_LOCALE_BASED(locBased, *result);
|
|
|
|
locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName());
|
|
|
|
}
|
2004-01-14 18:03:50 +00:00
|
|
|
return result;
|
2003-06-10 21:36:36 +00:00
|
|
|
}
|
2004-07-18 01:18:23 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return makeInstance(loc, kind, status);
|
2002-11-15 23:52:14 +00:00
|
|
|
}
|
2002-11-08 18:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
BreakIterator*
|
|
|
|
BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
|
|
|
|
{
|
2004-01-16 21:31:17 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-01-14 18:03:50 +00:00
|
|
|
BreakIterator *result = NULL;
|
2002-11-08 18:07:48 +00:00
|
|
|
switch (kind) {
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_CHARACTER:
|
2004-01-14 18:03:50 +00:00
|
|
|
result = BreakIterator::makeCharacterInstance(loc, status);
|
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_WORD:
|
2004-01-14 18:03:50 +00:00
|
|
|
result = BreakIterator::makeWordInstance(loc, status);
|
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_LINE:
|
2004-01-14 18:03:50 +00:00
|
|
|
result = BreakIterator::makeLineInstance(loc, status);
|
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_SENTENCE:
|
2004-01-14 18:03:50 +00:00
|
|
|
result = BreakIterator::makeSentenceInstance(loc, status);
|
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_TITLE:
|
2004-01-14 18:03:50 +00:00
|
|
|
result = BreakIterator::makeTitleInstance(loc, status);
|
|
|
|
break;
|
2002-11-08 18:07:48 +00:00
|
|
|
default:
|
2004-01-16 21:31:17 +00:00
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
2002-11-08 18:07:48 +00:00
|
|
|
}
|
2004-01-16 21:31:17 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-20 00:03:20 +00:00
|
|
|
// this is more of a placeholder. All the break iterators have the same actual locale: root
|
|
|
|
// except the Thai one
|
2004-09-03 15:17:54 +00:00
|
|
|
UResourceBundle *res = ures_open(NULL, loc.getName(), &status);
|
2004-01-20 23:06:38 +00:00
|
|
|
U_LOCALE_BASED(locBased, *result);
|
2004-09-03 15:17:54 +00:00
|
|
|
locBased.setLocaleIDs(ures_getLocaleByType(res, ULOC_VALID_LOCALE, &status),
|
2004-01-20 23:06:38 +00:00
|
|
|
(uprv_strcmp(loc.getLanguage(), "th") == 0) ?
|
|
|
|
"th" : "root");
|
2004-09-03 15:17:54 +00:00
|
|
|
ures_close(res);
|
2003-11-20 00:03:20 +00:00
|
|
|
return result;
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 07:06:58 +00:00
|
|
|
Locale
|
2004-01-20 23:06:38 +00:00
|
|
|
BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
|
|
|
|
U_LOCALE_BASED(locBased, *this);
|
|
|
|
return locBased.getLocale(type, status);
|
2003-11-20 00:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2004-01-20 23:06:38 +00:00
|
|
|
BreakIterator::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
|
|
|
|
U_LOCALE_BASED(locBased, *this);
|
|
|
|
return locBased.getLocaleID(type, status);
|
2003-11-14 07:06:58 +00:00
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
// defined in ucln_cmn.h
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release all static memory held by breakiterator.
|
|
|
|
*/
|
|
|
|
U_CFUNC UBool breakiterator_cleanup(void) {
|
2004-07-18 01:18:23 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2004-01-14 18:03:50 +00:00
|
|
|
if (gService) {
|
|
|
|
delete gService;
|
|
|
|
gService = NULL;
|
|
|
|
}
|
2004-07-18 01:18:23 +00:00
|
|
|
#endif
|
2004-01-14 18:03:50 +00:00
|
|
|
return TRUE;
|
2002-11-08 18:07:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|