]> granicus.if.org Git - icu/commitdiff
ICU-9476 fixed bug with numeric collation
authorDebabrata Sengupta <dsengup@svn.icu-project.org>
Thu, 23 Aug 2012 20:59:35 +0000 (20:59 +0000)
committerDebabrata Sengupta <dsengup@svn.icu-project.org>
Thu, 23 Aug 2012 20:59:35 +0000 (20:59 +0000)
X-SVN-Rev: 32223

icu4j/main/classes/collate/src/com/ibm/icu/text/CollationElementIterator.java
icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java

index 5d207e6534b3597f759e75233866c602510666f2..c6006b629edddeb3f51e8ae6e80cb527dd979033 100644 (file)
@@ -1,6 +1,6 @@
 /**
 *******************************************************************************
-* Copyright (C) 1996-2011, International Business Machines Corporation and    *
+* Copyright (C) 1996-2012, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 *
@@ -1928,6 +1928,11 @@ public final class CollationElementIterator
                         // We drop the collation value into the buffer so if 
                         // we need to do a "front patch" we don't have to 
                         // check to see if we're hitting the last element.
+                        
+                        if (trailingZeroIndex != 0) {
+                            trailingZeroIndex = 0;
+                        }
+                        
                         collateVal = digVal * 10;
                         m_utilStringBuffer_.setCharAt((digIndx >>> 1) + 2, 
                                                 (char)((collateVal << 1) + 6));
@@ -1973,7 +1978,8 @@ public final class CollationElementIterator
             }
         
             int endIndex = trailingZeroIndex != 0 ? trailingZeroIndex 
-                                             : (digIndx >>> 1) + 2;              
+                                             : (digIndx >>> 1) + 2;   
+         
             if (digIndx % 2 != 0){
                 // We missed a value. Since digIndx isn't even, stuck too many 
                 // values into the buffer (this is what we get for padding the 
index a89731df17153b82f52ec00e5142b46ce8731328..69394faf2c293ce31ac177e9601ed6994ad5b104 100644 (file)
@@ -1936,6 +1936,12 @@ public class CollationMiscTest extends TestFmwk {
                                   "\u0663\u0662",
                                   "\u0663\u0663"
         };
+        
+        //Additional tests to cover bug reported in #9476
+        String lastDigitDifferent[]={"2004","2005",
+                                     "110005", "110006",
+                                     "11005", "11006",
+                                     "100000000005","100000000006"};
 
         // Open our collator.
         RuleBasedCollator coll
@@ -1963,6 +1969,13 @@ public class CollationMiscTest extends TestFmwk {
                                      preZeroTestStrings[j],0);
             }
         }
+        
+        //Testing that the behavior reported in #9476 is fixed
+        //We expect comparisons between adjacent pairs will result in -1
+        for (int i=0; i < lastDigitDifferent.length -1; i=i+2 ) {
+            CollationTest.doTest(this, coll, lastDigitDifferent[i], lastDigitDifferent[i+1], -1);
+        }
+        
 
         //cover setNumericCollationDefault, getNumericCollation
         assertTrue("The Numeric Collation setting is on", coll.getNumericCollation());