From: Markus Scherer Date: Thu, 10 Jul 2014 22:17:20 +0000 (+0000) Subject: ICU-10912 create Collator from binary: support length<0 again, and document that... X-Git-Tag: milestone-59-0-1~1790 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37c7676f5e153251b98ba408c6508cc5763ee620;p=icu ICU-10912 create Collator from binary: support length<0 again, and document that the base collator is required (see ticket #10517) X-SVN-Rev: 36021 --- diff --git a/icu4c/source/i18n/rulebasedcollator.cpp b/icu4c/source/i18n/rulebasedcollator.cpp index 40d657009e4..710ba8fe954 100644 --- a/icu4c/source/i18n/rulebasedcollator.cpp +++ b/icu4c/source/i18n/rulebasedcollator.cpp @@ -158,7 +158,7 @@ RuleBasedCollator::RuleBasedCollator(const uint8_t *bin, int32_t length, explicitlySetAttributes(0), actualLocaleIsSameAsValid(FALSE) { if(U_FAILURE(errorCode)) { return; } - if(bin == NULL || length <= 0 || base == NULL) { + if(bin == NULL || length == 0 || base == NULL) { errorCode = U_ILLEGAL_ARGUMENT_ERROR; return; } diff --git a/icu4c/source/i18n/unicode/tblcoll.h b/icu4c/source/i18n/unicode/tblcoll.h index cca4a4e53cc..f392ac0e994 100644 --- a/icu4c/source/i18n/unicode/tblcoll.h +++ b/icu4c/source/i18n/unicode/tblcoll.h @@ -182,14 +182,14 @@ public: * cloneBinary. Binary image used in instantiation of the * collator remains owned by the user and should stay around for * the lifetime of the collator. The API also takes a base collator - * which usually should be the root collator. + * which must be the root collator. * @param bin binary image owned by the user and required through the * lifetime of the collator * @param length size of the image. If negative, the API will try to * figure out the length of the image - * @param base fallback collator, usually root. The base is required to be - * present through the lifetime of the collator. Currently - * it cannot be NULL. + * @param base Base collator, for lookup of untailored characters. + * Must be the root collator, must not be NULL. + * The base is required to be present through the lifetime of the collator. * @param status for catching errors * @return newly created collator * @see cloneBinary diff --git a/icu4c/source/i18n/unicode/ucol.h b/icu4c/source/i18n/unicode/ucol.h index 1ec229a8803..8e201b9ed20 100644 --- a/icu4c/source/i18n/unicode/ucol.h +++ b/icu4c/source/i18n/unicode/ucol.h @@ -1429,14 +1429,14 @@ ucol_cloneBinary(const UCollator *coll, * ucol_cloneBinary. Binary image used in instantiation of the * collator remains owned by the user and should stay around for * the lifetime of the collator. The API also takes a base collator - * which usually should be the root collator. + * which must be the root collator. * @param bin binary image owned by the user and required through the * lifetime of the collator * @param length size of the image. If negative, the API will try to * figure out the length of the image - * @param base fallback collator, usually the root collator. Base is required to be - * present through the lifetime of the collator. Currently - * it cannot be NULL. + * @param base Base collator, for lookup of untailored characters. + * Must be the root collator, must not be NULL. + * The base is required to be present through the lifetime of the collator. * @param status for catching errors * @return newly created collator * @see ucol_cloneBinary diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index 5576dfe1ad7..bbd36ca53ef 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -2386,6 +2386,14 @@ void CollationAPITest::TestCloneBinary() { int32_t bin2Length = rbc2.cloneBinary(bin2, LENGTHOF(bin2), errorCode); assertEquals("len(rbc binary)==len(rbc2 binary)", binLength, bin2Length); assertTrue("rbc binary==rbc2 binary", binLength == bin2Length && memcmp(bin, bin2, binLength) == 0); + + RuleBasedCollator rbc3(bin, -1, rbRoot, errorCode); + if(errorCode.logDataIfFailureAndReset("RuleBasedCollator(rbc binary, length<0)")) { + return; + } + assertEquals("rbc3.strength==primary", UCOL_PRIMARY, rbc3.getAttribute(UCOL_STRENGTH, errorCode)); + assertEquals("rbc3: u-umlaut==ue", UCOL_EQUAL, rbc3.compare(uUmlaut, ue, errorCode)); + assertTrue("rbc==rbc3", *rbc == rbc3); } void CollationAPITest::TestIterNumeric() {