#include "unicode/utypes.h"
#if !UCONFIG_NO_BREAK_ITERATION
#include "unicode/rbbi.h"
#include "unicode/brkiter.h"
#include "unicode/udata.h"
#include "unicode/uloc.h"
#include "unicode/ures.h"
#include "unicode/ustring.h"
#include "unicode/filteredbrk.h"
#include "bytesinkutil.h"
#include "ucln_cmn.h"
#include "cstring.h"
#include "umutex.h"
#include "servloc.h"
#include "locbased.h"
#include "uresimp.h"
#include "uassert.h"
#include "ubrkimpl.h"
#include "utracimp.h"
#include "charstr.h"
U_NAMESPACE_BEGIN
BreakIterator*
BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &status)
{ … }
BreakIterator* U_EXPORT2
BreakIterator::createWordInstance(const Locale& key, UErrorCode& status)
{ … }
BreakIterator* U_EXPORT2
BreakIterator::createLineInstance(const Locale& key, UErrorCode& status)
{ … }
BreakIterator* U_EXPORT2
BreakIterator::createCharacterInstance(const Locale& key, UErrorCode& status)
{ … }
BreakIterator* U_EXPORT2
BreakIterator::createSentenceInstance(const Locale& key, UErrorCode& status)
{ … }
BreakIterator* U_EXPORT2
BreakIterator::createTitleInstance(const Locale& key, UErrorCode& status)
{ … }
const Locale* U_EXPORT2
BreakIterator::getAvailableLocales(int32_t& count)
{ … }
BreakIterator::BreakIterator()
{ … }
BreakIterator::BreakIterator(const BreakIterator &other) : … { … }
BreakIterator &BreakIterator::operator =(const BreakIterator &other) { … }
BreakIterator::~BreakIterator()
{ … }
#if !UCONFIG_NO_SERVICE
class ICUBreakIteratorFactory : public ICUResourceBundleFactory {
public:
virtual ~ICUBreakIteratorFactory();
protected:
virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* , UErrorCode& status) const override {
return BreakIterator::makeInstance(loc, kind, status);
}
};
ICUBreakIteratorFactory::~ICUBreakIteratorFactory() {}
class ICUBreakIteratorService : public ICULocaleService {
public:
ICUBreakIteratorService()
: ICULocaleService(UNICODE_STRING("Break Iterator", 14))
{
UErrorCode status = U_ZERO_ERROR;
registerFactory(new ICUBreakIteratorFactory(), status);
}
virtual ~ICUBreakIteratorService();
virtual UObject* cloneInstance(UObject* instance) const override {
return ((BreakIterator*)instance)->clone();
}
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* , UErrorCode& status) const override {
LocaleKey& lkey = static_cast<LocaleKey&>(const_cast<ICUServiceKey&>(key));
int32_t kind = lkey.kind();
Locale loc;
lkey.currentLocale(loc);
return BreakIterator::makeInstance(loc, kind, status);
}
virtual UBool isDefault() const override {
return countFactories() == 1;
}
};
ICUBreakIteratorService::~ICUBreakIteratorService() {}
U_NAMESPACE_END
static icu::UInitOnce gInitOnceBrkiter {};
static icu::ICULocaleService* gService = nullptr;
U_CDECL_BEGIN
static UBool U_CALLCONV breakiterator_cleanup() {
#if !UCONFIG_NO_SERVICE
if (gService) {
delete gService;
gService = nullptr;
}
gInitOnceBrkiter.reset();
#endif
return true;
}
U_CDECL_END
U_NAMESPACE_BEGIN
static void U_CALLCONV
initService() {
gService = new ICUBreakIteratorService();
ucln_common_registerCleanup(UCLN_COMMON_BREAKITERATOR, breakiterator_cleanup);
}
static ICULocaleService*
getService()
{
umtx_initOnce(gInitOnceBrkiter, &initService);
return gService;
}
static inline UBool
hasService()
{
return !gInitOnceBrkiter.isReset() && getService() != nullptr;
}
URegistryKey U_EXPORT2
BreakIterator::registerInstance(BreakIterator* toAdopt, const Locale& locale, UBreakIteratorType kind, UErrorCode& status)
{
ICULocaleService *service = getService();
if (service == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
return service->registerInstance(toAdopt, locale, kind, status);
}
UBool U_EXPORT2
BreakIterator::unregister(URegistryKey key, UErrorCode& status)
{
if (U_SUCCESS(status)) {
if (hasService()) {
return gService->unregister(key, status);
}
status = U_MEMORY_ALLOCATION_ERROR;
}
return false;
}
StringEnumeration* U_EXPORT2
BreakIterator::getAvailableLocales()
{
ICULocaleService *service = getService();
if (service == nullptr) {
return nullptr;
}
return service->getAvailableLocales();
}
#endif
BreakIterator*
BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& status)
{ … }
enum { … };
BreakIterator*
BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
{ … }
Locale
BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const { … }
const char *
BreakIterator::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { … }
int32_t BreakIterator::getRuleStatus() const { … }
int32_t BreakIterator::getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) { … }
BreakIterator::BreakIterator (const Locale& valid, const Locale& actual) { … }
U_NAMESPACE_END
#endif