harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r964697 - 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:06:05 GMT
Author: regisxu
Date: Fri Jul 16 07:06:05 2010
New Revision: 964697

URL: http://svn.apache.org/viewvc?rev=964697&view=rev
Log:
Apply patch for HARMONY-6582: [classlib][luni]String.indexOf 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=964697&r1=964696&r2=964697&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:06:05 2010
@@ -986,9 +986,20 @@ public final class String implements Ser
             if (start < 0) {
                 start = 0;
             }
-            for (int i = offset + start; i < offset + count; i++) {
-                if (value[i] == c) {
-                    return i - offset;
+            if (c >= 0 && c <= Character.MAX_VALUE) {
+                for (int i = offset + start; i < offset + count; i++) {
+                    if (value[i] == c) {
+                        return i - offset;
+                    }
+                }
+            } else if (c > Character.MAX_VALUE && c <= Character.MAX_CODE_POINT)
{
+                for (int i = start; i < count; 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=964697&r1=964696&r2=964697&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:06:05 2010
@@ -544,7 +544,7 @@ public class String2Test extends junit.f
     public void test_indexOfI() {
         // Test for method int java.lang.String.indexOf(int)
         assertEquals("Invalid index returned", 1, hw1.indexOf('e'));
-
+        assertEquals("Invalid index returned", 1, "a\ud800\udc00".indexOf(0x10000));
     }
 
     /**
@@ -553,7 +553,7 @@ public class String2Test extends junit.f
     public void test_indexOfII() {
         // Test for method int java.lang.String.indexOf(int, int)
         assertEquals("Invalid character index returned", 5, hw1.indexOf('W', 2));
-
+        assertEquals("Invalid index returned", 2, "ab\ud800\udc00".indexOf(0x10000, 1));
     }
 
     /**



Mime
View raw message