directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r307429 - /directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java
Date Sun, 09 Oct 2005 13:47:53 GMT
Author: elecharny
Date: Sun Oct  9 06:47:49 2005
New Revision: 307429

URL: http://svn.apache.org/viewcvs?rev=307429&view=rev
Log:
Extended this class by adding methods that accepts char[] instead of byte[]

Modified:
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java

Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java?rev=307429&r1=307428&r2=307429&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java
(original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/utils/DNUtils.java
Sun Oct  9 06:47:49 2005
@@ -86,6 +86,36 @@
         false, false, false, false, false, false, false, false
     };
 
+    /** "oid." static */
+    public static final char[] OID_LOWER = new char[] { 'o', 'i', 'd', '.' };
+
+    /** "OID." static */
+    public static final char[] OID_UPPER = new char[] { 'O', 'I', 'D', '.' };
+    
+    /** "oid." static */
+    public static final byte[] OID_LOWER_BYTES = new byte[] { 'o', 'i', 'd', '.' };
+
+    /** "OID." static */
+    public static final byte[] OID_UPPER_BYTES = new byte[] { 'O', 'I', 'D', '.' };
+
+    /** A value if we got an error while parsing */
+    public static final int PARSING_ERROR = -1;
+
+    /** If an hex pair contains only one char, this value is returned */ 
+    public static final int BAD_HEX_PAIR = -2;
+    
+    /** A constant representing one char length */
+    public static final int ONE_CHAR = 1;
+
+    /** A constant representing two chars length */
+    public static final int TWO_CHARS = 2;
+
+    /** A constant representing one byte length */
+    public static final int ONE_BYTE = 1;
+
+    /** A constant representing two bytes length */
+    public static final int TWO_BYTES = 2;
+
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
@@ -166,6 +196,37 @@
     }
 
     /**
+     * Walk the buffer while characters are Alpha characters :
+     *  <alpha>    ::= [0x41-0x5A] | [0x61-0x7A]
+     * 
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return The position of the first character which is not an Alpha Char
+     */
+    public static int parseAlphaASCII( char[] charArray, int index )
+    {
+        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= charArray.length ) )
+        {
+            return PARSING_ERROR;
+        }
+        else
+        {
+            char c = charArray[index++];
+
+            if ( ( c > 127 ) || ( StringUtils.ALPHA[c] == false ) )
+            {
+                return PARSING_ERROR;
+            }
+            else
+            {
+                return index;
+            }
+        }
+    }
+
+    /**
      * Check if the current character is a Pair Char
      *  <pairchar>    ::= ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
| [0-9a-fA-F] [0-9a-fA-F]
      *  
@@ -204,6 +265,44 @@
     }
 
     /**
+     * Check if the current character is a Pair Char
+     *  <pairchar>    ::= ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
| [0-9a-fA-F] [0-9a-fA-F]
+     *  
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return <code>true</code> if the current character is a Pair Char
+     */
+    public static boolean isPairChar( char[] charArray, int index )
+    {
+        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= charArray.length ) )
+        {
+            return false;
+        }
+        else
+        {
+            char c = charArray[index];
+
+            if ( ( c > 127 ) || ( PAIR_CHAR[c] == false ) )
+            {
+                return false;
+            }
+            else
+            {
+                if ( StringUtils.isHex( charArray, index++ ) )
+                {
+                    return StringUtils.isHex( charArray, index );
+                }
+                else
+                {
+                    return true;
+                }
+            }
+        }
+    }
+
+    /**
      * Check if the current character is a String Char.
      * Chars are Unicode, not ASCII.
      *  <stringchar>    ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
@@ -245,6 +344,47 @@
     }
 
     /**
+     * Check if the current character is a String Char.
+     * Chars are Unicode, not ASCII.
+     *  <stringchar>    ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return The current char if it is a String Char, or '#' (this is
+     * simpler than throwing an exception :)
+     */
+    public static int isStringChar( char[] charArray, int index )
+    {
+        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= charArray.length ) )
+        {
+            return PARSING_ERROR;
+        }
+        else
+        {
+            char c = charArray[index];
+
+            if ( ( c == 0x0A ) ||
+                    ( c == 0x0D ) ||
+                    ( c == '"' ) ||
+                    ( c == '#' ) ||
+                    ( c == '+' ) ||
+                    ( c == ',' ) ||
+                    ( c == ';' ) ||
+                    ( c == '<' ) ||
+                    ( c == '=' ) ||
+                    ( c == '>' ) )
+            {
+                return PARSING_ERROR;
+            }
+            else
+            {
+                return ONE_CHAR;
+            }
+        }
+    }
+
+    /**
      * Check if the current character is a Quote Char
      * We are testing Unicode chars
      *  <quotechar>    ::= [0x00-0xFFFF] - [\"]
@@ -277,6 +417,38 @@
     }
 
     /**
+     * Check if the current character is a Quote Char
+     * We are testing Unicode chars
+     *  <quotechar>    ::= [0x00-0xFFFF] - [\"]
+     * 
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return <code>true</code> if the current character is a Quote Char
+     */
+    public static int isQuoteChar( char[] charArray, int index )
+    {
+        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= charArray.length ) )
+        {
+            return PARSING_ERROR;
+        }
+        else
+        {
+            char c = charArray[index];
+
+            if ( ( c == '\\' ) || ( c == '"' ) )
+            {
+                return PARSING_ERROR;
+            }
+            else
+            {
+                return ONE_CHAR;
+            }
+        }
+    }
+
+    /**
      * Parse an hex pair
      *   <hexpair>    ::= <hex> <hex>
      *
@@ -306,6 +478,35 @@
     }
 
     /**
+     * Parse an hex pair
+     *   <hexpair>    ::= <hex> <hex>
+     *
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return The new position, -1 if the buffer does not contain an HexPair, -2 if the
+     * buffer contains an hex byte but not two.
+     */
+    public static int parseHexPair( char[] charArray, int index )
+    {
+        if ( StringUtils.isHex( charArray, index ) )
+        {
+            if ( StringUtils.isHex( charArray, index + 1 ) )
+            {
+                return index + TWO_CHARS;
+            }
+            else
+            {
+                return BAD_HEX_PAIR;
+            }
+        }
+        else
+        {
+            return PARSING_ERROR;
+        }
+    }
+
+    /**
      * Parse an hex string, which is a list of hex pairs
      *  <hexstring>    ::= <hexpair> <hexpairs>
      *  <hexpairs>    ::= <hexpair> <hexpairs> | e
@@ -335,6 +536,38 @@
         }
 
         return ( ( result == -2 ) ? -1 : index );
+    }
+
+    /**
+     * Parse an hex string, which is a list of hex pairs
+     *  <hexstring>    ::= <hexpair> <hexpairs>
+     *  <hexpairs>    ::= <hexpair> <hexpairs> | e
+     *
+     * @param charArray The buffer which contains the data
+     * @param index Current position in the buffer
+     *
+     * @return Return the first position which is not an hex pair, or -1 if there is no
+     * hexpair at the beginning or if an hexpair is invalid (if we have only one hex instead
of 2)
+     */
+    public static int parseHexString( char[] charArray, int index )
+    {
+        int result = parseHexPair( charArray, index );
+
+        if ( result < 0 )
+        {
+            return PARSING_ERROR;
+        }
+        else
+        {
+            index += TWO_CHARS;
+        }
+
+        while ( ( result = parseHexPair( charArray, index ) ) >= 0 )
+        {
+            index += TWO_CHARS;
+        }
+
+        return ( ( result == BAD_HEX_PAIR ) ? PARSING_ERROR : index );
     }
 
     /**



Mime
View raw message