NO_MORE_CES added to public access.
Comments of use added.

X-SVN-Rev: 3701
This commit is contained in:
Syn Wee Quek 2001-02-21 01:58:55 +00:00
parent 398b3b6a2e
commit 1418000403
4 changed files with 106 additions and 27 deletions

View file

@ -41,6 +41,7 @@
/* synwee : public can't remove */
int32_t const CollationElementIterator::NULLORDER = 0xffffffff;
// int32_t const CollationElementIterator::UNMAPPEDCHARVALUE = 0x7fff0000;
int32_t const CollationElementIterator::NO_MORE_CES = 0x00010101;
/* CollationElementIterator public constructor/destructor ------------------ */
@ -53,7 +54,8 @@ CollationElementIterator::CollationElementIterator(
CollationElementIterator::~CollationElementIterator()
{
ucol_closeElements(m_data_);
if (isDataOwned_)
ucol_closeElements(m_data_);
}
/* CollationElementIterator public methods --------------------------------- */
@ -65,8 +67,9 @@ UTextOffset CollationElementIterator::getOffset() const
/**
* Get the ordering priority of the next character in the string.
* @return the next character's ordering. Returns NULLORDER if the end of string
* is reached.
* @return the next character's ordering. Returns NULLORDER if an error has
* occured otherwise if the end of string has been reached,
* NO_MORE_CES is returned.
*/
int32_t CollationElementIterator::next(UErrorCode& status)
{
@ -186,8 +189,9 @@ UBool CollationElementIterator::operator==(
/**
* Get the ordering priority of the previous collation element in the string.
* @param status the error code status.
* @return the previous element's ordering. Returns NULLORDER if the beginning of
* string is reached.
* @return the previous element's ordering. Returns NULLORDER if an error has
* occured otherwise if the start of string has been reached,
* NO_MORE_CES is returned.
*/
int32_t CollationElementIterator::previous(UErrorCode& status)
{
@ -342,7 +346,7 @@ void CollationElementIterator::setText(CharacterIterator& source,
Using this constructor will prevent buffer from being removed when
string gets removed
*/
UnicodeString string(buffer, length, length);
UnicodeString string;
source.getText(string);
string.extract(0, length, buffer);
m_data_->length_ = length;
@ -388,9 +392,10 @@ CollationElementIterator::CollationElementIterator(
* over the source text using the specified collator
*/
CollationElementIterator::CollationElementIterator(
const UnicodeString& sourceText,
const RuleBasedCollator* order,
UErrorCode& status)
const UnicodeString& sourceText,
const RuleBasedCollator* order,
UErrorCode& status)
: isDataOwned_(TRUE)
{
if (U_FAILURE(status))
return;
@ -413,7 +418,16 @@ CollationElementIterator::CollationElementIterator(
status = U_MEMORY_ALLOCATION_ERROR;
}
*/
m_data_ = ucol_openElements(order->ucollator, NULL, 0, &status);
int32_t length = sourceText.length();
UChar *string = new UChar[length];
/*
Using this constructor will prevent buffer from being removed when
string gets removed
*/
sourceText.extract(0, length, string);
m_data_ = ucol_openElements(order->ucollator, string, length, &status);
m_data_->iteratordata_.isWritable = TRUE;
}
/**
@ -455,11 +469,11 @@ CollationElementIterator::CollationElementIterator(
string gets removed
*/
UnicodeString string(buffer, length, length);
// synwee sourceText.getText(string);
((CharacterIterator &)sourceText).getText(string);
string.extract(0, length, buffer);
m_data_ = ucol_openElements(order->ucollator, NULL, 0, &status);
// synwee ucol_setText(m_data_, buffer, length, TRUE, &status);
m_data_ = ucol_openElements(order->ucollator, buffer, length, &status);
m_data_->iteratordata_.isWritable = TRUE;
}
/* CollationElementIterator private methods -------------------------------- */
@ -494,7 +508,8 @@ const CollationElementIterator& CollationElementIterator::operator=(
orderAlias = other.orderAlias;
*/
this->m_data_ = other.m_data_;
this->m_data_ = other.m_data_;
this->isDataOwned_ = FALSE;
}
return *this;

View file

@ -113,8 +113,56 @@ ucol_previous(UCollationElements *elems,
return UCOL_NULLORDER;
int32_t result;
UCOL_GETPREVCE(result, elems->collator_, elems->iteratordata_,
elems->length_, status);
/* UCOL_GETPREVCE(result, elems->collator_, elems->iteratordata_,
elems->length_, status); */
/* synwee : to be removed, only for testing */
const UCollator *coll = elems->collator_;
collIterate *data = &(elems->iteratordata_);
int32_t length = elems->length_;
if (data->CEpos > data->CEs)
{
(result) = *(data->toReturn --);
if (data->CEs == data->toReturn)
data->CEpos = data->toReturn = data->CEs;
}
else
{
/*
pointers are always at the next position to be retrieved for getnextce
for every first previous step after a next, value returned will the same
as the last next value
*/
if (data->len - data->pos == length)
(result) = UCOL_NO_MORE_CES;
else
{
if (data->pos != data->writableBuffer)
data->pos --;
else
{
data->pos = data->string +
(length - (data->len - data->writableBuffer));
data->len = data->string + length;
data->isThai = TRUE;
}
UChar ch = *(data->pos);
if (ch <= 0xFF)
(result) = (coll)->latinOneMapping[ch];
else
(result) = ucmp32_get((coll)->mapping, ch);
if ((result) >= UCOL_NOT_FOUND)
{
(result) = getSpecialPrevCE(coll, result, data, length, status);
if ((result) == UCOL_NOT_FOUND)
(result) = ucol_getPrevUCA(ch, data, length, status);
}
}
}
return result;
}
@ -195,3 +243,4 @@ ucol_setOffset(UCollationElements *elems,

View file

@ -108,9 +108,15 @@ public:
// CollationElementIterator public data member ------------------------------
/**
* NULLORDER indicates the iterator has consumed the last element.
* NULLORDER indicates that an error has occured while processing
*/
static int32_t const NULLORDER;
static int32_t const NULLORDER;
/**
* NO_MORE_CES indicates that the iterator has consumed the last element.
* Constant is actually the bitwise seperator of the collation elements.
*/
static int32_t const NO_MORE_CES;
// CollationElementIterator public constructor/destructor -------------------
@ -144,16 +150,18 @@ public:
/**
* Gets the ordering priority of the next character in the string.
* @param status the error code status.
* @return the next character's ordering. NULLORDER returned if the end of
* string is reached.
* @return the next character's ordering. otherwise returns NULLORDER if an
* error has occured or NO_MORE_CES if the end of string has been
* reached
*/
int32_t next(UErrorCode& status);
/**
* Get the ordering priority of the previous collation element in the string.
* @param status the error code status.
* @return the previous element's ordering. NULLORDER returned if the beginning
* of string is reached.
* @return the previous element's ordering. otherwise returns NULLORDER if an
* error has occured or NO_MORE_CES if the start of string has been
* reached
*/
int32_t previous(UErrorCode& status);

View file

@ -17,9 +17,14 @@
#define UCOLEITR_H
/**
* This indicates the last element in a UCollationElements has been consumed.
* This indicates an error has occured during processing.
*/
#define UCOL_NULLORDER 0xFFFFFFFF
/*
* End or start of the of string has been reached, hence there's no more
* collation element to be retrieved.
*/
#define UCOL_NO_MORE_CES 0x00010101
#include "unicode/ucol.h"
@ -124,8 +129,9 @@ ucol_reset(UCollationElements *elems);
* A single character may contain more than one collation element.
* @param elems The UCollationElements containing the text.
* @param status A pointer to an UErrorCode to receive any errors.
* @return The next collation elements ordering, or \Ref{UCOL_NULLORDER} if
* the end of the text is reached.
* @return The next collation elements ordering, otherwise returns NULLORDER
* if an error has occured or NO_MORE_CES if the end of string has
* been reached
*/
U_CAPI int32_t
ucol_next(UCollationElements *elems, UErrorCode *status);
@ -135,8 +141,9 @@ ucol_next(UCollationElements *elems, UErrorCode *status);
* A single character may contain more than one collation element.
* @param elems The UCollationElements containing the text.
* @param status A pointer to an UErrorCode to receive any errors.
* @return The previous collation elements ordering, or \Ref{UCOL_NULLORDER}
* if the end of the text is reached.
* @return The previous collation elements ordering, otherwise returns
* NULLORDER if an error has occured or NO_MORE_CES if the start of
* string has been reached
*/
U_CAPI int32_t
ucol_previous(UCollationElements *elems, UErrorCode *status);