1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
* Copyright (C) 1996-2001, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
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"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------------------
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator *iter = 0;
|
2002-06-25 17:23:07 +00:00
|
|
|
iter = new UCharCharacterIterator(text, textLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(iter == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
delete result;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
result->adoptText(iter);
|
|
|
|
|
|
|
|
return (UBreakIterator*)result;
|
|
|
|
}
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ubrk_openRules open a break iterator from a set of break rules.
|
|
|
|
// Invokes the rule builder.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------------------
|
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) {
|
|
|
|
|
|
|
|
BreakIterator *result = 0;
|
|
|
|
|
|
|
|
UnicodeString ruleString(rules, rulesLength);
|
|
|
|
result = RBBIRuleBuilder::createRuleBasedBreakIterator(ruleString, *parseErr, *status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator *iter = 0;
|
|
|
|
iter = new UCharCharacterIterator(text, textLength);
|
|
|
|
if(iter == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
delete result;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
result->adoptText(iter);
|
|
|
|
return (UBreakIterator *)result;
|
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,
|
|
|
|
void *stackBuffer,
|
|
|
|
int32_t *pBufferSize,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-02-21 23:40:41 +00:00
|
|
|
if (status == NULL || U_FAILURE(*status)){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!pBufferSize || !bi){
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-09-28 23:39:06 +00:00
|
|
|
return (UBreakIterator *)(((BreakIterator*)bi)->
|
|
|
|
createBufferClone(stackBuffer, *pBufferSize, *status));
|
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)
|
|
|
|
{
|
2002-06-25 17:23:07 +00:00
|
|
|
BreakIterator *ubi = (BreakIterator*) bi;
|
|
|
|
if (ubi) {
|
|
|
|
if (ubi->isBufferClone()) {
|
|
|
|
ubi->~BreakIterator();
|
|
|
|
*(uint32_t *)ubi = 0xdeadbeef;
|
|
|
|
} else {
|
|
|
|
delete ubi;
|
|
|
|
}
|
2001-02-21 23:40:41 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
if (U_FAILURE(*status)) return;
|
2001-09-28 23:39:06 +00:00
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
const CharacterIterator& biText = ((BreakIterator*)bi)->getText();
|
|
|
|
|
|
|
|
int32_t textLen = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
if (biText.getDynamicClassID() == UCharCharacterIterator::getStaticClassID()) {
|
|
|
|
((UCharCharacterIterator&)biText).setText(text, textLen);
|
|
|
|
}
|
2001-09-28 23:39:06 +00:00
|
|
|
else {
|
2000-01-08 02:05:05 +00:00
|
|
|
UCharCharacterIterator *iter = 0;
|
|
|
|
iter = new UCharCharacterIterator(text, textLen);
|
|
|
|
if(iter == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
((BreakIterator*)bi)->adoptText(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->current();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->next();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->previous();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->first();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->last();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->preceding(offset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((BreakIterator*)bi)->following(offset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ubrk_isBoundary(UBreakIterator *bi, int32_t offset)
|
|
|
|
{
|
|
|
|
return ((BreakIterator *)bi)->isBoundary(offset);
|
|
|
|
};
|
2002-07-08 22:46:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ubrk_getRuleStatus(UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((RuleBasedBreakIterator *)bi)->getRuleStatus();
|
|
|
|
};
|