[haiku-commits] r37787 - in haiku/trunk/src: kits/locale tests/kits/locale
- From: pulkomandy@xxxxxxxxxxxxxxxxx
- To: haiku-commits@xxxxxxxxxxxxx
- Date: Wed, 28 Jul 2010 16:23:08 +0200 (CEST)
Author: pulkomandy
Date: 2010-07-28 16:23:08 +0200 (Wed, 28 Jul 2010)
New Revision: 37787
Changeset: http://dev.haiku-os.org/changeset/37787
Modified:
haiku/trunk/src/kits/locale/Collator.cpp
haiku/trunk/src/tests/kits/locale/collatorTest.cpp
Log:
* Fix some issues in collators archiving and key computation
* The test now pass. But unarchiving still isn't working and restores the
default collator instead of the archved one.
Modified: haiku/trunk/src/kits/locale/Collator.cpp
===================================================================
--- haiku/trunk/src/kits/locale/Collator.cpp 2010-07-28 13:55:25 UTC (rev
37786)
+++ haiku/trunk/src/kits/locale/Collator.cpp 2010-07-28 14:23:08 UTC (rev
37787)
@@ -116,9 +116,29 @@
status_t
BCollator::GetSortKey(const char *string, BString *key, int8 strength)
{
- // TODO : handle fIgnorePunctuation and strength
+ // TODO : handle fIgnorePunctuation
if (strength == B_COLLATE_DEFAULT)
strength = fStrength;
+ Collator::ECollationStrength icuStrength;
+ switch(strength) {
+ case B_COLLATE_PRIMARY:
+ icuStrength = Collator::PRIMARY;
+ break;
+ case B_COLLATE_SECONDARY:
+ icuStrength = Collator::SECONDARY;
+ break;
+ case B_COLLATE_TERTIARY:
+ default:
+ icuStrength = Collator::TERTIARY;
+ break;
+ case B_COLLATE_QUATERNARY:
+ icuStrength = Collator::QUATERNARY;
+ break;
+ case B_COLLATE_IDENTICAL:
+ icuStrength = Collator::IDENTICAL;
+ break;
+ }
+ fICUCollator->setStrength(icuStrength);
int length = strlen(string);
@@ -127,20 +147,25 @@
if (buffer == NULL)
return B_NO_MEMORY;
- int requiredSize = fICUCollator->getSortKey(UnicodeString(string,
length),
- buffer, length * 2);
+ UErrorCode error = U_ZERO_ERROR;
+ int requiredSize = fICUCollator->getSortKey(UnicodeString(string,
length,
+ NULL, error), buffer, length * 2);
if (requiredSize > length * 2) {
buffer = (uint8_t*)realloc(buffer, requiredSize);
if (buffer == NULL)
return B_NO_MEMORY;
- fICUCollator->getSortKey(UnicodeString(string, length), buffer,
- requiredSize);
+ error = U_ZERO_ERROR;
+ fICUCollator->getSortKey(UnicodeString(string, length, NULL,
error),
+ buffer, requiredSize);
}
key->SetTo((char*)buffer);
free(buffer);
- return B_OK;
+ if (error == U_ZERO_ERROR)
+ return B_OK;
+ else
+ return B_ERROR;
}
@@ -170,7 +195,8 @@
break;
}
fICUCollator->setStrength(icuStrength);
- return fICUCollator->compare(a, b, length);
+ UErrorCode error = U_ZERO_ERROR;
+ return fICUCollator->compare(a, b, error);
}
Modified: haiku/trunk/src/tests/kits/locale/collatorTest.cpp
===================================================================
--- haiku/trunk/src/tests/kits/locale/collatorTest.cpp 2010-07-28 13:55:25 UTC
(rev 37786)
+++ haiku/trunk/src/tests/kits/locale/collatorTest.cpp 2010-07-28 14:23:08 UTC
(rev 37787)
@@ -75,7 +75,7 @@
if (compare > 0)
printf("\n%2lu)", bucket++);
else if (compare < 0) {
- printf("\t*** broken sort order!\n");
+ printf("\t*** broken sort order, next is NOT
%s\n", strings[i]);
exit(-1);
}
Other related posts: