ICU-8468 changes following code review

X-SVN-Rev: 30074
This commit is contained in:
Stuart Gill 2011-05-09 23:54:46 +00:00
parent 1341b94989
commit 871cc23d57
4 changed files with 51 additions and 13 deletions

View File

@ -6698,7 +6698,7 @@ ucol_getStrength(const UCollator *coll)
return ucol_getAttribute(coll, UCOL_STRENGTH, &status);
}
U_CAPI int32_t U_EXPORT2
U_DRAFT int32_t U_EXPORT2
ucol_getReorderCodes(const UCollator *coll,
int32_t *dest,
int32_t destCapacity,
@ -6727,7 +6727,7 @@ ucol_getReorderCodes(const UCollator *coll,
return coll->reorderCodesLength;
}
U_CAPI void U_EXPORT2
U_DRAFT void U_EXPORT2
ucol_setReorderCodes(UCollator* coll,
const int32_t* reorderCodes,
int32_t reorderCodesLength,
@ -6766,7 +6766,7 @@ ucol_setReorderCodes(UCollator* coll,
ucol_buildPermutationTable(coll, status);
}
U_CAPI int32_t U_EXPORT2
U_DRAFT int32_t U_EXPORT2
ucol_getEquivalentReorderCodes(int32_t reorderCode,
int32_t* dest,
int32_t destCapacity,

View File

@ -1055,11 +1055,19 @@ void ucol_setReorderCodesFromParser(UCollator *coll, UColTokenParser *parser, UE
}
coll->defaultReorderCodesLength = parser->reorderCodesLength;
coll->defaultReorderCodes = (int32_t*) uprv_malloc(coll->defaultReorderCodesLength * sizeof(int32_t));
if (coll->defaultReorderCodes == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_memcpy(coll->defaultReorderCodes, parser->reorderCodes, coll->defaultReorderCodesLength * sizeof(int32_t));
coll->freeDefaultReorderCodesOnClose = TRUE;
coll->reorderCodesLength = parser->reorderCodesLength;
coll->reorderCodes = (int32_t*) uprv_malloc(coll->reorderCodesLength * sizeof(int32_t));
if (coll->reorderCodes == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_memcpy(coll->reorderCodes, parser->reorderCodes, coll->reorderCodesLength * sizeof(int32_t));
coll->freeReorderCodesOnClose = TRUE;
}
@ -1183,6 +1191,10 @@ ucol_buildPermutationTable(UCollator *coll, UErrorCode *status) {
// set reordering to the default reordering
if (coll->reorderCodes[0] == UCOL_REORDER_CODE_DEFAULT) {
if (coll->reorderCodesLength != 1) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if (coll->freeReorderCodesOnClose == TRUE) {
uprv_free(coll->reorderCodes);
}

View File

@ -605,12 +605,29 @@ ucol_getReorderCodes(const UCollator* coll,
int32_t* dest,
int32_t destCapacity,
UErrorCode *pErrorCode);
/**
/**
* Sets the reordering codes for this collator.
* Reordering codes allow the collation ordering for groups of characters to be changed.
* The reordering codes are a combination of UScript codes and UColReorderCode entries.
* These allow the ordering of characters belonging to these groups to be changed as a group.
* Collation reordering allows scripts and some other defined blocks of characters
* to be moved relative to each other as a block. This reordering is done on top of
* the DUCET/CLDR standard collation order. Reordering can specify groups to be placed
* at the start and/or the end of the collation order. These groups are specified using
* UScript codes and UColReorderCode entries.
* <p>By default, reordering codes specified for the start of the order are placed in the
* order given after a group of special non-script blocks. These special groups of characters
* are space, punctuation, symbol, currency, and digit. These special groups are represented with
* UColReorderCode entries. Script groups can be intermingled with
* these special non-script blocks if those special blocks are explicitly specified in the reordering.
* <p>The special code OTHERS stands for any script that is not explicitly
* mentioned in the list of reordering codes given. Anything that is after OTHERS
* will go at the very end of the reordering in the order given.
* <p>The special reorder code DEFAULT will reset the reordering for this collator
* to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that
* was specified when this collator was created from resource data or from rules. The
* DEFAULT code <b>must</b> be the sole code supplied when it used. If not
* that will result in an U_ILLEGAL_ARGUMENT_ERROR being set.
* <p>The special reorder code NONE will remove any reordering for this collator.
* The result of setting no reordering will be to have the DUCET/CLDR reordering used. The
* NONE code <b>must</b> be the sole code supplied when it used.
* @param coll The UCollator to set.
* @param reorderCodes An array of script codes in the new order. This can be NULL if the
* length is also set to 0. An empty array will clear any reordering codes on the collator.
@ -619,9 +636,9 @@ ucol_getReorderCodes(const UCollator* coll,
* failure before the function call.
* @see ucol_getReorderCodes
* @see ucol_getEquivalentReorderCodes
* @draft ICU 4.8
*/
U_CAPI void U_EXPORT2
* @draft ICU 4.8
*/
U_DRAFT void U_EXPORT2
ucol_setReorderCodes(UCollator* coll,
const int32_t* reorderCodes,
int32_t reorderCodesLength,
@ -641,7 +658,7 @@ ucol_setReorderCodes(UCollator* coll,
* @see ucol_getReorderCodes
* @draft ICU 4.8
*/
U_CAPI int32_t U_EXPORT2
U_DRAFT int32_t U_EXPORT2
ucol_getEquivalentReorderCodes(int32_t reorderCode,
int32_t* dest,
int32_t destCapacity,

View File

@ -5993,6 +5993,7 @@ static void TestReorderingAPI(void)
UCollator *myCollation;
int32_t reorderCodes[3] = {USCRIPT_GREEK, USCRIPT_HAN, UCOL_REORDER_CODE_PUNCTUATION};
int32_t duplicateReorderCodes[] = {USCRIPT_CUNEIFORM, USCRIPT_GREEK, UCOL_REORDER_CODE_CURRENCY, USCRIPT_EGYPTIAN_HIEROGLYPHS};
int32_t reorderCodesStartingWithDefault[] = {UCOL_REORDER_CODE_DEFAULT, USCRIPT_GREEK, USCRIPT_HAN, UCOL_REORDER_CODE_PUNCTUATION};
UCollationResult collResult;
int32_t retrievedReorderCodesLength;
int32_t retrievedReorderCodes[10];
@ -6073,7 +6074,15 @@ static void TestReorderingAPI(void)
/* test for error condition on duplicate reorder codes */
ucol_setReorderCodes(myCollation, duplicateReorderCodes, LEN(duplicateReorderCodes), &status);
if (!U_FAILURE(status)) {
log_err_status(status, "ERROR: setting duplicate reorder codes did not generate a failure");
log_err_status(status, "ERROR: setting duplicate reorder codes did not generate a failure\n");
return;
}
status = U_ZERO_ERROR;
/* test for reorder codes after a reset code */
ucol_setReorderCodes(myCollation, reorderCodesStartingWithDefault, LEN(reorderCodesStartingWithDefault), &status);
if (!U_FAILURE(status)) {
log_err_status(status, "ERROR: reorderd code sequence starting with default and having following codes didn't cause an error\n");
return;
}