harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r537159 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/Attributes.java main/java/org/apache/harmony/archive/util/Util.java test/java/org/apache/harmony/archive/util/UtilTest.java
Date Fri, 11 May 2007 10:59:37 GMT
Author: apetrenko
Date: Fri May 11 03:59:36 2007
New Revision: 537159

URL: http://svn.apache.org/viewvc?view=rev&rev=537159
Log:
Patch for HARMONY-3469 "[classlib][archive]equalsIgnoreCase in the inner class Name could
be optimized"

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java?view=diff&rev=537159&r1=537158&r2=537159
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
Fri May 11 03:59:36 2007
@@ -109,7 +109,7 @@
                 return false;
             }
             return an.getClass() == this.getClass()
-                    && name.equalsIgnoreCase(((Name) an).name);
+                    && Util.equalsIgnoreCase(name, ((Name) an).name);
         }
 
         @Override

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java?view=diff&rev=537159&r1=537158&r2=537159
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
Fri May 11 03:59:36 2007
@@ -65,4 +65,38 @@
         }
         return buffer.toString();
     }
+    
+    public static final boolean equalsIgnoreCase(String s1, String s2){
+        if (s1 == s2) {
+            return true;
+        }
+        
+        if (s1 == null || s2 == null || s1.length() != s2.length()) {
+            return false;
+        }
+
+        char c1, c2;
+        
+        for (int i=0; i< s1.length(); i++) {
+            if ((c1 = s1.charAt(i)) != (c2 = s2.charAt(i))
+                    && toASCIIUpperCase(c1) != toASCIIUpperCase(c2)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static final char toASCIILowerCase(char c) {
+        if ('A' <= c && c <= 'Z') {
+            return (char) (c + ('a' - 'A'));
+        }
+        return c;
+    }
+
+    public static final char toASCIIUpperCase(char c) {
+        if ('a' <= c && c <= 'z') {
+            return (char) (c - ('a' - 'A'));
+        }
+        return c;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java?view=diff&rev=537159&r1=537158&r2=537159
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
Fri May 11 03:59:36 2007
@@ -20,10 +20,10 @@
 import junit.framework.TestCase;
 
 public class UtilTest extends TestCase {
+    String s1 = "abcdefghijklmnopqrstuvwxyz"; //$NON-NLS-1$
+    String s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //$NON-NLS-1$
 
     public void testASCIIIgnoreCaseRegionMatches() {
-        String s1 = "abcdefghijklmnopqrstuvwxyz"; //$NON-NLS-1$
-        String s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //$NON-NLS-1$
         for (int i = 0; i < s1.length(); i++) {
             assertTrue(Util.ASCIIIgnoreCaseRegionMatches(s1, i, s2, i, s1
                     .length()
@@ -61,6 +61,10 @@
             String cString = "" + (char) i; //$NON-NLS-1$
             assertEquals(cString, Util.toASCIIUpperCase(cString));
         }
+    }
+    
+    public void testEqualsIgnoreCase(){
+        assertTrue(Util.equalsIgnoreCase(s1, s2));
     }
 
 }



Mime
View raw message