]> granicus.if.org Git - icu/commitdiff
ICU-10912 create Collator from binary: support length<0 again, and document that...
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 10 Jul 2014 22:17:20 +0000 (22:17 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 10 Jul 2014 22:17:20 +0000 (22:17 +0000)
X-SVN-Rev: 36021

icu4c/source/i18n/rulebasedcollator.cpp
icu4c/source/i18n/unicode/tblcoll.h
icu4c/source/i18n/unicode/ucol.h
icu4c/source/test/intltest/apicoll.cpp

index 40d657009e4a9394ac9d4ac25a8ce567159d72da..710ba8fe954ad6b4c10c761727737eb1df7c27eb 100644 (file)
@@ -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;
     }
index cca4a4e53cc529668b4b9b43a4105c2f6ff7b922..f392ac0e9947485ddaa3da70dbe1168e187546fb 100644 (file)
@@ -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
index 1ec229a880346a54c97b33715db2f98e076b3ce9..8e201b9ed209c91a885e885551644558a2b7daa7 100644 (file)
@@ -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
index 5576dfe1ad76a3691d4615a8698e4988ab32f116..bbd36ca53ef9c98d291367dde7a35022fe9488df 100644 (file)
@@ -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() {