2001-01-15 19:02:30 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************
|
2001-01-15 19:02:30 +00:00
|
|
|
* Copyright (C) 2001, International Business Machines
|
|
|
|
* 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
|
|
|
|
2001-03-12 08:58:37 +00:00
|
|
|
#include <stdio.h>
|
2001-01-15 19:02:30 +00:00
|
|
|
#include "unicode/ucoleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
#include "unicode/sortkey.h"
|
2001-03-08 17:40:42 +00:00
|
|
|
#include "ucol_imp.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
|
|
|
|
#define BUFFER_LENGTH 100
|
|
|
|
|
|
|
|
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-02-20 00:26:50 +00:00
|
|
|
/**
|
|
|
|
* Since this is going to be deprecated, I'll leave it as it is
|
|
|
|
*/
|
2001-01-15 19:02:30 +00:00
|
|
|
U_CAPI int32_t
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_keyHashCode(const uint8_t *key,
|
|
|
|
int32_t length)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
|
|
|
CollationKey newKey(key, length);
|
|
|
|
return newKey.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UCollationElements*
|
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));
|
|
|
|
|
|
|
|
/* gets the correct length of the null-terminated string */
|
2001-03-07 21:01:53 +00:00
|
|
|
if (textLength == -1) {
|
2001-02-20 00:26:50 +00:00
|
|
|
textLength = u_strlen(text);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
result->length_ = textLength;
|
2001-02-23 23:36:42 +00:00
|
|
|
result->reset_ = TRUE;
|
2001-03-15 02:54:01 +00:00
|
|
|
result->normalization_ = UNORM_DEFAULT;
|
|
|
|
|
2001-03-09 00:50:37 +00:00
|
|
|
init_collIterate(coll, text, textLength, &result->iteratordata_, FALSE);
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
return result;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
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-02-20 00:26:50 +00:00
|
|
|
if (elems->iteratordata_.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-02-20 00:26:50 +00:00
|
|
|
uprv_free(elems);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
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-03-12 20:05:46 +00:00
|
|
|
ci->start = ci->string;
|
2001-02-20 00:26:50 +00:00
|
|
|
ci->pos = ci->string;
|
|
|
|
ci->len = ci->string + elems->length_;
|
|
|
|
ci->CEpos = ci->toReturn = ci->CEs;
|
2001-03-03 04:06:43 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
ci->isThai = TRUE;
|
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-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_next(UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2001-03-15 19:10:41 +00:00
|
|
|
uint32_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
|
|
|
|
2001-03-09 18:25:30 +00:00
|
|
|
#ifdef _DEBUG
|
2001-02-22 23:16:06 +00:00
|
|
|
if ((elems->iteratordata_).CEpos > (elems->iteratordata_).toReturn)
|
2001-02-23 23:36:42 +00:00
|
|
|
{
|
|
|
|
result = *((elems->iteratordata_).toReturn++);
|
|
|
|
if ((elems->iteratordata_).CEpos == (elems->iteratordata_).toReturn)
|
|
|
|
(elems->iteratordata_).CEpos = (elems->iteratordata_).toReturn =
|
|
|
|
(elems->iteratordata_).CEs;
|
2001-02-22 23:16:06 +00:00
|
|
|
}
|
2001-02-23 23:36:42 +00:00
|
|
|
else
|
|
|
|
if ((elems->iteratordata_).pos < (elems->iteratordata_).len)
|
|
|
|
{
|
|
|
|
UChar ch = *(elems->iteratordata_).pos++;
|
|
|
|
if (ch <= 0xFF)
|
2001-03-15 02:54:01 +00:00
|
|
|
(result) = (elems->iteratordata_.coll)->latinOneMapping[ch];
|
2001-02-23 23:36:42 +00:00
|
|
|
else
|
2001-03-15 02:54:01 +00:00
|
|
|
(result) = ucmp32_get((elems->iteratordata_.coll)->mapping, ch);
|
2001-02-23 23:36:42 +00:00
|
|
|
|
|
|
|
if((result) >= UCOL_NOT_FOUND)
|
|
|
|
{
|
2001-03-15 02:54:01 +00:00
|
|
|
(result) = getSpecialCE((elems->iteratordata_.coll), (result),
|
2001-02-23 23:36:42 +00:00
|
|
|
&(elems->iteratordata_), (status));
|
|
|
|
if ((result) == UCOL_NOT_FOUND)
|
|
|
|
(result) = ucol_getNextUCA(ch, &(elems->iteratordata_), (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(result) = UCOL_NO_MORE_CES;
|
2001-03-09 18:25:30 +00:00
|
|
|
#else
|
2001-03-15 02:54:01 +00:00
|
|
|
UCOL_GETNEXTCE(result, elems->iteratordata_.coll, elems->iteratordata_, status);
|
2001-03-07 21:01:53 +00:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
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
|
|
|
|
{
|
2001-03-15 19:10:41 +00:00
|
|
|
uint32_t result;
|
2001-02-23 23:36:42 +00:00
|
|
|
|
|
|
|
if (elems->reset_ &&
|
|
|
|
(elems->iteratordata_.pos == elems->iteratordata_.string))
|
|
|
|
elems->iteratordata_.pos = elems->iteratordata_.len;
|
|
|
|
|
|
|
|
elems->reset_ = FALSE;
|
|
|
|
|
2001-03-09 18:25:30 +00:00
|
|
|
#ifdef _DEBUG
|
2001-03-15 02:54:01 +00:00
|
|
|
const UCollator *coll = elems->iteratordata_.coll;
|
2001-02-23 23:36:42 +00:00
|
|
|
collIterate *data = &(elems->iteratordata_);
|
|
|
|
int32_t length = elems->length_;
|
|
|
|
|
|
|
|
if (data->CEpos > data->CEs)
|
|
|
|
{
|
|
|
|
data->toReturn --;
|
|
|
|
(result) = *(data->toReturn);
|
|
|
|
if (data->CEs == data->toReturn)
|
|
|
|
data->CEpos = data->toReturn = data->CEs;
|
|
|
|
}
|
2001-02-21 01:58:55 +00:00
|
|
|
else
|
2001-02-23 23:36:42 +00:00
|
|
|
{
|
2001-03-12 20:05:46 +00:00
|
|
|
if (data->pos == data->start) {
|
|
|
|
if (data->pos < data->start) {
|
2001-03-12 08:58:37 +00:00
|
|
|
fprintf(stderr, "less pos:%x string:%x writable:%x\n", data->pos, data->string, data->writableBuffer);
|
2001-03-12 20:05:46 +00:00
|
|
|
}
|
2001-02-23 23:36:42 +00:00
|
|
|
(result) = UCOL_NO_MORE_CES;
|
2001-03-12 20:05:46 +00:00
|
|
|
}
|
|
|
|
else
|
2001-02-23 23:36:42 +00:00
|
|
|
{
|
|
|
|
data->pos --;
|
|
|
|
|
|
|
|
UChar ch = *(data->pos);
|
|
|
|
if (ch <= 0xFF)
|
|
|
|
(result) = (coll)->latinOneMapping[ch];
|
2001-03-09 18:25:30 +00:00
|
|
|
else {
|
2001-03-12 20:05:46 +00:00
|
|
|
if (data->isThai && UCOL_ISTHAIBASECONSONANT(ch) && data->pos > data->start
|
|
|
|
&& UCOL_ISTHAIPREVOWEL(*(data->pos -1))) {
|
2001-03-09 18:25:30 +00:00
|
|
|
result = UCOL_THAI;
|
2001-03-12 20:05:46 +00:00
|
|
|
}
|
2001-03-09 18:25:30 +00:00
|
|
|
else {
|
|
|
|
(result) = ucmp32_get((coll)->mapping, ch);
|
2001-03-12 20:05:46 +00:00
|
|
|
}
|
2001-03-09 18:25:30 +00:00
|
|
|
}
|
2001-02-21 01:58:55 +00:00
|
|
|
|
2001-02-23 23:36:42 +00:00
|
|
|
if ((result) >= UCOL_NOT_FOUND)
|
|
|
|
{
|
|
|
|
(result) = getSpecialPrevCE(coll, result, data, length, status);
|
|
|
|
if ((result) == UCOL_NOT_FOUND)
|
|
|
|
(result) = ucol_getPrevUCA(ch, data, length, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 18:25:30 +00:00
|
|
|
#else
|
2001-03-15 02:54:01 +00:00
|
|
|
UCOL_GETPREVCE(result, elems->iteratordata_.coll, elems->iteratordata_,
|
2001-03-09 18:25:30 +00:00
|
|
|
elems->length_, status);
|
2001-03-07 21:01:53 +00:00
|
|
|
#endif
|
2001-02-23 23:36:42 +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
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
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-01-15 19:02:30 +00:00
|
|
|
U_CAPI void
|
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-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
/* gets the correct length of the null-terminated string */
|
2001-03-07 21:01:53 +00:00
|
|
|
if (textLength == -1) {
|
2001-02-20 00:26:50 +00:00
|
|
|
textLength = u_strlen(text);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
elems->length_ = textLength;
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
if (elems->iteratordata_.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-03-15 02:54:01 +00:00
|
|
|
init_collIterate(elems->iteratordata_.coll, text, textLength, &elems->iteratordata_, FALSE);
|
2001-03-03 04:06:43 +00:00
|
|
|
|
|
|
|
elems->reset_ = TRUE;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UTextOffset
|
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
const collIterate *ci = &(elems->iteratordata_);
|
2001-03-12 20:05:46 +00:00
|
|
|
return ci->pos - ci->start;
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_setOffset(UCollationElements *elems,
|
|
|
|
UTextOffset offset,
|
|
|
|
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-03-12 20:05:46 +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;
|
|
|
|
ci->isThai = TRUE;
|
|
|
|
if (ci->stackWritableBuffer != ci->writableBuffer)
|
|
|
|
{
|
|
|
|
uprv_free(ci->writableBuffer);
|
|
|
|
ci->writableBuffer = ci->stackWritableBuffer;
|
|
|
|
}
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-02-21 01:58:55 +00:00
|
|
|
|