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
|
|
|
|
|
|
|
#include "unicode/ucoleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
#include "unicode/sortkey.h"
|
|
|
|
#include "ucolimp.h"
|
|
|
|
#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;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = (UCollationElements *)uprv_malloc(sizeof(UCollationElements));
|
|
|
|
|
|
|
|
result->collator_ = coll;
|
|
|
|
|
|
|
|
/* gets the correct length of the null-terminated string */
|
|
|
|
if (textLength == -1)
|
|
|
|
textLength = u_strlen(text);
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
result->length_ = textLength;
|
|
|
|
init_collIterate(text, textLength, &result->iteratordata_, FALSE);
|
|
|
|
|
|
|
|
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_;
|
|
|
|
if (ci->writableBuffer != ci->stackWritableBuffer)
|
|
|
|
uprv_free(ci->writableBuffer);
|
|
|
|
if (elems->iteratordata_.isWritable && elems->iteratordata_.string != NULL)
|
|
|
|
uprv_free(elems->iteratordata_.string);
|
|
|
|
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_);
|
|
|
|
ci->pos = ci->string;
|
|
|
|
ci->len = ci->string + elems->length_;
|
|
|
|
ci->CEpos = ci->toReturn = ci->CEs;
|
|
|
|
/*
|
|
|
|
problem here, that means we'll have to keep calculating the new thai set
|
|
|
|
whenever we reset. maybe getSpecialCE should just do up the whole string
|
|
|
|
instead of only a substring of it.
|
|
|
|
*/
|
|
|
|
ci->isThai = TRUE;
|
|
|
|
if (ci->stackWritableBuffer != ci->writableBuffer)
|
|
|
|
{
|
|
|
|
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-02-20 00:26:50 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
return UCOL_NULLORDER;
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
int32_t result;
|
|
|
|
UCOL_GETNEXTCE(result, elems->collator_, elems->iteratordata_, status);
|
|
|
|
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-02-20 00:26:50 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return UCOL_NULLORDER;
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
int32_t result;
|
|
|
|
UCOL_GETPREVCE(result, elems->collator_, elems->iteratordata_,
|
|
|
|
elems->length_, status);
|
|
|
|
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-02-20 00:26:50 +00:00
|
|
|
/*
|
|
|
|
synwee : requested this implementation from vladimir, need discussion. so
|
|
|
|
hang on.
|
|
|
|
*/
|
|
|
|
/* return ((CollationElementIterator*)elems)->getMaxExpansion(order); */
|
|
|
|
return -1;
|
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-02-20 00:26:50 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* gets the correct length of the null-terminated string */
|
|
|
|
if (textLength == -1)
|
|
|
|
textLength = u_strlen(text);
|
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)
|
|
|
|
uprv_free(elems->iteratordata_.string);
|
|
|
|
init_collIterate(text, textLength, &elems->iteratordata_, FALSE);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UTextOffset
|
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
/* return ((CollationElementIterator*)elems)->getOffset(); */
|
|
|
|
const collIterate *ci = &(elems->iteratordata_);
|
|
|
|
if (ci->isThai == TRUE)
|
|
|
|
return ci->pos - ci->string;
|
|
|
|
|
|
|
|
/*
|
|
|
|
if it is a thai string with reversed elements, since getNextCE does not
|
|
|
|
store only a substring in writeablebuffer, we'll have to do some calculation
|
|
|
|
to get the offset out.
|
|
|
|
need discussion to see if it is a better idea to store the whole string
|
|
|
|
instead.
|
|
|
|
*/
|
|
|
|
return elems->length_ - (ci->len - ci->pos);
|
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-02-20 00:26:50 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
collIterate *ci = &(elems->iteratordata_);
|
|
|
|
ci->pos = ci->string + offset;
|
|
|
|
ci->CEpos = ci->toReturn = ci->CEs;
|
|
|
|
/*
|
|
|
|
problem here, that means we'll have to keep calculating the new thai set
|
|
|
|
whenever we reset. maybe getSpecialCE should just do up the whole string
|
|
|
|
instead of only a substring of it.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|