2016-06-15 18:58:17 +00:00
|
|
|
// Copyright (C) 2016 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2008-02-17 19:13:10 +00:00
|
|
|
********************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 1996-2015, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2008-02-17 19:13:10 +00:00
|
|
|
********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ubrk.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/brkiter.h"
|
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/uchriter.h"
|
2002-06-25 17:23:07 +00:00
|
|
|
#include "unicode/rbbi.h"
|
|
|
|
#include "rbbirb.h"
|
2006-04-26 04:01:00 +00:00
|
|
|
#include "uassert.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2008-02-17 19:13:10 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// ubrk_open Create a canned type of break iterator based on type (word, line, etc.)
|
|
|
|
// and locale.
|
|
|
|
//
|
2008-02-17 19:13:10 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBreakIterator* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_open(UBreakIteratorType type,
|
|
|
|
const char *locale,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
2001-09-28 23:39:06 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
BreakIterator *result = 0;
|
2001-09-28 23:39:06 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
switch(type) {
|
|
|
|
|
|
|
|
case UBRK_CHARACTER:
|
2000-04-15 21:23:28 +00:00
|
|
|
result = BreakIterator::createCharacterInstance(Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UBRK_WORD:
|
2000-04-15 21:23:28 +00:00
|
|
|
result = BreakIterator::createWordInstance(Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UBRK_LINE:
|
2000-04-15 21:23:28 +00:00
|
|
|
result = BreakIterator::createLineInstance(Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UBRK_SENTENCE:
|
2000-04-15 21:23:28 +00:00
|
|
|
result = BreakIterator::createSentenceInstance(Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
2002-02-28 01:28:04 +00:00
|
|
|
|
|
|
|
case UBRK_TITLE:
|
|
|
|
result = BreakIterator::createTitleInstance(Locale(locale), *status);
|
|
|
|
break;
|
2006-04-26 04:01:00 +00:00
|
|
|
|
|
|
|
default:
|
2006-05-03 03:32:18 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for allocation error
|
2001-09-28 23:39:06 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
if(result == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-26 01:07:31 +00:00
|
|
|
|
|
|
|
UBreakIterator *uBI = (UBreakIterator *)result;
|
2005-06-23 05:51:28 +00:00
|
|
|
if (text != NULL) {
|
2006-04-26 01:07:31 +00:00
|
|
|
ubrk_setText(uBI, text, textLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2006-04-26 01:07:31 +00:00
|
|
|
return uBI;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
2008-02-17 19:13:10 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// ubrk_openRules open a break iterator from a set of break rules.
|
|
|
|
// Invokes the rule builder.
|
|
|
|
//
|
2008-02-17 19:13:10 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBreakIterator* U_EXPORT2
|
2002-06-25 17:23:07 +00:00
|
|
|
ubrk_openRules( const UChar *rules,
|
|
|
|
int32_t rulesLength,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UParseError *parseErr,
|
|
|
|
UErrorCode *status) {
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
if (status == NULL || U_FAILURE(*status)){
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
BreakIterator *result = 0;
|
2002-06-25 17:23:07 +00:00
|
|
|
UnicodeString ruleString(rules, rulesLength);
|
2008-02-17 19:13:10 +00:00
|
|
|
result = RBBIRuleBuilder::createRuleBasedBreakIterator(ruleString, parseErr, *status);
|
2002-06-25 17:23:07 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-26 01:07:31 +00:00
|
|
|
UBreakIterator *uBI = (UBreakIterator *)result;
|
2002-08-08 00:39:13 +00:00
|
|
|
if (text != NULL) {
|
2006-04-26 01:07:31 +00:00
|
|
|
ubrk_setText(uBI, text, textLength, status);
|
2002-06-25 17:23:07 +00:00
|
|
|
}
|
2006-04-26 01:07:31 +00:00
|
|
|
return uBI;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBreakIterator * U_EXPORT2
|
2001-02-16 22:43:39 +00:00
|
|
|
ubrk_safeClone(
|
|
|
|
const UBreakIterator *bi,
|
2013-09-17 19:48:50 +00:00
|
|
|
void * /*stackBuffer*/,
|
2001-02-16 22:43:39 +00:00
|
|
|
int32_t *pBufferSize,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-02-21 23:40:41 +00:00
|
|
|
if (status == NULL || U_FAILURE(*status)){
|
2013-09-17 19:48:50 +00:00
|
|
|
return NULL;
|
2001-02-21 23:40:41 +00:00
|
|
|
}
|
2013-09-17 19:48:50 +00:00
|
|
|
if (bi == NULL) {
|
2001-02-21 23:40:41 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
2013-09-17 19:48:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (pBufferSize != NULL) {
|
|
|
|
int32_t inputSize = *pBufferSize;
|
|
|
|
*pBufferSize = 1;
|
|
|
|
if (inputSize == 0) {
|
|
|
|
return NULL; // preflighting for deprecated functionality
|
|
|
|
}
|
2001-02-21 23:40:41 +00:00
|
|
|
}
|
2013-09-17 19:48:50 +00:00
|
|
|
BreakIterator *newBI = ((BreakIterator *)bi)->clone();
|
|
|
|
if (newBI == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
*status = U_SAFECLONE_ALLOCATED_WARNING;
|
2006-08-04 18:15:29 +00:00
|
|
|
}
|
2013-09-17 19:48:50 +00:00
|
|
|
return (UBreakIterator *)newBI;
|
2001-02-16 22:43:39 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_close(UBreakIterator *bi)
|
|
|
|
{
|
2013-09-17 19:48:50 +00:00
|
|
|
delete (BreakIterator *)bi;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2000-01-08 02:05:05 +00:00
|
|
|
ubrk_setText(UBreakIterator* bi,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2006-04-26 00:51:53 +00:00
|
|
|
UText ut = UTEXT_INITIALIZER;
|
|
|
|
utext_openUChars(&ut, text, textLength, status);
|
2015-09-09 04:05:01 +00:00
|
|
|
((BreakIterator*)bi)->setText(&ut, *status);
|
2013-09-17 19:48:50 +00:00
|
|
|
// A stack allocated UText wrapping a UChar * string
|
2006-04-26 00:51:53 +00:00
|
|
|
// can be dumped without explicitly closing it.
|
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2005-06-23 05:51:28 +00:00
|
|
|
ubrk_setUText(UBreakIterator *bi,
|
|
|
|
UText *text,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2015-09-09 04:05:01 +00:00
|
|
|
((BreakIterator*)bi)->setText(text, *status);
|
2005-06-23 05:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_current(const UBreakIterator *bi)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->current();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_next(UBreakIterator *bi)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->next();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_previous(UBreakIterator *bi)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->previous();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_first(UBreakIterator *bi)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->first();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_last(UBreakIterator *bi)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->last();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_preceding(UBreakIterator *bi,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t offset)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->preceding(offset);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_following(UBreakIterator *bi,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t offset)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->following(offset);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_getAvailable(int32_t index)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_countAvailable()
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
2002-03-08 18:58:46 +00:00
|
|
|
|
|
|
|
|
2002-08-08 00:39:13 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2002-03-08 18:58:46 +00:00
|
|
|
ubrk_isBoundary(UBreakIterator *bi, int32_t offset)
|
|
|
|
{
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->isBoundary(offset);
|
2002-11-30 04:41:53 +00:00
|
|
|
}
|
2002-07-08 22:46:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
2004-03-31 22:10:20 +00:00
|
|
|
ubrk_getRuleStatus(UBreakIterator *bi)
|
2002-07-08 22:46:16 +00:00
|
|
|
{
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->getRuleStatus();
|
2002-11-30 04:41:53 +00:00
|
|
|
}
|
2002-09-20 01:54:48 +00:00
|
|
|
|
2004-03-08 18:18:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2004-03-31 22:10:20 +00:00
|
|
|
ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, UErrorCode *status)
|
2004-03-08 18:18:42 +00:00
|
|
|
{
|
2015-09-09 04:05:01 +00:00
|
|
|
return ((BreakIterator*)bi)->getRuleStatusVec(fillInVec, capacity, *status);
|
2004-03-08 18:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 07:06:58 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
2005-06-23 05:51:28 +00:00
|
|
|
ubrk_getLocaleByType(const UBreakIterator *bi,
|
|
|
|
ULocDataLocaleType type,
|
2003-11-14 07:06:58 +00:00
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
if (bi == NULL) {
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((BreakIterator*)bi)->getLocaleID(type, *status);
|
2003-11-14 07:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-09 22:49:40 +00:00
|
|
|
void ubrk_refreshUText(UBreakIterator *bi,
|
|
|
|
UText *text,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
BreakIterator *bii = reinterpret_cast<BreakIterator *>(bi);
|
|
|
|
bii->refreshInputText(text, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|