ICU-10998 collation reorder others=Zzzz, recognize only others = reset

X-SVN-Rev: 36017
This commit is contained in:
Markus Scherer 2014-07-09 22:53:09 +00:00
parent 47a28993e7
commit 9bc6f268fb
7 changed files with 60 additions and 13 deletions

View file

@ -301,6 +301,9 @@ int32_t getReorderCode(const char *s) {
return UCOL_REORDER_CODE_FIRST + i;
}
}
// Not supporting "others" = UCOL_REORDER_CODE_OTHERS
// as a synonym for Zzzz = USCRIPT_UNKNOWN for now:
// Avoid introducing synonyms/aliases.
return -1;
}

View file

@ -710,8 +710,7 @@ CollationRuleParser::parseReordering(const UnicodeString &raw, UErrorCode &error
i = limit;
}
int32_t length = reorderCodes.size();
if(length == 1 && reorderCodes.elementAti(0) == UCOL_REORDER_CODE_DEFAULT) {
// The root collator does not have a reordering, by definition.
if(length == 1 && reorderCodes.elementAti(0) == UCOL_REORDER_CODE_NONE) {
settings->resetReordering();
return;
}
@ -738,10 +737,10 @@ CollationRuleParser::getReorderCode(const char *word) {
if(script >= 0) {
return script;
}
if(uprv_stricmp(word, "default") == 0) {
return UCOL_REORDER_CODE_DEFAULT;
if(uprv_stricmp(word, "others") == 0) {
return UCOL_REORDER_CODE_OTHERS; // same as Zzzz = USCRIPT_UNKNOWN
}
return -2;
return -1;
}
UColAttributeValue

View file

@ -132,8 +132,7 @@ public:
/**
* Gets a script or reorder code from its string representation.
* @return the script/reorder code, or
* -1==UCOL_REORDER_CODE_DEFAULT, or
* -2 if not recognized
* -1 if not recognized
*/
static int32_t getReorderCode(const char *word);

View file

@ -670,7 +670,7 @@ RuleBasedCollator::setReorderCodes(const int32_t *reorderCodes, int32_t length,
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
if(length == 0) {
if(length == 0 || (length == 1 && reorderCodes[0] == UCOL_REORDER_CODE_NONE)) {
ownedSettings->resetReordering();
} else {
uint8_t reorderTable[256];

View file

@ -4691,6 +4691,7 @@ static void TestReorderingAPI(void)
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};
int32_t reorderCodeNone = UCOL_REORDER_CODE_NONE;
UCollationResult collResult;
int32_t retrievedReorderCodesLength;
int32_t retrievedReorderCodes[10];
@ -4768,6 +4769,22 @@ static void TestReorderingAPI(void)
return;
}
/* clear the reordering using [NONE] */
ucol_setReorderCodes(myCollation, &reorderCodeNone, 1, &status);
if (U_FAILURE(status)) {
log_err_status(status, "ERROR: setting reorder codes to [NONE]: %s\n", myErrorName(status));
return;
}
/* get the reordering again */
retrievedReorderCodesLength = ucol_getReorderCodes(myCollation, NULL, 0, &status);
if (retrievedReorderCodesLength != 0) {
log_err_status(status,
"ERROR: [NONE] retrieved reorder codes length was %d but should have been 0\n",
retrievedReorderCodesLength);
return;
}
/* test for error condition on duplicate reorder codes */
ucol_setReorderCodes(myCollation, duplicateReorderCodes, LEN(duplicateReorderCodes), &status);
if (!U_FAILURE(status)) {

View file

@ -1173,11 +1173,15 @@ void CollationTest::parseAndSetReorderCodes(int32_t start, IcuTestErrorCode &err
CharString name;
name.appendInvariantChars(fileLine.tempSubStringBetween(start, limit), errorCode);
int32_t code = CollationRuleParser::getReorderCode(name.data());
if(code < -1) {
errln("invalid reorder code '%s' on line %d", name.data(), (int)fileLineNumber);
infoln(fileLine);
errorCode.set(U_PARSE_ERROR);
return;
if(code < 0) {
if(uprv_stricmp(name.data(), "default") == 0) {
code = UCOL_REORDER_CODE_DEFAULT; // -1
} else {
errln("invalid reorder code '%s' on line %d", name.data(), (int)fileLineNumber);
infoln(fileLine);
errorCode.set(U_PARSE_ERROR);
return;
}
}
reorderCodes.addElement(code, errorCode);
start = limit;

View file

@ -2439,3 +2439,28 @@
<1 a
<1 ae
<2 ä
** test: import rules from a language with non-Latin native script, and reset the reordering, ICU ticket 10998
# Greek should sort Greek first.
@ rules
[import el]
* compare
<1 4
<1 Ω
<1 L
# Import Greek, and then reset the reordering.
@ rules
[import el][reorder Zzzz]
* compare
<1 4
<1 L
<1 Ω
# "others" is a synonym for Zzzz.
@ rules
[import el][reorder others]
* compare
<1 4
<1 L
<1 Ω