/*
*******************************************************************************
-* Copyright (C) 1996-2008, International Business Machines Corporation and *
+* Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
#include "unicode/coleitr.h"
#include "unicode/ustring.h"
#include "ucol_imp.h"
+#include "uassert.h"
#include "cmemory.h"
// the constructor and setText always sets a length
// and we only compare the string not the contents of the normalization
// buffer
- int thislength = m_data_->iteratordata_.endp -
- m_data_->iteratordata_.string;
- int thatlength = that.m_data_->iteratordata_.endp -
- that.m_data_->iteratordata_.string;
+ int thislength = (int)(m_data_->iteratordata_.endp - m_data_->iteratordata_.string);
+ int thatlength = (int)(that.m_data_->iteratordata_.endp - that.m_data_->iteratordata_.string);
if (thislength != thatlength) {
return FALSE;
}
// both are in the normalization buffer
if (m_data_->iteratordata_.pos
- - m_data_->iteratordata_.writableBuffer
+ - m_data_->iteratordata_.writableBuffer.getBuffer()
!= that.m_data_->iteratordata_.pos
- - that.m_data_->iteratordata_.writableBuffer) {
+ - that.m_data_->iteratordata_.writableBuffer.getBuffer()) {
// not in the same position in the normalization buffer
return FALSE;
}
int32_t length = source.length();
UChar *string = NULL;
if (m_data_->isWritable && m_data_->iteratordata_.string != NULL) {
- uprv_free(m_data_->iteratordata_.string);
+ uprv_free((UChar *)m_data_->iteratordata_.string);
}
m_data_->isWritable = TRUE;
if (length > 0) {
*string = 0;
}
/* Free offsetBuffer before initializing it. */
- freeOffsetBuffer(&(m_data_->iteratordata_));
+ ucol_freeOffsetBuffer(&(m_data_->iteratordata_));
uprv_init_collIterate(m_data_->iteratordata_.coll, string, length,
- &m_data_->iteratordata_);
+ &m_data_->iteratordata_, &status);
m_data_->reset_ = TRUE;
}
}
if (m_data_->isWritable && m_data_->iteratordata_.string != NULL) {
- uprv_free(m_data_->iteratordata_.string);
+ uprv_free((UChar *)m_data_->iteratordata_.string);
}
m_data_->isWritable = TRUE;
/* Free offsetBuffer before initializing it. */
- freeOffsetBuffer(&(m_data_->iteratordata_));
+ ucol_freeOffsetBuffer(&(m_data_->iteratordata_));
uprv_init_collIterate(m_data_->iteratordata_.coll, buffer, length,
- &m_data_->iteratordata_);
+ &m_data_->iteratordata_, &status);
m_data_->reset_ = TRUE;
}
// checking only UCOL_ITER_HASLEN is not enough here as we may be in
// the normalization buffer
- length = othercoliter->endp - othercoliter->string;
+ length = (int)(othercoliter->endp - othercoliter->string);
ucolelem->reset_ = otherucolelem->reset_;
ucolelem->isWritable = TRUE;
if (length > 0) {
coliter->string = (UChar *)uprv_malloc(length * U_SIZEOF_UCHAR);
if(coliter->string != NULL) {
- uprv_memcpy(coliter->string, othercoliter->string,
+ uprv_memcpy((UChar *)coliter->string, othercoliter->string,
length * U_SIZEOF_UCHAR);
} else { // Error: couldn't allocate memory. No copying should be done
length = 0;
}
/* start and end of string */
- coliter->endp = coliter->string + length;
+ coliter->endp = coliter->string == NULL ? NULL : coliter->string + length;
/* handle writable buffer here */
if (othercoliter->flags & UCOL_ITER_INNORMBUF) {
- uint32_t wlength = u_strlen(othercoliter->writableBuffer) + 1;
- if (wlength < coliter->writableBufSize) {
- uprv_memcpy(coliter->stackWritableBuffer,
- othercoliter->stackWritableBuffer,
- wlength * U_SIZEOF_UCHAR);
- }
- else {
- if (coliter->writableBuffer != coliter->stackWritableBuffer) {
- uprv_free(coliter->writableBuffer);
- }
- coliter->writableBuffer = (UChar *)uprv_malloc(
- wlength * U_SIZEOF_UCHAR);
- if(coliter->writableBuffer != NULL) {
- uprv_memcpy(coliter->writableBuffer,
- othercoliter->writableBuffer,
- wlength * U_SIZEOF_UCHAR);
- coliter->writableBufSize = wlength;
- } else { // Error: couldn't allocate memory for writableBuffer
- coliter->writableBufSize = 0;
- }
- }
+ coliter->writableBuffer = othercoliter->writableBuffer;
+ coliter->writableBuffer.getTerminatedBuffer();
}
/* current position */
if (othercoliter->pos >= othercoliter->string &&
othercoliter->pos <= othercoliter->endp)
{
+ U_ASSERT(coliter->string != NULL);
coliter->pos = coliter->string +
(othercoliter->pos - othercoliter->string);
}
- else if (coliter->writableBuffer != NULL) {
- coliter->pos = coliter->writableBuffer +
- (othercoliter->pos - othercoliter->writableBuffer);
- }
else {
- // Error: couldn't allocate memory for writableBuffer
- coliter->pos = NULL;
+ coliter->pos = coliter->writableBuffer.getTerminatedBuffer() +
+ (othercoliter->pos - othercoliter->writableBuffer.getBuffer());
}
/* CE buffer */
}
if (othercoliter->fcdPosition != NULL) {
+ U_ASSERT(coliter->string != NULL);
coliter->fcdPosition = coliter->string +
(othercoliter->fcdPosition
- othercoliter->string);