directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r423302 - /directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Date Wed, 19 Jul 2006 00:09:42 GMT
Author: elecharny
Date: Tue Jul 18 17:09:42 2006
New Revision: 423302

URL: http://svn.apache.org/viewvc?rev=423302&view=rev
Log:
Added a toLowerCase method for speed

Modified:
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=423302&r1=423301&r2=423302&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Tue Jul 18 17:09:42 2006
@@ -170,6 +170,35 @@
             -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1  // 60 -> 6F
( a, b, c, d, e, f )
         };
 
+    /** lowerCase = 'a' .. 'z', '0'..'9', '-' */
+    public static final char[] LOWER_CASE =
+        { 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0, '-',   0,   0, 
+            '0', '1', '2', '3', '4', '5', '6', '7', 
+            '8', '9',   0,   0,   0,   0,   0,   0, 
+              0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 
+            'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 
+            'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
+            'x', 'y', 'z',   0,   0,   0,   0,   0, 
+              0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 
+            'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 
+            'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
+            'x', 'y', 'z',   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0, 
+              0,   0,   0,   0,   0,   0,   0,   0 
+        };
+
     private static int CHAR_ONE_BYTE_MASK = 0xFFFFFF80;
 
     private static int CHAR_TWO_BYTES_MASK = 0xFFFFF800;
@@ -413,7 +442,26 @@
         return buf.toString().toUpperCase();
     }
 
-
+    /**
+     * Rewrote the toLowercase method to improve performances.
+     * In Ldap, attributesType are supposed to use ASCII chars :
+     * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
+     * 
+     * @param value The String to lowercase
+     * @return The lowercase string
+     */
+    public static String toLowerCase( String value )
+    {
+        char[] chars = value.toCharArray();
+        
+        for ( int i = 0; i < chars.length; i++ )
+        {
+            chars[i] = LOWER_CASE[ chars[i]];
+        }
+        
+        return new String( chars );
+    }
+    
     /**
      * Get byte array from hex string
      * 



Mime
View raw message