ICU-4092 Increase code coverage by merging redundant lines,
and properly cleanup when there is an error. X-SVN-Rev: 17012
This commit is contained in:
parent
6c0562fc29
commit
068cfc80be
@ -102,24 +102,24 @@ CanonicalIterator::~CanonicalIterator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CanonicalIterator::cleanPieces() {
|
void CanonicalIterator::cleanPieces() {
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
if(pieces != NULL) {
|
if(pieces != NULL) {
|
||||||
for(i = 0; i < pieces_length; i++) {
|
for(i = 0; i < pieces_length; i++) {
|
||||||
if(pieces[i] != NULL) {
|
if(pieces[i] != NULL) {
|
||||||
delete[] pieces[i];
|
delete[] pieces[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
uprv_free(pieces);
|
||||||
|
pieces = NULL;
|
||||||
|
if(pieces_lengths != NULL) {
|
||||||
|
uprv_free(pieces_lengths);
|
||||||
|
}
|
||||||
|
pieces_lengths = NULL;
|
||||||
|
if(current != NULL) {
|
||||||
|
uprv_free(current);
|
||||||
|
}
|
||||||
|
current = NULL;
|
||||||
}
|
}
|
||||||
uprv_free(pieces);
|
|
||||||
pieces = NULL;
|
|
||||||
if(pieces_lengths != NULL) {
|
|
||||||
uprv_free(pieces_lengths);
|
|
||||||
}
|
|
||||||
pieces_lengths = NULL;
|
|
||||||
if(current != NULL) {
|
|
||||||
uprv_free(current);
|
|
||||||
}
|
|
||||||
current = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,6 +180,12 @@ UnicodeString CanonicalIterator::next() {
|
|||||||
* while changing the source string, saving object creation.
|
* while changing the source string, saving object creation.
|
||||||
*/
|
*/
|
||||||
void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &status) {
|
void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &status) {
|
||||||
|
int32_t list_length = 0;
|
||||||
|
UChar32 cp = 0;
|
||||||
|
int32_t start = 0;
|
||||||
|
int32_t i = 0;
|
||||||
|
UnicodeString *list = NULL;
|
||||||
|
|
||||||
Normalizer::normalize(newSource, UNORM_NFD, 0, source, status);
|
Normalizer::normalize(newSource, UNORM_NFD, 0, source, status);
|
||||||
if(U_FAILURE(status)) {
|
if(U_FAILURE(status)) {
|
||||||
return;
|
return;
|
||||||
@ -202,48 +208,37 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (current == NULL) {
|
if (current == NULL) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
uprv_free(pieces);
|
goto CleanPartialInitialization;
|
||||||
pieces = NULL;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
current[0] = 0;
|
current[0] = 0;
|
||||||
pieces[0] = new UnicodeString[1];
|
pieces[0] = new UnicodeString[1];
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (pieces[0] == 0) {
|
if (pieces[0] == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
uprv_free(pieces);
|
goto CleanPartialInitialization;
|
||||||
pieces = NULL;
|
|
||||||
uprv_free(current);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
pieces[0][0] = UnicodeString();
|
pieces[0][0] = UnicodeString();
|
||||||
pieces_lengths = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
|
pieces_lengths = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (pieces_lengths == 0) {
|
if (pieces_lengths == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
uprv_free(pieces);
|
goto CleanPartialInitialization;
|
||||||
pieces = NULL;
|
|
||||||
uprv_free(current);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
pieces_lengths[0] = 1;
|
pieces_lengths[0] = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UnicodeString *list = new UnicodeString[source.length()];
|
list = new UnicodeString[source.length()];
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (list == 0) {
|
if (list == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
return;
|
goto CleanPartialInitialization;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t list_length = 0;
|
|
||||||
UChar32 cp = 0;
|
|
||||||
int32_t start = 0;
|
|
||||||
// i should initialy be the number of code units at the
|
// i should initialy be the number of code units at the
|
||||||
// start of the string
|
// start of the string
|
||||||
int32_t i = UTF16_CHAR_LENGTH(source.char32At(0));
|
i = UTF16_CHAR_LENGTH(source.char32At(0));
|
||||||
//int32_t i = 1;
|
//int32_t i = 1;
|
||||||
// find the segments
|
// find the segments
|
||||||
// This code iterates through the source string and
|
// This code iterates through the source string and
|
||||||
@ -265,18 +260,14 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (pieces == NULL) {
|
if (pieces == NULL) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
delete[] list;
|
goto CleanPartialInitialization;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
pieces_length = list_length;
|
pieces_length = list_length;
|
||||||
pieces_lengths = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
|
pieces_lengths = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
|
||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (pieces_lengths == 0) {
|
if (pieces_lengths == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
delete[] list;
|
goto CleanPartialInitialization;
|
||||||
uprv_free(pieces);
|
|
||||||
pieces = NULL;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_length = list_length;
|
current_length = list_length;
|
||||||
@ -284,11 +275,7 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||||||
/* test for NULL */
|
/* test for NULL */
|
||||||
if (current == 0) {
|
if (current == 0) {
|
||||||
status = U_MEMORY_ALLOCATION_ERROR;
|
status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
delete[] list;
|
goto CleanPartialInitialization;
|
||||||
uprv_free(pieces);
|
|
||||||
pieces = NULL;
|
|
||||||
uprv_free(pieces_lengths);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < current_length; i++) {
|
for (i = 0; i < current_length; i++) {
|
||||||
current[i] = 0;
|
current[i] = 0;
|
||||||
@ -301,6 +288,24 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete[] list;
|
delete[] list;
|
||||||
|
return;
|
||||||
|
// Common section to cleanup all local variables and reset object variables.
|
||||||
|
CleanPartialInitialization:
|
||||||
|
delete[] list;
|
||||||
|
if (pieces != NULL) {
|
||||||
|
uprv_free(pieces);
|
||||||
|
}
|
||||||
|
pieces = NULL;
|
||||||
|
pieces_length = 0;
|
||||||
|
if(pieces_lengths != NULL) {
|
||||||
|
uprv_free(pieces_lengths);
|
||||||
|
}
|
||||||
|
pieces_lengths = NULL;
|
||||||
|
if(current != NULL) {
|
||||||
|
uprv_free(current);
|
||||||
|
}
|
||||||
|
current = NULL;
|
||||||
|
current_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user