2001-01-15 19:02:30 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************
|
2006-03-16 07:36:52 +00:00
|
|
|
* Copyright (C) 2001-2006, International Business Machines
|
2001-01-15 19:02:30 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* File ucoleitr.cpp
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/15/2001 synwee Modified all methods to process its own function
|
|
|
|
* instead of calling the equivalent c++ api (coleitr.h)
|
|
|
|
******************************************************************************/
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
2001-01-15 19:02:30 +00:00
|
|
|
#include "unicode/ucoleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
2001-11-14 22:24:17 +00:00
|
|
|
#include "unicode/sortkey.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "ucol_imp.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
#define BUFFER_LENGTH 100
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
typedef struct collIterate collIterator;
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
/* public methods ---------------------------------------------------- */
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UCollationElements* U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_openElements(const UCollator *coll,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
UCollationElements *result;
|
|
|
|
|
2001-03-07 21:01:53 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return NULL;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
result = (UCollationElements *)uprv_malloc(sizeof(UCollationElements));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
2001-02-23 23:36:42 +00:00
|
|
|
result->reset_ = TRUE;
|
2001-04-06 23:37:48 +00:00
|
|
|
result->isWritable = FALSE;
|
2001-06-20 18:14:51 +00:00
|
|
|
|
|
|
|
if (text == NULL) {
|
|
|
|
textLength = 0;
|
|
|
|
}
|
2002-07-16 01:46:42 +00:00
|
|
|
uprv_init_collIterate(coll, text, textLength, &result->iteratordata_);
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
return result;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_closeElements(UCollationElements *elems)
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
collIterate *ci = &elems->iteratordata_;
|
2001-03-07 21:01:53 +00:00
|
|
|
if (ci->writableBuffer != ci->stackWritableBuffer) {
|
2001-02-20 00:26:50 +00:00
|
|
|
uprv_free(ci->writableBuffer);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
if (elems->isWritable && elems->iteratordata_.string != NULL)
|
2001-03-07 21:01:53 +00:00
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
uprv_free(elems->iteratordata_.string);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2007-12-15 00:30:35 +00:00
|
|
|
if (ci->extendCEs) {
|
|
|
|
uprv_free(ci->extendCEs);
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
uprv_free(elems);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_reset(UCollationElements *elems)
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
collIterate *ci = &(elems->iteratordata_);
|
2001-02-23 23:36:42 +00:00
|
|
|
elems->reset_ = TRUE;
|
2001-02-20 00:26:50 +00:00
|
|
|
ci->pos = ci->string;
|
2001-04-26 01:15:34 +00:00
|
|
|
if ((ci->flags & UCOL_ITER_HASLEN) == 0 || ci->endp == NULL) {
|
2001-04-12 00:08:26 +00:00
|
|
|
ci->endp = ci->string + u_strlen(ci->string);
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
ci->CEpos = ci->toReturn = ci->CEs;
|
2001-04-12 00:08:26 +00:00
|
|
|
ci->flags = UCOL_ITER_HASLEN;
|
|
|
|
if (ci->coll->normalizationMode == UCOL_ON) {
|
|
|
|
ci->flags |= UCOL_ITER_NORM;
|
|
|
|
}
|
2001-03-03 04:06:43 +00:00
|
|
|
|
2001-03-07 21:01:53 +00:00
|
|
|
if (ci->stackWritableBuffer != ci->writableBuffer) {
|
2001-02-20 00:26:50 +00:00
|
|
|
uprv_free(ci->writableBuffer);
|
|
|
|
ci->writableBuffer = ci->stackWritableBuffer;
|
2001-04-17 02:43:35 +00:00
|
|
|
ci->writableBufSize = UCOL_WRITABLE_BUFFER_SIZE;
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
2001-08-03 01:01:42 +00:00
|
|
|
ci->fcdPosition = NULL;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-04-26 01:15:34 +00:00
|
|
|
ucol_next(UCollationElements *elems,
|
2001-02-20 00:26:50 +00:00
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2006-03-16 07:36:52 +00:00
|
|
|
int32_t result;
|
2001-03-07 21:01:53 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return UCOL_NULLORDER;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-23 23:36:42 +00:00
|
|
|
elems->reset_ = FALSE;
|
2001-03-03 04:06:43 +00:00
|
|
|
|
2006-03-16 07:36:52 +00:00
|
|
|
result = (int32_t)ucol_getNextCE(elems->iteratordata_.coll,
|
|
|
|
&elems->iteratordata_,
|
|
|
|
status);
|
2001-02-23 23:36:42 +00:00
|
|
|
|
2001-03-07 21:01:53 +00:00
|
|
|
if (result == UCOL_NO_MORE_CES) {
|
2001-02-22 23:16:06 +00:00
|
|
|
result = UCOL_NULLORDER;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
return result;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_previous(UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-03-07 21:01:53 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return UCOL_NULLORDER;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-02-23 23:36:42 +00:00
|
|
|
else
|
|
|
|
{
|
2006-03-16 07:36:52 +00:00
|
|
|
int32_t result;
|
2001-02-23 23:36:42 +00:00
|
|
|
|
|
|
|
if (elems->reset_ &&
|
2001-04-12 00:08:26 +00:00
|
|
|
(elems->iteratordata_.pos == elems->iteratordata_.string)) {
|
|
|
|
if (elems->iteratordata_.endp == NULL) {
|
|
|
|
elems->iteratordata_.endp = elems->iteratordata_.string +
|
|
|
|
u_strlen(elems->iteratordata_.string);
|
|
|
|
elems->iteratordata_.flags |= UCOL_ITER_HASLEN;
|
|
|
|
}
|
|
|
|
elems->iteratordata_.pos = elems->iteratordata_.endp;
|
2001-08-03 01:01:42 +00:00
|
|
|
elems->iteratordata_.fcdPosition = elems->iteratordata_.endp;
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
2001-02-23 23:36:42 +00:00
|
|
|
|
|
|
|
elems->reset_ = FALSE;
|
|
|
|
|
2006-03-16 07:36:52 +00:00
|
|
|
result = (int32_t)ucol_getPrevCE(elems->iteratordata_.coll,
|
|
|
|
&(elems->iteratordata_),
|
|
|
|
status);
|
2001-04-20 22:29:53 +00:00
|
|
|
|
2001-03-07 21:01:53 +00:00
|
|
|
if (result == UCOL_NO_MORE_CES) {
|
2001-02-23 23:36:42 +00:00
|
|
|
result = UCOL_NULLORDER;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-02-21 01:58:55 +00:00
|
|
|
|
2001-02-23 23:36:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_getMaxExpansion(const UCollationElements *elems,
|
|
|
|
int32_t order)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-03-02 01:14:03 +00:00
|
|
|
uint8_t result;
|
2001-03-15 19:10:41 +00:00
|
|
|
UCOL_GETMAXEXPANSION(elems->iteratordata_.coll, (uint32_t)order, result);
|
2001-03-02 01:14:03 +00:00
|
|
|
return result;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
2001-03-03 04:06:43 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_setText( UCollationElements *elems,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-03-07 21:01:53 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-20 22:29:53 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if (elems->isWritable && elems->iteratordata_.string != NULL)
|
2001-03-07 21:01:53 +00:00
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
uprv_free(elems->iteratordata_.string);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-03-09 00:50:37 +00:00
|
|
|
|
2001-06-20 18:14:51 +00:00
|
|
|
if (text == NULL) {
|
|
|
|
textLength = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
elems->isWritable = FALSE;
|
2002-07-16 01:46:42 +00:00
|
|
|
uprv_init_collIterate(elems->iteratordata_.coll, text, textLength,
|
2001-09-07 21:56:18 +00:00
|
|
|
&elems->iteratordata_);
|
2001-03-03 04:06:43 +00:00
|
|
|
|
|
|
|
elems->reset_ = TRUE;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
const collIterate *ci = &(elems->iteratordata_);
|
2001-06-26 17:41:10 +00:00
|
|
|
// while processing characters in normalization buffer getOffset will
|
|
|
|
// return the next non-normalized character.
|
|
|
|
// should be inline with the old implementation since the old codes uses
|
|
|
|
// nextDecomp in normalizer which also decomposes the string till the
|
|
|
|
// first base character is found.
|
|
|
|
if (ci->flags & UCOL_ITER_INNORMBUF) {
|
|
|
|
if (ci->fcdPosition == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-30 21:03:00 +00:00
|
|
|
return (int32_t)(ci->fcdPosition - ci->string);
|
2001-06-26 17:41:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-04-30 21:03:00 +00:00
|
|
|
return (int32_t)(ci->pos - ci->string);
|
2001-06-26 17:41:10 +00:00
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_setOffset(UCollationElements *elems,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t offset,
|
2001-02-20 00:26:50 +00:00
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-03-07 21:01:53 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
2001-09-07 21:56:18 +00:00
|
|
|
// this methods will clean up any use of the writable buffer and points to
|
|
|
|
// the original string
|
2001-02-20 00:26:50 +00:00
|
|
|
collIterate *ci = &(elems->iteratordata_);
|
|
|
|
ci->pos = ci->string + offset;
|
|
|
|
ci->CEpos = ci->toReturn = ci->CEs;
|
2001-08-25 02:03:53 +00:00
|
|
|
if (ci->flags & UCOL_ITER_INNORMBUF) {
|
2001-09-07 21:56:18 +00:00
|
|
|
ci->flags = ci->origFlags;
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2001-06-08 01:16:44 +00:00
|
|
|
if ((ci->flags & UCOL_ITER_HASLEN) == 0) {
|
2001-09-07 21:56:18 +00:00
|
|
|
ci->endp = ci->string + u_strlen(ci->string);
|
|
|
|
ci->flags |= UCOL_ITER_HASLEN;
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
2001-08-02 17:48:25 +00:00
|
|
|
ci->fcdPosition = NULL;
|
2003-07-09 23:16:04 +00:00
|
|
|
elems->reset_ = FALSE;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-23 04:47:00 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_primaryOrder (int32_t order)
|
|
|
|
{
|
|
|
|
order &= UCOL_PRIMARYMASK;
|
2003-05-01 15:42:02 +00:00
|
|
|
return (order >> UCOL_PRIMARYORDERSHIFT);
|
2003-04-23 04:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_secondaryOrder (int32_t order)
|
|
|
|
{
|
|
|
|
order &= UCOL_SECONDARYMASK;
|
2003-05-01 15:42:02 +00:00
|
|
|
return (order >> UCOL_SECONDARYORDERSHIFT);
|
2003-04-23 04:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_tertiaryOrder (int32_t order)
|
|
|
|
{
|
|
|
|
return (order & UCOL_TERTIARYMASK);
|
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|