directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r900990 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java
Date Tue, 19 Jan 2010 22:38:46 GMT
Author: elecharny
Date: Tue Jan 19 22:38:46 2010
New Revision: 900990

URL: http://svn.apache.org/viewvc?rev=900990&view=rev
Log:
Challenged by Seelmann, here is a faster version of the UUID SC :)

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java?rev=900990&r1=900989&r2=900990&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxCheckers/UuidSyntaxChecker.java
Tue Jan 19 22:38:46 2010
@@ -21,6 +21,7 @@
 
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,8 +42,12 @@
     /** The serialVersionUID */
     private static final long serialVersionUID = 1L;
 
-    private static final String UUID_REGEX = "^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$";
-    
+    // Tells if the byte is alphanumeric
+    private static boolean isHex( byte b )
+    {
+        return ( b > 0 ) && StringTools.ALPHA_DIGIT[b];
+    }
+
     /**
      * Creates a new instance of UUIDSyntaxChecker.
      */
@@ -69,15 +74,33 @@
             return false;
         }
 
-        String uuid = ( String ) value;
-        if ( ! uuid.matches( UUID_REGEX ) )
+        byte[] b = ((String)value).getBytes();
+        
+        if ( b.length < 36)
         {
-            LOG.debug( "Syntax invalid for '{}'", value );
             return false;
         }
         
-        // There is not that much more we can check.
-        LOG.debug( "Syntax valid for '{}'", value );
-        return true;
+        if ( 
+            isHex( b[0] ) && isHex( b[1] ) && isHex( b[2] ) && isHex(
b[3] ) &
+            isHex( b[4] ) && isHex( b[5] ) && isHex( b[6] ) && isHex(
b[7] ) &
+            b[8] == '-' &
+            isHex( b[9] ) && isHex( b[10] ) && isHex( b[11] ) &&
isHex( b[12] ) &
+            b[13] == '-' &
+            isHex( b[14] ) && isHex( b[15] ) && isHex( b[16] ) &&
isHex( b[17] ) &
+            b[18] == '-' &
+            isHex( b[19] ) && isHex( b[20] ) && isHex( b[21] ) &&
isHex( b[22] ) &
+            b[23] == '-' &
+            isHex( b[24] ) && isHex( b[25] ) && isHex( b[26] ) &&
isHex( b[27] ) &
+            isHex( b[28] ) && isHex( b[29] ) && isHex( b[30] ) &&
isHex( b[31] ) &
+            isHex( b[32] ) && isHex( b[33] ) && isHex( b[34] ) &&
isHex( b[35] ) )
+        {
+            // There is not that much more we can check.
+            LOG.debug( "Syntax valid for '{}'", value );
+            return true;
+        }
+
+        LOG.debug( "Syntax invalid for '{}'", value );
+        return false;
     }
 }



Mime
View raw message