directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1621679 - /directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java
Date Mon, 01 Sep 2014 06:05:46 GMT
Author: elecharny
Date: Mon Sep  1 06:05:46 2014
New Revision: 1621679

URL: http://svn.apache.org/r1621679
Log:
o The Chars.isHex(byte) method was buggy. It accepted any char below 7F as a valid hex digit...
o Added a isHex(char) method
o some other cleanup

Modified:
    directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java

Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java?rev=1621679&r1=1621678&r2=1621679&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java (original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Chars.java Mon
Sep  1 06:05:46 2014
@@ -791,6 +791,19 @@ public final class Chars
 
 
     /**
+     * Check if the current char is an Hex Char
+     * <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
+     *
+     * @param c The char we want to check
+     * @return <code>true</code> if the current char is a Hex char
+     */
+    public static boolean isHex( char c )
+    {
+        return ( ( c | 0x007F ) == 0x007F ) && HEX[c];
+    }
+
+
+    /**
      * Check if the current byte is an Hex Char
      * &lt;hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
      *
@@ -799,7 +812,7 @@ public final class Chars
      */
     public static boolean isHex( byte b )
     {
-        return ( ( b | 0x7F ) == 0x7F ) || HEX[b];
+        return ( ( b | 0x7F ) == 0x7F ) && HEX[b];
     }
 
 
@@ -821,14 +834,7 @@ public final class Chars
         {
             byte c = bytes[index];
 
-            if ( ( ( c | 0x7F ) != 0x7F ) || !HEX[c] )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
+            return ( ( ( c | 0x7F ) == 0x7F ) && HEX[c] );
         }
     }
 
@@ -851,14 +857,7 @@ public final class Chars
         {
             char c = chars[index];
 
-            if ( ( c > 127 ) || !HEX[c] )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
+            return ( ( ( c | 0x007F ) == 0x007F ) && HEX[c] );
         }
     }
 
@@ -888,17 +887,11 @@ public final class Chars
         {
             char c = string.charAt( index );
 
-            if ( ( c > 127 ) || !HEX[c] )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
+            return ( ( ( c | 0x007F ) == 0x007F ) && HEX[c] );
         }
     }
     
+    
     /**
      * Check if the current character is the ASCII character underscore 0x5F.
      *



Mime
View raw message