1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
1999-11-23 01:30:04 +00:00
|
|
|
* Copyright (C) 1996-1999, International Business Machines
|
|
|
|
* 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"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UBreakIterator*
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_open(UBreakIteratorType type,
|
|
|
|
const char *locale,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
BreakIterator *result = 0;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for allocation error
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t textLen = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
UCharCharacterIterator *iter = 0;
|
|
|
|
iter = new UCharCharacterIterator(text, textLen);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UBreakIterator*
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_openRules(const UChar *rules,
|
|
|
|
int32_t rulesLength,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
2000-01-25 17:57:36 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-16 22:43:39 +00:00
|
|
|
U_CAPI UBreakIterator *
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return (UBreakIterator *)(((BreakIterator*)bi)->
|
|
|
|
createBufferClone(stackBuffer, *pBufferSize, *status));
|
2001-02-16 22:43:39 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_close(UBreakIterator *bi)
|
|
|
|
{
|
2001-02-21 23:40:41 +00:00
|
|
|
if (!((BreakIterator*) bi)->isBufferClone())
|
|
|
|
{
|
|
|
|
delete (BreakIterator*) bi;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
U_CAPI void
|
|
|
|
ubrk_setText(UBreakIterator* bi,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) return;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UCharCharacterIterator *iter = 0;
|
|
|
|
iter = new UCharCharacterIterator(text, textLen);
|
|
|
|
if(iter == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
((BreakIterator*)bi)->adoptText(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_current(const UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->current();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_next(UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->next();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_previous(UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->previous();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_first(UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->first();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_last(UBreakIterator *bi)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->last();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_preceding(UBreakIterator *bi,
|
|
|
|
UTextOffset offset)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->preceding(offset);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_following(UBreakIterator *bi,
|
|
|
|
UTextOffset offset)
|
|
|
|
{
|
|
|
|
return ((BreakIterator*)bi)->following(offset);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const char*
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ubrk_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|