harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r964699 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/lang/String.java test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Date Fri, 16 Jul 2010 07:15:12 GMT
Author: regisxu
Date: Fri Jul 16 07:15:11 2010
New Revision: 964699

URL: http://svn.apache.org/viewvc?rev=964699&view=rev
Log:
Apply patch for HARMONY-6583: [classlib][luni]String.lastIndexOf behaves wrongly if the string
contains any Supplementary Characters

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java?rev=964699&r1=964698&r2=964699&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/lang/String.java
Fri Jul 16 07:15:11 2010
@@ -1110,9 +1110,20 @@ public final class String implements Ser
             if (start >= count) {
                 start = count - 1;
             }
-            for (int i = offset + start; i >= offset; --i) {
-                if (value[i] == c) {
-                    return i - offset;
+            if (c >= 0 && c <= Character.MAX_VALUE) {
+                for (int i = offset + start; i >= offset; --i) {
+                    if (value[i] == c) {
+                        return i - offset;
+                    }
+                }
+            } else if (c > Character.MAX_VALUE && c <= Character.MAX_CODE_POINT)
{
+                for (int i = start; i >= 0; --i) {
+                    int codePoint = codePointAt(i);
+                    if (codePoint == c) {
+                        return i;
+                    } else if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
+                        --i;
+                    }
                 }
             }
         }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java?rev=964699&r1=964698&r2=964699&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Fri Jul 16 07:15:11 2010
@@ -595,7 +595,8 @@ public class String2Test extends junit.f
         assertEquals("Failed to return correct index", 5, hw1.lastIndexOf('W'));
         assertEquals("Returned index for non-existent char", -1, hw1
                 .lastIndexOf('Z'));
-
+        assertEquals("Failed to return correct index", 1, "a\ud800\udc00"
+                .lastIndexOf(0x10000));
     }
 
     /**



Mime
View raw message