1999-08-16 21:50:52 +00:00
|
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
|
*******************************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
|
* Copyright (C) 1996-2001, International Business Machines Corporation and *
|
1999-11-22 20:25:35 +00:00
|
|
|
|
* others. All Rights Reserved. *
|
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
|
*/
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* File coleitr.cpp
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Created by: Helena Shih
|
|
|
|
|
*
|
|
|
|
|
* Modification History:
|
|
|
|
|
*
|
2001-02-20 00:26:50 +00:00
|
|
|
|
* Date Name Description
|
2001-01-30 18:52:58 +00:00
|
|
|
|
*
|
2001-02-20 00:26:50 +00:00
|
|
|
|
* 6/23/97 helena Adding comments to make code more readable.
|
|
|
|
|
* 08/03/98 erm Synched with 1.2 version of CollationElementIterator.java
|
|
|
|
|
* 12/10/99 aliu Ported Thai collation support from Java.
|
|
|
|
|
* 01/25/01 swquek Modified to a C++ wrapper calling C APIs (ucoliter.h)
|
|
|
|
|
* 02/19/01 swquek Removed CollationElementsIterator() since it is
|
|
|
|
|
* private constructor and no calls are made to it
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
#include "unicode/coleitr.h"
|
2001-03-08 17:40:42 +00:00
|
|
|
|
#include "ucol_imp.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
|
#include "cmemory.h"
|
2001-04-12 00:08:26 +00:00
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
1999-12-10 18:53:45 +00:00
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/* Constants --------------------------------------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
|
const char CollationElementIterator::fgClassID=0;
|
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/* synwee : public can't remove */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
int32_t const CollationElementIterator::NULLORDER = 0xffffffff;
|
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/* CollationElementIterator public constructor/destructor ------------------ */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
CollationElementIterator::CollationElementIterator(
|
2001-02-20 00:26:50 +00:00
|
|
|
|
const CollationElementIterator& other)
|
|
|
|
|
: isDataOwned_(TRUE)
|
2001-01-18 00:23:29 +00:00
|
|
|
|
{
|
2001-03-15 02:54:01 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-04-12 00:08:26 +00:00
|
|
|
|
m_data_ = ucol_openElements(other.m_data_->iteratordata_.coll, NULL, 0,
|
|
|
|
|
&status);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
|
|
|
|
|
/* Test for buffer overflows */
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*this = other;
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
CollationElementIterator::~CollationElementIterator()
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-03-15 02:54:01 +00:00
|
|
|
|
if (isDataOwned_) {
|
2001-02-21 01:58:55 +00:00
|
|
|
|
ucol_closeElements(m_data_);
|
2001-03-15 02:54:01 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/* CollationElementIterator public methods --------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
|
int32_t CollationElementIterator::getOffset() const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
|
return ucol_getOffset(m_data_);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the ordering priority of the next character in the string.
|
2001-02-21 01:58:55 +00:00
|
|
|
|
* @return the next character's ordering. Returns NULLORDER if an error has
|
2001-02-22 23:16:06 +00:00
|
|
|
|
* occured or if the end of string has been reached
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*/
|
|
|
|
|
int32_t CollationElementIterator::next(UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
|
return ucol_next(m_data_, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UBool CollationElementIterator::operator!=(
|
2001-02-20 00:26:50 +00:00
|
|
|
|
const CollationElementIterator& other) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return !(*this == other);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
UBool CollationElementIterator::operator==(
|
|
|
|
|
const CollationElementIterator& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-06-27 19:27:56 +00:00
|
|
|
|
UBool result = TRUE;
|
|
|
|
|
|
|
|
|
|
if (this == &that) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
2001-06-27 19:27:56 +00:00
|
|
|
|
if (m_data_ == that.m_data_) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
|
2001-06-27 19:27:56 +00:00
|
|
|
|
// option comparison
|
2001-06-28 20:42:56 +00:00
|
|
|
|
result = this->m_data_->reset_ == that.m_data_->reset_ &&
|
2001-06-27 19:27:56 +00:00
|
|
|
|
this->m_data_->iteratordata_.coll ==
|
|
|
|
|
that.m_data_->iteratordata_.coll;
|
|
|
|
|
|
|
|
|
|
int thislength = 0;
|
|
|
|
|
if (this->m_data_->iteratordata_.flags & UCOL_ITER_HASLEN) {
|
|
|
|
|
thislength = this->m_data_->iteratordata_.endp -
|
|
|
|
|
this->m_data_->iteratordata_.string;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
thislength = u_strlen(this->m_data_->iteratordata_.string);
|
|
|
|
|
}
|
|
|
|
|
int thatlength = 0;
|
|
|
|
|
if (that.m_data_->iteratordata_.endp != NULL) {
|
|
|
|
|
thatlength = that.m_data_->iteratordata_.endp -
|
|
|
|
|
that.m_data_->iteratordata_.string;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
thatlength = u_strlen(that.m_data_->iteratordata_.string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (thislength != thatlength) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = result && (uprv_memcmp(this->m_data_->iteratordata_.string,
|
|
|
|
|
that.m_data_->iteratordata_.string,
|
2002-02-07 00:18:19 +00:00
|
|
|
|
thislength * U_SIZEOF_UCHAR) == 0);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
result = result && (this->getOffset() == that.getOffset());
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
2001-06-27 19:27:56 +00:00
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the ordering priority of the previous collation element in the string.
|
|
|
|
|
* @param status the error code status.
|
2001-02-21 01:58:55 +00:00
|
|
|
|
* @return the previous element's ordering. Returns NULLORDER if an error has
|
2001-02-22 23:16:06 +00:00
|
|
|
|
* occured or if the start of string has been reached.
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*/
|
|
|
|
|
int32_t CollationElementIterator::previous(UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
|
return ucol_previous(m_data_, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:23:29 +00:00
|
|
|
|
* Resets the cursor to the beginning of the string.
|
|
|
|
|
*/
|
|
|
|
|
void CollationElementIterator::reset()
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
|
ucol_reset(m_data_);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
|
void CollationElementIterator::setOffset(int32_t newOffset,
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-02-20 00:26:50 +00:00
|
|
|
|
ucol_setOffset(m_data_, newOffset, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the source to the new source string.
|
|
|
|
|
*/
|
|
|
|
|
void CollationElementIterator::setText(const UnicodeString& source,
|
|
|
|
|
UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-04-12 00:08:26 +00:00
|
|
|
|
if (U_FAILURE(status)) {
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return;
|
2001-04-12 00:08:26 +00:00
|
|
|
|
}
|
2002-02-28 01:42:40 +00:00
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
int32_t length = source.length();
|
2001-06-20 18:14:51 +00:00
|
|
|
|
UChar *string = NULL;
|
|
|
|
|
if (m_data_->isWritable && m_data_->iteratordata_.string != NULL) {
|
2001-02-20 00:26:50 +00:00
|
|
|
|
uprv_free(m_data_->iteratordata_.string);
|
2001-04-12 00:08:26 +00:00
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
m_data_->isWritable = TRUE;
|
2001-06-20 18:14:51 +00:00
|
|
|
|
if (length > 0) {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
string = (UChar *)uprv_malloc(U_SIZEOF_UCHAR * length);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (string == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-02-07 00:18:19 +00:00
|
|
|
|
u_memcpy(string, source.getBuffer(), length);
|
2001-06-20 18:14:51 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
string = (UChar *)uprv_malloc(U_SIZEOF_UCHAR);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (string == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
*string = 0;
|
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
init_collIterate(m_data_->iteratordata_.coll, string, length,
|
|
|
|
|
&m_data_->iteratordata_);
|
2001-06-26 17:41:10 +00:00
|
|
|
|
|
|
|
|
|
m_data_->reset_ = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
// Sets the source to the new character iterator.
|
|
|
|
|
void CollationElementIterator::setText(CharacterIterator& source,
|
|
|
|
|
UErrorCode& status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
int32_t length = source.getLength();
|
2001-06-20 18:14:51 +00:00
|
|
|
|
UChar *buffer = NULL;
|
|
|
|
|
|
|
|
|
|
if (length == 0) {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
buffer = (UChar *)uprv_malloc(U_SIZEOF_UCHAR);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (buffer == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
*buffer = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
buffer = (UChar *)uprv_malloc(U_SIZEOF_UCHAR * length);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (buffer == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
/*
|
|
|
|
|
Using this constructor will prevent buffer from being removed when
|
|
|
|
|
string gets removed
|
|
|
|
|
*/
|
|
|
|
|
UnicodeString string;
|
|
|
|
|
source.getText(string);
|
2002-02-07 00:18:19 +00:00
|
|
|
|
u_memcpy(buffer, string.getBuffer(), length);
|
2001-06-20 18:14:51 +00:00
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
|
|
|
|
|
if (m_data_->isWritable && m_data_->iteratordata_.string != NULL)
|
2001-02-20 00:26:50 +00:00
|
|
|
|
uprv_free(m_data_->iteratordata_.string);
|
2001-04-06 23:37:48 +00:00
|
|
|
|
m_data_->isWritable = TRUE;
|
2001-04-12 00:08:26 +00:00
|
|
|
|
init_collIterate(m_data_->iteratordata_.coll, buffer, length,
|
|
|
|
|
&m_data_->iteratordata_);
|
2001-06-26 17:41:10 +00:00
|
|
|
|
m_data_->reset_ = TRUE;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
int32_t CollationElementIterator::strengthOrder(int32_t order) const
|
|
|
|
|
{
|
2001-03-15 02:54:01 +00:00
|
|
|
|
UCollationStrength s = ucol_getStrength(m_data_->iteratordata_.coll);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
// Mask off the unwanted differences.
|
2001-02-20 00:26:50 +00:00
|
|
|
|
if (s == UCOL_PRIMARY)
|
2001-01-18 00:23:29 +00:00
|
|
|
|
order &= RuleBasedCollator::PRIMARYDIFFERENCEONLY;
|
|
|
|
|
else
|
2001-02-20 00:26:50 +00:00
|
|
|
|
if (s == UCOL_SECONDARY)
|
2001-01-18 00:23:29 +00:00
|
|
|
|
order &= RuleBasedCollator::SECONDARYDIFFERENCEONLY;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return order;
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/* CollationElementIterator private constructors/destructors --------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* This is the "real" constructor for this class; it constructs an iterator
|
|
|
|
|
* over the source text using the specified collator
|
|
|
|
|
*/
|
|
|
|
|
CollationElementIterator::CollationElementIterator(
|
2001-02-21 01:58:55 +00:00
|
|
|
|
const UnicodeString& sourceText,
|
|
|
|
|
const RuleBasedCollator* order,
|
|
|
|
|
UErrorCode& status)
|
|
|
|
|
: isDataOwned_(TRUE)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
2001-02-20 00:26:50 +00:00
|
|
|
|
|
2001-02-21 01:58:55 +00:00
|
|
|
|
int32_t length = sourceText.length();
|
2001-05-25 21:58:49 +00:00
|
|
|
|
UChar *string = NULL;
|
|
|
|
|
|
|
|
|
|
if (length > 0) {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
string = (UChar *)uprv_malloc(U_SIZEOF_UCHAR * length);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (string == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-05-25 21:58:49 +00:00
|
|
|
|
/*
|
|
|
|
|
Using this constructor will prevent buffer from being removed when
|
|
|
|
|
string gets removed
|
|
|
|
|
*/
|
2002-02-07 00:18:19 +00:00
|
|
|
|
u_memcpy(string, sourceText.getBuffer(), length);
|
2001-05-25 21:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
string = (UChar *)uprv_malloc(U_SIZEOF_UCHAR);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (string == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-05-25 21:58:49 +00:00
|
|
|
|
*string = 0;
|
|
|
|
|
}
|
2001-02-21 01:58:55 +00:00
|
|
|
|
m_data_ = ucol_openElements(order->ucollator, string, length, &status);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
|
|
|
|
|
/* Test for buffer overflows */
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
m_data_->isWritable = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* This is the "real" constructor for this class; it constructs an iterator over
|
|
|
|
|
* the source text using the specified collator
|
|
|
|
|
*/
|
|
|
|
|
CollationElementIterator::CollationElementIterator(
|
2001-02-20 00:26:50 +00:00
|
|
|
|
const CharacterIterator& sourceText,
|
|
|
|
|
const RuleBasedCollator* order,
|
|
|
|
|
UErrorCode& status)
|
|
|
|
|
: isDataOwned_(TRUE)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// **** should I just drop this test? ****
|
2001-02-20 00:26:50 +00:00
|
|
|
|
/*
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if ( sourceText.endIndex() != 0 )
|
|
|
|
|
{
|
|
|
|
|
// A CollationElementIterator is really a two-layered beast.
|
|
|
|
|
// Internally it uses a Normalizer to munge the source text into a form
|
|
|
|
|
// where all "composed" Unicode characters (such as <20>) are split into a
|
|
|
|
|
// normal character and a combining accent character.
|
|
|
|
|
// Afterward, CollationElementIterator does its own processing to handle
|
|
|
|
|
// expanding and contracting collation sequences, ignorables, and so on.
|
|
|
|
|
|
|
|
|
|
Normalizer::EMode decomp = order->getStrength() == Collator::IDENTICAL
|
|
|
|
|
? Normalizer::NO_OP : order->getDecomposition();
|
|
|
|
|
|
|
|
|
|
text = new Normalizer(sourceText, decomp);
|
|
|
|
|
if (text == NULL)
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
*/
|
|
|
|
|
int32_t length = sourceText.getLength();
|
2001-06-20 18:14:51 +00:00
|
|
|
|
UChar *buffer;
|
|
|
|
|
if (length > 0) {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
buffer = (UChar *)uprv_malloc(U_SIZEOF_UCHAR * length);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (buffer == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
/*
|
|
|
|
|
Using this constructor will prevent buffer from being removed when
|
|
|
|
|
string gets removed
|
|
|
|
|
*/
|
|
|
|
|
UnicodeString string(buffer, length, length);
|
|
|
|
|
((CharacterIterator &)sourceText).getText(string);
|
2002-02-07 00:18:19 +00:00
|
|
|
|
const UChar *temp = string.getBuffer();
|
|
|
|
|
u_memcpy(buffer, temp, length);
|
2001-06-20 18:14:51 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
buffer = (UChar *)uprv_malloc(U_SIZEOF_UCHAR);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
|
if (buffer == 0) {
|
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
*buffer = 0;
|
|
|
|
|
}
|
2001-02-21 01:58:55 +00:00
|
|
|
|
m_data_ = ucol_openElements(order->ucollator, buffer, length, &status);
|
2002-07-02 15:10:30 +00:00
|
|
|
|
|
|
|
|
|
/* Test for buffer overflows */
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
m_data_->isWritable = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
|
/* CollationElementIterator protected methods ----------------------------- */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
const CollationElementIterator& CollationElementIterator::operator=(
|
2001-02-20 00:26:50 +00:00
|
|
|
|
const CollationElementIterator& other)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (this != &other)
|
|
|
|
|
{
|
2001-04-12 00:08:26 +00:00
|
|
|
|
UCollationElements *ucolelem = this->m_data_;
|
|
|
|
|
UCollationElements *otherucolelem = other.m_data_;
|
|
|
|
|
collIterate *coliter = &(ucolelem->iteratordata_);
|
|
|
|
|
collIterate *othercoliter = &(otherucolelem->iteratordata_);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
int length = 0;
|
|
|
|
|
|
|
|
|
|
// checking only UCOL_ITER_HASLEN is not enough here as we may be in
|
|
|
|
|
// the normalization buffer
|
|
|
|
|
if (othercoliter->endp != NULL) {
|
|
|
|
|
length = othercoliter->endp - othercoliter->string;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (othercoliter->string == NULL) {
|
|
|
|
|
length = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
length = u_strlen(othercoliter->string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
|
ucolelem->reset_ = otherucolelem->reset_;
|
|
|
|
|
ucolelem->isWritable = TRUE;
|
2001-03-15 02:54:01 +00:00
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
|
/* create a duplicate of string */
|
2001-06-27 19:27:56 +00:00
|
|
|
|
if (length > 0) {
|
2002-02-07 00:18:19 +00:00
|
|
|
|
coliter->string = (UChar *)uprv_malloc(length * U_SIZEOF_UCHAR);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
uprv_memcpy(coliter->string, othercoliter->string,
|
2002-02-07 00:18:19 +00:00
|
|
|
|
length * U_SIZEOF_UCHAR);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
coliter->string = NULL;
|
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
|
|
|
|
|
/* start and end of string */
|
2001-06-27 19:27:56 +00:00
|
|
|
|
coliter->endp = coliter->string + length;
|
2001-04-12 00:08:26 +00:00
|
|
|
|
|
|
|
|
|
/* handle writable buffer here */
|
2001-06-27 19:27:56 +00:00
|
|
|
|
|
|
|
|
|
if (othercoliter->flags & UCOL_ITER_INNORMBUF) {
|
|
|
|
|
uint32_t wlength = u_strlen(othercoliter->writableBuffer) + 1;
|
|
|
|
|
if (wlength < coliter->writableBufSize) {
|
|
|
|
|
uprv_memcpy(coliter->stackWritableBuffer,
|
|
|
|
|
othercoliter->stackWritableBuffer,
|
2002-02-07 00:18:19 +00:00
|
|
|
|
othercoliter->writableBufSize * U_SIZEOF_UCHAR);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (coliter->writableBuffer != coliter->stackWritableBuffer) {
|
|
|
|
|
delete coliter->writableBuffer;
|
|
|
|
|
}
|
|
|
|
|
coliter->writableBuffer = (UChar *)uprv_malloc(
|
2002-02-07 00:18:19 +00:00
|
|
|
|
wlength * U_SIZEOF_UCHAR);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
uprv_memcpy(coliter->writableBuffer,
|
|
|
|
|
othercoliter->writableBuffer,
|
2002-02-07 00:18:19 +00:00
|
|
|
|
wlength * U_SIZEOF_UCHAR);
|
2001-06-27 19:27:56 +00:00
|
|
|
|
coliter->writableBufSize = wlength;
|
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* current position */
|
|
|
|
|
if (othercoliter->pos >= othercoliter->string &&
|
|
|
|
|
othercoliter->pos <= othercoliter->endp) {
|
|
|
|
|
coliter->pos = coliter->string +
|
|
|
|
|
(othercoliter->pos - othercoliter->string);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
coliter->pos = coliter->writableBuffer +
|
|
|
|
|
(othercoliter->pos - othercoliter->writableBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* CE buffer */
|
|
|
|
|
uprv_memcpy(coliter->CEs, othercoliter->CEs,
|
|
|
|
|
UCOL_EXPAND_CE_BUFFER_SIZE * sizeof(uint32_t));
|
|
|
|
|
coliter->toReturn = coliter->CEs +
|
|
|
|
|
(othercoliter->toReturn - othercoliter->CEs);
|
|
|
|
|
coliter->CEpos = othercoliter->CEs +
|
|
|
|
|
(othercoliter->CEpos - othercoliter->CEs);
|
|
|
|
|
|
|
|
|
|
coliter->fcdPosition = coliter->string +
|
|
|
|
|
(othercoliter->fcdPosition - othercoliter->string);
|
|
|
|
|
coliter->flags = othercoliter->flags | UCOL_ITER_HASLEN;
|
|
|
|
|
coliter->origFlags = othercoliter->origFlags;
|
|
|
|
|
coliter->coll = othercoliter->coll;
|
|
|
|
|
this->isDataOwned_ = TRUE;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return *this;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
|
U_NAMESPACE_END
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
|
/* eof */
|