2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 1997-2015, International Business Machines Corporation and
|
2010-02-25 22:32:39 +00:00
|
|
|
* others. All Rights Reserved.
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
2014-03-06 11:21:15 +00:00
|
|
|
* File brkiter.cpp
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
#include "unicode/rbbi.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"
|
2006-04-21 00:30:22 +00:00
|
|
|
#include "unicode/ustring.h"
|
2015-09-09 04:05:01 +00:00
|
|
|
#include "unicode/filteredbrk.h"
|
2004-10-06 23:10:53 +00:00
|
|
|
#include "ucln_cmn.h"
|
2000-04-15 21:23:28 +00:00
|
|
|
#include "cstring.h"
|
2006-09-08 03:33:14 +00:00
|
|
|
#include "umutex.h"
|
2004-12-21 06:55:20 +00:00
|
|
|
#include "servloc.h"
|
2004-01-20 23:06:38 +00:00
|
|
|
#include "locbased.h"
|
2004-10-21 01:03:01 +00:00
|
|
|
#include "uresimp.h"
|
2005-08-17 18:36:35 +00:00
|
|
|
#include "uassert.h"
|
2006-03-23 00:54:12 +00:00
|
|
|
#include "ubrkimpl.h"
|
2014-06-25 23:39:07 +00:00
|
|
|
#include "charstr.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
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
2002-11-08 00:22:18 +00:00
|
|
|
BreakIterator*
|
2017-12-03 00:36:54 +00:00
|
|
|
BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-10-21 01:03:01 +00:00
|
|
|
char fnbuff[256];
|
2006-04-21 00:30:22 +00:00
|
|
|
char ext[4]={'\0'};
|
2014-06-25 23:39:07 +00:00
|
|
|
CharString actualLocale;
|
2004-10-21 01:03:01 +00:00
|
|
|
int32_t size;
|
|
|
|
const UChar* brkfname = NULL;
|
2005-08-17 18:36:35 +00:00
|
|
|
UResourceBundle brkRulesStack;
|
|
|
|
UResourceBundle brkNameStack;
|
|
|
|
UResourceBundle *brkRules = &brkRulesStack;
|
|
|
|
UResourceBundle *brkName = &brkNameStack;
|
2006-03-23 00:54:12 +00:00
|
|
|
RuleBasedBreakIterator *result = NULL;
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2001-10-09 22:57:29 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
return NULL;
|
2002-08-08 00:39:13 +00:00
|
|
|
|
2004-11-13 00:49:55 +00:00
|
|
|
ures_initStackObject(brkRules);
|
|
|
|
ures_initStackObject(brkName);
|
|
|
|
|
2004-10-21 01:03:01 +00:00
|
|
|
// Get the locale
|
2014-12-04 21:11:26 +00:00
|
|
|
UResourceBundle *b = ures_openNoDefault(U_ICUDATA_BRKITR, loc.getName(), &status);
|
2004-10-21 01:03:01 +00:00
|
|
|
|
|
|
|
// Get the "boundaries" array.
|
|
|
|
if (U_SUCCESS(status)) {
|
2004-11-13 00:49:55 +00:00
|
|
|
brkRules = ures_getByKeyWithFallback(b, "boundaries", brkRules, &status);
|
|
|
|
// Get the string object naming the rules file
|
|
|
|
brkName = ures_getByKeyWithFallback(brkRules, type, brkName, &status);
|
|
|
|
// Get the actual string
|
|
|
|
brkfname = ures_getString(brkName, &size, &status);
|
2006-01-21 07:00:54 +00:00
|
|
|
U_ASSERT((size_t)size<sizeof(fnbuff));
|
|
|
|
if ((size_t)size>=sizeof(fnbuff)) {
|
2005-08-17 18:36:35 +00:00
|
|
|
size=0;
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
status = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2004-10-21 01:03:01 +00:00
|
|
|
|
2004-11-13 00:49:55 +00:00
|
|
|
// Use the string if we found it
|
|
|
|
if (U_SUCCESS(status) && brkfname) {
|
2014-06-25 23:39:07 +00:00
|
|
|
actualLocale.append(ures_getLocaleInternal(brkName, &status), -1, status);
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2006-04-21 00:30:22 +00:00
|
|
|
UChar* extStart=u_strchr(brkfname, 0x002e);
|
|
|
|
int len = 0;
|
|
|
|
if(extStart!=NULL){
|
2009-11-11 15:47:22 +00:00
|
|
|
len = (int)(extStart-brkfname);
|
2006-04-21 00:30:22 +00:00
|
|
|
u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
|
|
|
|
u_UCharsToChars(brkfname, fnbuff, len);
|
|
|
|
}
|
|
|
|
fnbuff[len]=0; // nul terminate
|
2004-11-13 00:49:55 +00:00
|
|
|
}
|
2000-01-08 02:05:05 +00:00
|
|
|
}
|
|
|
|
|
2004-11-13 00:49:55 +00:00
|
|
|
ures_close(brkRules);
|
|
|
|
ures_close(brkName);
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2006-04-21 00:30:22 +00:00
|
|
|
UDataMemory* file = udata_open(U_ICUDATA_BRKITR, ext, fnbuff, &status);
|
2002-08-08 00:39:13 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2004-10-21 01:03:01 +00:00
|
|
|
ures_close(b);
|
2002-08-08 00:39:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-01-08 02:05:05 +00:00
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
// Create a RuleBasedBreakIterator
|
|
|
|
result = new RuleBasedBreakIterator(file, status);
|
2004-10-21 01:03:01 +00:00
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
// If there is a result, set the valid locale and actual locale, and the kind
|
2004-10-21 01:03:01 +00:00
|
|
|
if (U_SUCCESS(status) && result != NULL) {
|
2006-11-21 00:10:29 +00:00
|
|
|
U_LOCALE_BASED(locBased, *(BreakIterator*)result);
|
2014-06-25 23:39:07 +00:00
|
|
|
locBased.setLocaleIDs(ures_getLocaleByType(b, ULOC_VALID_LOCALE, &status),
|
|
|
|
actualLocale.data());
|
2004-10-21 01:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ures_close(b);
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2004-10-21 01:03:01 +00:00
|
|
|
if (U_FAILURE(status) && result != NULL) { // Sometimes redundant check, but simple
|
|
|
|
delete result;
|
2003-09-09 23:51:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-21 01:03:01 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
udata_close(file);
|
2004-10-21 01:03:01 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2002-08-08 00:39:13 +00:00
|
|
|
}
|
2004-10-21 01:03:01 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2004-10-21 01:03:01 +00:00
|
|
|
// Creates a break iterator for word breaks.
|
|
|
|
BreakIterator* U_EXPORT2
|
|
|
|
BreakIterator::createWordInstance(const Locale& key, UErrorCode& status)
|
|
|
|
{
|
|
|
|
return createInstance(key, UBRK_WORD, status);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
//
|
2017-07-31 20:20:37 +00:00
|
|
|
// Constructors, destructor and assignment operator
|
2002-08-08 00:39:13 +00:00
|
|
|
//
|
|
|
|
//-------------------------------------------
|
2002-11-08 00:22:18 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator::BreakIterator()
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
*validLocale = *actualLocale = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 20:20:37 +00:00
|
|
|
BreakIterator::BreakIterator(const BreakIterator &other) : UObject(other) {
|
|
|
|
uprv_strncpy(actualLocale, other.actualLocale, sizeof(actualLocale));
|
|
|
|
uprv_strncpy(validLocale, other.validLocale, sizeof(validLocale));
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakIterator &BreakIterator::operator =(const BreakIterator &other) {
|
|
|
|
if (this != &other) {
|
|
|
|
uprv_strncpy(actualLocale, other.actualLocale, sizeof(actualLocale));
|
|
|
|
uprv_strncpy(validLocale, other.validLocale, sizeof(validLocale));
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// -------------------------------------
|
2002-11-08 00:22:18 +00:00
|
|
|
|
|
|
|
class ICUBreakIteratorFactory : public ICUResourceBundleFactory {
|
2011-07-26 05:32:25 +00:00
|
|
|
public:
|
|
|
|
virtual ~ICUBreakIteratorFactory();
|
2002-11-08 00:22:18 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2011-07-26 05:32:25 +00:00
|
|
|
ICUBreakIteratorFactory::~ICUBreakIteratorFactory() {}
|
|
|
|
|
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);
|
|
|
|
}
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2011-07-26 05:32:25 +00:00
|
|
|
virtual ~ICUBreakIteratorService();
|
|
|
|
|
2004-01-14 18:03:50 +00:00
|
|
|
virtual UObject* cloneInstance(UObject* instance) const {
|
|
|
|
return ((BreakIterator*)instance)->clone();
|
|
|
|
}
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2004-01-14 18:03:50 +00:00
|
|
|
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);
|
|
|
|
}
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2004-01-14 18:03:50 +00:00
|
|
|
virtual UBool isDefault() const {
|
|
|
|
return countFactories() == 1;
|
|
|
|
}
|
2002-11-08 00:22:18 +00:00
|
|
|
};
|
|
|
|
|
2011-07-26 05:32:25 +00:00
|
|
|
ICUBreakIteratorService::~ICUBreakIteratorService() {}
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
// defined in ucln_cmn.h
|
2013-09-10 00:13:41 +00:00
|
|
|
U_NAMESPACE_END
|
2004-10-06 23:10:53 +00:00
|
|
|
|
2019-04-22 19:54:14 +00:00
|
|
|
static icu::UInitOnce gInitOnceBrkiter = U_INITONCE_INITIALIZER;
|
2011-07-06 04:03:35 +00:00
|
|
|
static icu::ICULocaleService* gService = NULL;
|
2013-09-10 00:13:41 +00:00
|
|
|
|
|
|
|
|
2006-09-03 17:08:23 +00:00
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
/**
|
2007-08-16 23:14:06 +00:00
|
|
|
* Release all static memory held by breakiterator.
|
2004-10-06 23:10:53 +00:00
|
|
|
*/
|
|
|
|
U_CDECL_BEGIN
|
2013-10-20 21:15:16 +00:00
|
|
|
static UBool U_CALLCONV breakiterator_cleanup(void) {
|
2004-10-06 23:10:53 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
if (gService) {
|
|
|
|
delete gService;
|
|
|
|
gService = NULL;
|
|
|
|
}
|
2017-08-11 21:38:54 +00:00
|
|
|
gInitOnceBrkiter.reset();
|
2004-10-06 23:10:53 +00:00
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
U_CDECL_END
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
static void U_CALLCONV
|
|
|
|
initService(void) {
|
|
|
|
gService = new ICUBreakIteratorService();
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_BREAKITERATOR, breakiterator_cleanup);
|
|
|
|
}
|
|
|
|
|
2007-08-16 23:14:06 +00:00
|
|
|
static ICULocaleService*
|
2002-11-08 18:07:48 +00:00
|
|
|
getService(void)
|
2002-11-08 00:22:18 +00:00
|
|
|
{
|
2017-08-11 21:38:54 +00:00
|
|
|
umtx_initOnce(gInitOnceBrkiter, &initService);
|
2003-06-10 21:36:36 +00:00
|
|
|
return gService;
|
|
|
|
}
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
|
2003-06-10 21:36:36 +00:00
|
|
|
// -------------------------------------
|
|
|
|
|
2006-09-08 03:33:14 +00:00
|
|
|
static inline UBool
|
2007-08-16 23:14:06 +00:00
|
|
|
hasService(void)
|
2003-06-10 21:36:36 +00:00
|
|
|
{
|
2017-08-11 21:38:54 +00:00
|
|
|
return !gInitOnceBrkiter.isReset() && getService() != NULL;
|
2002-11-08 18:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
URegistryKey U_EXPORT2
|
2007-08-16 23:14:06 +00:00
|
|
|
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
|
2004-07-18 01:18:23 +00:00
|
|
|
{
|
2008-02-23 19:15:18 +00:00
|
|
|
ICULocaleService *service = getService();
|
|
|
|
if (service == NULL) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-01-09 05:42:43 +00:00
|
|
|
return service->registerInstance(toAdopt, locale, kind, status);
|
2004-07-18 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
UBool U_EXPORT2
|
2007-08-16 23:14:06 +00:00
|
|
|
BreakIterator::unregister(URegistryKey key, UErrorCode& status)
|
2004-07-18 01:18:23 +00:00
|
|
|
{
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (hasService()) {
|
|
|
|
return gService->unregister(key, status);
|
|
|
|
}
|
2008-01-09 23:18:58 +00:00
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2004-07-18 01:18:23 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2004-08-24 17:21:14 +00:00
|
|
|
StringEnumeration* U_EXPORT2
|
2004-07-18 01:18:23 +00:00
|
|
|
BreakIterator::getAvailableLocales(void)
|
|
|
|
{
|
2008-01-09 05:42:43 +00:00
|
|
|
ICULocaleService *service = getService();
|
|
|
|
if (service == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
return NULL;
|
2008-01-09 05:42:43 +00:00
|
|
|
}
|
|
|
|
return service->getAvailableLocales();
|
2004-07-18 01:18:23 +00:00
|
|
|
}
|
|
|
|
#endif /* UCONFIG_NO_SERVICE */
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2002-11-08 18:07:48 +00:00
|
|
|
BreakIterator*
|
2006-03-23 00:54:12 +00:00
|
|
|
BreakIterator::createInstance(const Locale& loc, int32_t 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;
|
|
|
|
}
|
2007-08-16 23:14:06 +00:00
|
|
|
|
2004-07-18 01:18:23 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2003-06-10 21:36:36 +00:00
|
|
|
if (hasService()) {
|
2005-01-11 20:26:04 +00:00
|
|
|
Locale actualLoc("");
|
2004-01-22 22:43:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
2015-09-09 04:05:01 +00:00
|
|
|
enum { kKeyValueLenMax = 32 };
|
2002-11-08 18:07:48 +00:00
|
|
|
|
2007-08-16 23:14:06 +00:00
|
|
|
BreakIterator*
|
2002-11-08 18:07:48 +00:00
|
|
|
BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
|
|
|
|
{
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-09 04:05:01 +00:00
|
|
|
char lbType[kKeyValueLenMax];
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2004-01-14 18:03:50 +00:00
|
|
|
BreakIterator *result = NULL;
|
2002-11-08 18:07:48 +00:00
|
|
|
switch (kind) {
|
2007-08-16 23:14:06 +00:00
|
|
|
case UBRK_CHARACTER:
|
2017-12-03 00:36:54 +00:00
|
|
|
result = BreakIterator::buildInstance(loc, "grapheme", status);
|
2004-01-14 18:03:50 +00:00
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_WORD:
|
2017-12-03 00:36:54 +00:00
|
|
|
result = BreakIterator::buildInstance(loc, "word", status);
|
2004-01-14 18:03:50 +00:00
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_LINE:
|
2015-02-24 22:37:10 +00:00
|
|
|
uprv_strcpy(lbType, "line");
|
|
|
|
{
|
2015-09-09 04:05:01 +00:00
|
|
|
char lbKeyValue[kKeyValueLenMax] = {0};
|
2015-02-24 22:37:10 +00:00
|
|
|
UErrorCode kvStatus = U_ZERO_ERROR;
|
2015-09-09 04:05:01 +00:00
|
|
|
int32_t kLen = loc.getKeywordValue("lb", lbKeyValue, kKeyValueLenMax, kvStatus);
|
2015-03-02 08:17:54 +00:00
|
|
|
if (U_SUCCESS(kvStatus) && kLen > 0 && (uprv_strcmp(lbKeyValue,"strict")==0 || uprv_strcmp(lbKeyValue,"normal")==0 || uprv_strcmp(lbKeyValue,"loose")==0)) {
|
2015-02-24 22:37:10 +00:00
|
|
|
uprv_strcat(lbType, "_");
|
|
|
|
uprv_strcat(lbType, lbKeyValue);
|
|
|
|
}
|
|
|
|
}
|
2017-12-03 00:36:54 +00:00
|
|
|
result = BreakIterator::buildInstance(loc, lbType, status);
|
2004-01-14 18:03:50 +00:00
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_SENTENCE:
|
2017-12-03 00:36:54 +00:00
|
|
|
result = BreakIterator::buildInstance(loc, "sentence", status);
|
2016-09-28 07:37:19 +00:00
|
|
|
#if !UCONFIG_NO_FILTERED_BREAK_ITERATION
|
2015-09-09 04:05:01 +00:00
|
|
|
{
|
|
|
|
char ssKeyValue[kKeyValueLenMax] = {0};
|
|
|
|
UErrorCode kvStatus = U_ZERO_ERROR;
|
|
|
|
int32_t kLen = loc.getKeywordValue("ss", ssKeyValue, kKeyValueLenMax, kvStatus);
|
|
|
|
if (U_SUCCESS(kvStatus) && kLen > 0 && uprv_strcmp(ssKeyValue,"standard")==0) {
|
|
|
|
FilteredBreakIteratorBuilder* fbiBuilder = FilteredBreakIteratorBuilder::createInstance(loc, kvStatus);
|
|
|
|
if (U_SUCCESS(kvStatus)) {
|
|
|
|
result = fbiBuilder->build(result, status);
|
|
|
|
delete fbiBuilder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-28 07:37:19 +00:00
|
|
|
#endif
|
2004-01-14 18:03:50 +00:00
|
|
|
break;
|
2003-11-20 00:03:20 +00:00
|
|
|
case UBRK_TITLE:
|
2017-12-03 00:36:54 +00:00
|
|
|
result = BreakIterator::buildInstance(loc, "title", status);
|
2004-01-14 18:03:50 +00:00
|
|
|
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
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-01-16 21:31:17 +00:00
|
|
|
|
2003-11-20 00:03:20 +00:00
|
|
|
return result;
|
2002-11-08 00:22:18 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 23:14:06 +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
|
|
|
}
|
|
|
|
|
2013-06-14 00:47:11 +00:00
|
|
|
|
|
|
|
// This implementation of getRuleStatus is a do-nothing stub, here to
|
|
|
|
// provide a default implementation for any derived BreakIterator classes that
|
|
|
|
// do not implement it themselves.
|
|
|
|
int32_t BreakIterator::getRuleStatus() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This implementation of getRuleStatusVec is a do-nothing stub, here to
|
|
|
|
// provide a default implementation for any derived BreakIterator classes that
|
|
|
|
// do not implement it themselves.
|
|
|
|
int32_t BreakIterator::getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) {
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (capacity < 1) {
|
|
|
|
status = U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*fillInVec = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-06 11:21:15 +00:00
|
|
|
BreakIterator::BreakIterator (const Locale& valid, const Locale& actual) {
|
|
|
|
U_LOCALE_BASED(locBased, (*this));
|
|
|
|
locBased.setLocaleIDs(valid, actual);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|