You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/11/02 23:08:05 UTC

svn commit: r591493 [1/2] - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/name/ main/java/org/apache/directory/shared/ldap/util/ test/java/org/apache/directory/shared/ldap/name/

Author: elecharny
Date: Fri Nov  2 15:08:03 2007
New Revision: 591493

URL: http://svn.apache.org/viewvc?rev=591493&view=rev
Log:
o Fixed a bug in the DnParser : some unicode chars followed by escaped chars were not correctly parsed

In fact, DN should not have been parsed as if they were Strins, but should be first transformed to byte[].

o Added some helper methods in DNUtils and StringTools
o cleaned the javadoc
o added some tests

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=591493&r1=591492&r2=591493&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Fri Nov  2 15:08:03 2007
@@ -21,7 +21,6 @@
 package org.apache.directory.shared.ldap.name;
 
 
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -167,13 +166,13 @@
      * @param nameComponents
      *            List of String name components.
      */
-    LdapDN( Iterator nameComponents ) throws InvalidNameException
+    LdapDN( Iterator<String> nameComponents ) throws InvalidNameException
     {
         if ( nameComponents != null )
         {
             while ( nameComponents.hasNext() )
             {
-                String nameComponent = ( String ) nameComponents.next();
+                String nameComponent = nameComponents.next();
                 add( 0, nameComponent );
             }
         }
@@ -269,19 +268,10 @@
      */
     public LdapDN( byte[] bytes ) throws InvalidNameException
     {
-        try
-        {
-            upName = new String( bytes, "UTF-8" );
-            LdapDnParser.parseInternal( upName, rdns );
-            this.normName = toNormName();
-            normalized = false;
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            log.error( "The byte array is not an UTF-8 encoded Unicode String : " + uee.getMessage() );
-            throw new InvalidNameException( "The byte array is not an UTF-8 encoded Unicode String : "
-                + uee.getMessage() );
-        }
+        upName = StringTools.utf8ToString( bytes );
+        LdapDnParser.parseInternal( bytes, rdns );
+        this.normName = toNormName();
+        normalized = false;
     }
 
 
@@ -1488,11 +1478,11 @@
             Rdn rdnCopy = ( Rdn ) rdn.clone();
             rdn.clear();
 
-            Iterator atavs = rdnCopy.iterator();
+            Iterator<AttributeTypeAndValue> atavs = rdnCopy.iterator();
 
             while ( atavs.hasNext() )
             {
-            	AttributeTypeAndValue val = (AttributeTypeAndValue)atavs.next();
+            	AttributeTypeAndValue val = atavs.next();
                 AttributeTypeAndValue newAtav = atavOidToName( val, oidsMap );
                 rdn.addAttributeTypeAndValue( val.getUpType(), newAtav.getNormType(), val.getUpValue(), newAtav.getValue() );
             }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java?rev=591493&r1=591492&r2=591493&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDnParser.java Fri Nov  2 15:08:03 2007
@@ -96,12 +96,9 @@
    /**
     * Parse a DN
     *
-    * @param dn
-    *            The DN to be parsed
-    * @param rdns
-    *            The list that will contain the RDNs
-    * @throws InvalidNameException
-    *             If the DN is invalid
+    * @param dn The DN to be parsed
+    * @param rdns The list that will contain the RDNs
+    * @throws InvalidNameException If the DN is invalid
     */
    public static void parseInternal( String dn, List<Rdn> rdns ) throws InvalidNameException
    {
@@ -111,6 +108,27 @@
            return;
        }
 
+       parseInternal( StringTools.getBytesUtf8( dn ), rdns );
+       
+       return;
+   }
+
+
+   /**
+    * Parse a DN
+    *
+    * @param dn The DN to be parsed
+    * @param rdns The list that will contain the RDNs
+    * @throws InvalidNameException If the DN is invalid
+    */
+   public static void parseInternal( byte[] dn, List<Rdn> rdns ) throws InvalidNameException
+   {
+       if ( dn.length == 0 )
+       {
+           // We have an empty DN, just get out of the function.
+           return;
+       }
+
        Position pos = new Position();
        pos.start = 0;
        Rdn rdn = new Rdn();
@@ -130,7 +148,7 @@
                    && ( StringTools.isCharASCII( dn, pos.start, ';' ) == false ) )
                {
 
-                   if ( pos.start != dn.length() )
+                   if ( pos.start != dn.length )
                    {
                        throw new InvalidNameException( "Bad DN : " + dn );
                    }
@@ -156,18 +174,12 @@
    /**
     * Validate a DN
     *
-    * @param dn
-    *            The DN to be parsed
+    * @param dn The DN to be parsed
     *            
     * @return <code>true</code> if the DN is valid
     */
-   public static boolean validateInternal( String dn )
+   private static boolean validateInternal( byte[] dn )
    {
-       if ( dn.length() == 0 )
-       {
-           // We have an empty DN, just get out of the function.
-           return true;
-       }
 
        Position pos = new Position();
        pos.start = 0;
@@ -184,7 +196,7 @@
                    && ( StringTools.isCharASCII( dn, pos.start, ';' ) == false ) )
                {
 
-                   if ( pos.start != dn.length() )
+                   if ( pos.start != dn.length )
                    {
                        return false;
                    }
@@ -201,6 +213,25 @@
        }
 
        return false;
+   }
+
+   
+   /**
+    * Validate a DN
+    *
+    * @param dn The DN to be parsed
+    *            
+    * @return <code>true</code> if the DN is valid
+    */
+   public static boolean validateInternal( String dn )
+   {
+       if ( dn.length() == 0 )
+       {
+           // We have an empty DN, just get out of the function.
+           return true;
+       }
+
+       return validateInternal( StringTools.getBytesUtf8( dn ) );
    }
 
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=591493&r1=591492&r2=591493&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Fri Nov  2 15:08:03 2007
@@ -684,18 +684,18 @@
                                // We have to verify that each value of the
                                // first list are present in
                                // the second list
-                               Iterator atavLocals = atavLocalList.iterator();
+                               Iterator<AttributeTypeAndValue> atavLocals = atavLocalList.iterator();
 
                                while ( atavLocals.hasNext() )
                                {
-                                   AttributeTypeAndValue atavLocal = ( AttributeTypeAndValue ) atavLocals.next();
+                                   AttributeTypeAndValue atavLocal = atavLocals.next();
 
-                                   Iterator atavParams = atavParamList.iterator();
+                                   Iterator<AttributeTypeAndValue> atavParams = atavParamList.iterator();
                                    boolean found = false;
 
                                    while ( atavParams.hasNext() )
                                    {
-                                       AttributeTypeAndValue atavParam = ( AttributeTypeAndValue ) atavParams.next();
+                                       AttributeTypeAndValue atavParam = atavParams.next();
 
                                        if ( atavLocal.compareTo( atavParam ) == EQUALS )
                                        {
@@ -940,11 +940,11 @@
 
                    attribute = new AttributeImpl( type );
 
-                   Iterator iterValues = values.iterator();
+                   Iterator<AttributeTypeAndValue> iterValues = values.iterator();
 
                    while ( iterValues.hasNext() )
                    {
-                       AttributeTypeAndValue value = ( AttributeTypeAndValue ) iterValues.next();
+                       AttributeTypeAndValue value = iterValues.next();
 
                        attribute.add( value.getValue() );
                    }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=591493&r1=591492&r2=591493&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java Fri Nov  2 15:08:03 2007
@@ -20,8 +20,6 @@
 package org.apache.directory.shared.ldap.name;
 
 
-import java.io.UnsupportedEncodingException;
-
 import javax.naming.InvalidNameException;
 
 import org.apache.directory.shared.ldap.util.DNUtils;
@@ -95,20 +93,18 @@
      * &lt;oidValue&gt; ::= [0-9] &lt;digits&gt; &lt;oids&gt;
      * </p>
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the byte buffer
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @param bytes The bytes array to parse
+     * @param pos The current position in the byte buffer
+     * @return The new position in the vyte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    private static String parseOidValue( String string, Position pos )
+    private static String parseOidValue( byte[] bytes, Position pos )
     {
         pos.start += pos.length;
         pos.end = pos.start;
 
         // <attributType> ::= [0-9] <digits> <oids>
-        if ( StringTools.isDigit( string, pos.start ) == false )
+        if ( StringTools.isDigit( bytes, pos.start ) == false )
         {
             // Nope... An error
             return null;
@@ -118,13 +114,13 @@
             // Let's process an oid
             pos.end++;
 
-            while ( StringTools.isDigit( string, pos.end ) )
+            while ( StringTools.isDigit( bytes, pos.end ) )
             {
                 pos.end++;
             }
 
             // <oids> ::= '.' [0-9] <digits> <oids> | e
-            if ( StringTools.isCharASCII( string, pos.end, '.' ) == false )
+            if ( StringTools.isCharASCII( bytes, pos.end, '.' ) == false )
             {
                 return null;
             }
@@ -134,7 +130,7 @@
                 {
                     pos.end++;
 
-                    if ( StringTools.isDigit( string, pos.end ) == false )
+                    if ( StringTools.isDigit( bytes, pos.end ) == false )
                     {
                         return null;
                     }
@@ -142,39 +138,38 @@
                     {
                         pos.end++;
 
-                        while ( StringTools.isDigit( string, pos.end ) )
+                        while ( StringTools.isDigit( bytes, pos.end ) )
                         {
                             pos.end++;
                         }
                     }
 
                 }
-                while ( StringTools.isCharASCII( string, pos.end, '.' ) );
+                while ( StringTools.isCharASCII( bytes, pos.end, '.' ) );
 
-                return string.substring( pos.start - pos.length, pos.end );
+                return StringTools.utf8ToString( bytes, pos.start - pos.length, pos.end - pos.start + pos.length );
             }
         }
     }
 
+    
     /**
      * Validate this rule : <br>
      * <p>
      * &lt;oidValue&gt; ::= [0-9] &lt;digits&gt; &lt;oids&gt;
      * </p>
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the byte buffer
+     * @param bytes The byte array to parse
+     * @param pos The current position in the byte buffer
      * @return <code>true</code> if this is a valid OID
      */
-    private static boolean isValidOidValue( String string, Position pos )
+    private static boolean isValidOidValue( byte[] bytes, Position pos )
     {
         pos.start += pos.length;
         pos.end = pos.start;
 
         // <attributType> ::= [0-9] <digits> <oids>
-        if ( StringTools.isDigit( string, pos.start ) == false )
+        if ( StringTools.isDigit( bytes, pos.start ) == false )
         {
             // Nope... An error
             return false;
@@ -184,13 +179,13 @@
             // Let's process an oid
             pos.end++;
 
-            while ( StringTools.isDigit( string, pos.end ) )
+            while ( StringTools.isDigit( bytes, pos.end ) )
             {
                 pos.end++;
             }
 
             // <oids> ::= '.' [0-9] <digits> <oids> | e
-            if ( StringTools.isCharASCII( string, pos.end, '.' ) == false )
+            if ( StringTools.isCharASCII( bytes, pos.end, '.' ) == false )
             {
                 return false;
             }
@@ -200,7 +195,7 @@
                 {
                     pos.end++;
 
-                    if ( StringTools.isDigit( string, pos.end ) == false )
+                    if ( StringTools.isDigit( bytes, pos.end ) == false )
                     {
                         return false;
                     }
@@ -208,47 +203,46 @@
                     {
                         pos.end++;
 
-                        while ( StringTools.isDigit( string, pos.end ) )
+                        while ( StringTools.isDigit( bytes, pos.end ) )
                         {
                             pos.end++;
                         }
                     }
 
                 }
-                while ( StringTools.isCharASCII( string, pos.end, '.' ) );
+                while ( StringTools.isCharASCII( bytes, pos.end, '.' ) );
 
                 return true;
             }
         }
     }
 
+
     /**
      * Parse this rule : <br>
      * <p>
      * &lt;oidPrefix&gt; ::= 'OID.' | 'oid.' | e
      * </p>
      *
-     * @param bytes
-     *            The buffer to parse
-     * @param pos
-     *            The current position in the char array
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @param bytes The buffer to parse
+     * @param pos The current position in the byte array
+     * @return The new position in the byte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    private static int parseOidPrefix( String string, Position pos )
+    private static int parseOidPrefix( byte[] bytes, Position pos )
     {
-    	if ( StringTools.isICharASCII( string, pos.start, 'O' ) &&
-    		 StringTools.isICharASCII( string, pos.start + 1, 'I' ) && 
-    		 StringTools.isICharASCII( string, pos.start + 2, 'D' ) &&
-    		 StringTools.isICharASCII( string, pos.start + 3, '.' ) )
-    	{
-    		pos.end += DNUtils.OID_LOWER.length();
-    		return DNUtils.PARSING_OK;
-    	}
-    	else
-    	{
-    		return DNUtils.PARSING_ERROR;
-    	}
+        if ( StringTools.isICharASCII( bytes, pos.start, 'O' ) &&
+             StringTools.isICharASCII( bytes, pos.start + 1, 'I' ) && 
+             StringTools.isICharASCII( bytes, pos.start + 2, 'D' ) &&
+             StringTools.isICharASCII( bytes, pos.start + 3, '.' ) )
+        {
+            pos.end += DNUtils.OID_LOWER.length();
+            return DNUtils.PARSING_OK;
+        }
+        else
+        {
+            return DNUtils.PARSING_ERROR;
+        }
     }
 
 
@@ -260,28 +254,26 @@
      * </p>
      * The string *MUST* be an ASCII string, not an unicode string.
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the char array
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @param bytes The byte array to parse
+     * @param pos The current position in the byte array
+     * @return The new position in the byte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    private static String parseAttributeType( String string, Position pos )
+    private static String parseAttributeType( byte[] bytes, Position pos )
     {
         // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits>
         // <oids> | [0-9] <digits> <oids>
-        if ( StringTools.isAlphaASCII( string, pos.start ) )
+        if ( StringTools.isAlphaASCII( bytes, pos.start ) )
         {
             // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9]
             // <digits> <oids>
 
             // We have got an Alpha char, it may be the begining of an OID ?
-            if ( parseOidPrefix( string, pos ) != DNUtils.PARSING_ERROR )
+            if ( parseOidPrefix( bytes, pos ) != DNUtils.PARSING_ERROR )
             {
                 pos.length = 4;
 
-                return parseOidValue( string, pos );
+                return parseOidValue( bytes, pos );
             }
             else
             {
@@ -291,22 +283,23 @@
                 // <keychar> | e
                 pos.end++;
 
-                while ( StringTools.isAlphaDigitMinus( string, pos.end ) )
+                while ( StringTools.isAlphaDigitMinus( bytes, pos.end ) )
                 {
                     pos.end++;
                 }
 
-                return string.substring( pos.start, pos.end );
+                return StringTools.utf8ToString( bytes, pos.start, pos.end - pos.start );
             }
         }
         else
         {
             // An oid
             // <attributType> ::= [0-9] <digits> <oids>
-            return parseOidValue( string, pos );
+            return parseOidValue( bytes, pos );
         }
     }
 
+
     /**
      * Parse this rule : <br>
      * <p>
@@ -315,28 +308,26 @@
      * </p>
      * The string *MUST* be an ASCII string, not an unicode string.
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the char array
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @param bytes The byte array to parse
+     * @param pos The current position in the byte array
+     * @return The new position in the byte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    private static boolean isValidAttributeType( String string, Position pos )
+    private static boolean isValidAttributeType( byte[] bytes, Position pos )
     {
         // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits>
         // <oids> | [0-9] <digits> <oids>
-        if ( StringTools.isAlphaASCII( string, pos.start ) )
+        if ( StringTools.isAlphaASCII( bytes, pos.start ) )
         {
             // <attributType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9]
             // <digits> <oids>
 
             // We have got an Alpha char, it may be the begining of an OID ?
-            if ( parseOidPrefix( string, pos ) != DNUtils.PARSING_ERROR )
+            if ( parseOidPrefix( bytes, pos ) != DNUtils.PARSING_ERROR )
             {
                 pos.length = 4;
 
-                return isValidOidValue( string, pos );
+                return isValidOidValue( bytes, pos );
             }
             else
             {
@@ -346,7 +337,7 @@
                 // <keychar> | e
                 pos.end++;
 
-                while ( StringTools.isAlphaDigitMinus( string, pos.end ) )
+                while ( StringTools.isAlphaDigitMinus( bytes, pos.end ) )
                 {
                     pos.end++;
                 }
@@ -358,7 +349,7 @@
         {
             // An oid
             // <attributType> ::= [0-9] <digits> <oids>
-            return isValidOidValue( string, pos );
+            return isValidOidValue( bytes, pos );
         }
     }
 
@@ -376,17 +367,17 @@
      * &lt;quotechar-or-pairs&gt; | e <br>
      * </p>
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the char array
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @param bytes The byte array to parse
+     * @param pos The current position in the byte array
+     * @return The new position in the byte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    private static Object parseAttributeValue( String string, Position pos )
+    private static Object parseAttributeValue( byte[] bytes, Position pos )
     {
-        StringBuffer sb = new StringBuffer();
-        char c = StringTools.charAt( string, pos.start );
+        //StringBuffer sb = new StringBuffer();
+        byte c = bytes[pos.start];
+        byte[] buffer = new byte[bytes.length];
+        int currPos = 0;
 
         if ( c == '#' )
         {
@@ -395,7 +386,7 @@
             int currentPos = pos.start;
 
             // First, we will count the number of hexPairs
-            while ( DNUtils.parseHexPair( string, currentPos ) >= 0 )
+            while ( DNUtils.parseHexPair( bytes, currentPos ) >= 0 )
             {
                 nbHex++;
                 currentPos += DNUtils.TWO_CHARS;
@@ -405,13 +396,13 @@
 
             // Now, convert the value
             // <attributeValue> ::= '#' <hexstring>
-            if ( DNUtils.parseHexString( string, hexValue, pos ) == DNUtils.PARSING_ERROR )
+            if ( DNUtils.parseHexString( bytes, hexValue, pos ) == DNUtils.PARSING_ERROR )
             {
                 return null;
             }
 
             pos.start--;
-            StringTools.trimRight( string, pos );
+            StringTools.trimRight( bytes, pos );
             pos.length = pos.end - pos.start;
 
             return hexValue;
@@ -428,12 +419,12 @@
             //                                                  <pairchar> <quotechar-or-pairs> | e
             while ( true )
             {
-                if ( StringTools.isCharASCII( string, pos.end, '\\' ) )
+                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
                 {
                     pos.end++;
                     int nbChars = 0;
 
-                    if ( ( nbChars = DNUtils.isPairChar( string, pos.start ) ) != DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.start ) ) != DNUtils.PARSING_ERROR )
                     {
                         pos.end += nbChars;
                     }
@@ -442,7 +433,7 @@
                         return null;
                     }
                 }
-                else if ( ( nbBytes = DNUtils.isQuoteChar( string, pos.end ) ) != DNUtils.PARSING_ERROR )
+                else if ( ( nbBytes = DNUtils.isQuoteChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR )
                 {
                     pos.end += nbBytes;
                 }
@@ -453,10 +444,10 @@
                 }
             }
 
-            if ( StringTools.isCharASCII( string, pos.end, '"' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
             {
                 pos.end++;
-                return string.substring( pos.start, pos.start + pos.length );
+                return StringTools.utf8ToString( bytes, pos.start, pos.length );
             }
             else
             {
@@ -470,13 +461,13 @@
 
             while ( true )
             {
-                if ( StringTools.isCharASCII( string, pos.end, '\\' ) )
+                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
                 {
                     // '\' <pairchar> <pairs-or-strings>
                     pos.end++;
 
                     int nbChars = 0;
-                    if ( ( nbChars = DNUtils.isPairChar( string, pos.end ) ) == DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR )
                     {
                         return null;
                     }
@@ -484,7 +475,7 @@
                     {
                         if ( nbChars == 1 )
                         {
-                            sb.append( string.charAt( pos.end ) );
+                            buffer[currPos++] = bytes[pos.end];
                         }
                         else
                         {
@@ -493,14 +484,18 @@
                                 hasPairChar = true;
                             }
 
-                            byte b = StringTools.getHexValue( string.charAt( pos.end ), string.charAt( pos.end + 1 ) );
+                            byte b = StringTools.getHexValue( bytes[pos.end], bytes[pos.end + 1] );
 
-                            sb.append( (char)(b & 0x00FF) );
+                            buffer[currPos++] = b;
                         }
 
-                        if ( string.charAt( pos.end ) == ' ' )
+                        if ( bytes[pos.end] == ' ' )
                         {
-                            escapedSpace = sb.length();
+                            escapedSpace = currPos;
+                        }
+                        else
+                        {
+                            escapedSpace = -1;
                         }
 
                         pos.end += nbChars;
@@ -511,63 +506,61 @@
                     int nbChars = 0;
 
                     // <stringchar> <pairs-or-strings>
-                    if ( ( nbChars = DNUtils.isStringChar( string, pos.end ) ) != DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.isStringChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR )
                     {
                         // A special case : if we have some spaces before the
                         // '+' character,
                         // we MUST skip them.
-                        if ( StringTools.isCharASCII( string, pos.end, '+' ) )
+                        if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
                         {
                             //StringTools.trimLeft( string, pos );
 
-                            if ( ( DNUtils.isStringChar( string, pos.end ) == DNUtils.PARSING_ERROR )
-                                && ( StringTools.isCharASCII( string, pos.end, '\\' ) == false ) )
+                            if ( ( DNUtils.isStringChar( bytes, pos.end ) == DNUtils.PARSING_ERROR )
+                                && ( StringTools.isCharASCII( bytes, pos.end, '\\' ) == false ) )
                             {
                                 // Ok, we are done with the stringchar.
-                                String result = string.substring( pos.start, pos.start + pos.length );
+                                String result = StringTools.trimRight( StringTools.utf8ToString( bytes, pos.start, pos.start + pos.length ) );
                                 
-                                if ( hasPairChar )
-                                {
-                                    return unescapeValue( result );
-                                }
-                                else
-                                {
-                                    return result; 
-                                }
+                                return result;
                             }
                             else
                             {
-                                sb.append( string.charAt( pos.end ) );
-                                pos.end++;
+                                for ( int i = 0; i < nbChars; i++ )
+                                {
+                                    buffer[currPos++] = bytes[pos.end];
+                                    pos.end ++;
+                                }
                             }
                         }
                         else
                         {
-                            sb.append( string.charAt( pos.end ) );
-                            pos.end += nbChars;
+                            for ( int i = 0; i < nbChars; i++ )
+                            {
+                                buffer[currPos++] = bytes[pos.end];
+                                pos.end ++;
+                            }
                         }
                     }
                     else
                     {
                         pos.length = pos.end - pos.start;
-                        String value = sb.toString();
-                        String result = StringTools.trimRight( value, escapedSpace );
-
-                        if ( hasPairChar )
-                        {
-                            return unescapeValue( result );
-                        }
-                        else
+                        
+                        if ( escapedSpace == -1 )
                         {
+                            String result = StringTools.trimRight( StringTools.utf8ToString( buffer, currPos ) );
                             return result;
                         }
                         
+                        String result = StringTools.utf8ToString( buffer, escapedSpace );
+
+                        return result;
                     }
                 }
             }
         }
     }
 
+
     /**
      * Validate this rule : <br>
      * <p>
@@ -581,15 +574,13 @@
      * &lt;quotechar-or-pairs&gt; | e <br>
      * </p>
      *
-     * @param chars
-     *            The char array to parse
-     * @param pos
-     *            The current position in the char array
+     * @param bytes The byte array to parse
+     * @param pos The current position in the byte array
      * @return <code>true</code> if the rule is valid
      */
-    private static boolean isValidAttributeValue( String string, Position pos )
+    private static boolean isValidAttributeValue( byte[] bytes, Position pos )
     {
-        char c = StringTools.charAt( string, pos.start );
+        byte c = bytes[pos.start];
 
         if ( c == '#' )
         {
@@ -598,7 +589,7 @@
             int currentPos = pos.start;
 
             // First, we will count the number of hexPairs
-            while ( DNUtils.parseHexPair( string, currentPos ) >= 0 )
+            while ( DNUtils.parseHexPair( bytes, currentPos ) >= 0 )
             {
                 nbHex++;
                 currentPos += DNUtils.TWO_CHARS;
@@ -608,13 +599,13 @@
 
             // Now, convert the value
             // <attributeValue> ::= '#' <hexstring>
-            if ( DNUtils.parseHexString( string, hexValue, pos ) == DNUtils.PARSING_ERROR )
+            if ( DNUtils.parseHexString( bytes, hexValue, pos ) == DNUtils.PARSING_ERROR )
             {
                 return false;
             }
 
             pos.start--;
-            StringTools.trimRight( string, pos );
+            StringTools.trimRight( bytes, pos );
             pos.length = pos.end - pos.start;
 
             return true;
@@ -631,12 +622,12 @@
             //                                                  <pairchar> <quotechar-or-pairs> | e
             while ( true )
             {
-                if ( StringTools.isCharASCII( string, pos.end, '\\' ) )
+                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
                 {
                     pos.end++;
                     int nbChars = 0;
 
-                    if ( ( nbChars = DNUtils.isPairChar( string, pos.start ) ) != DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.start ) ) != DNUtils.PARSING_ERROR )
                     {
                         pos.end += nbChars;
                     }
@@ -645,7 +636,7 @@
                         return false;
                     }
                 }
-                else if ( ( nbBytes = DNUtils.isQuoteChar( string, pos.end ) ) != DNUtils.PARSING_ERROR )
+                else if ( ( nbBytes = DNUtils.isQuoteChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR )
                 {
                     pos.end += nbBytes;
                 }
@@ -656,7 +647,7 @@
                 }
             }
 
-            if ( StringTools.isCharASCII( string, pos.end, '"' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
             {
                 pos.end++;
                 return true;
@@ -670,14 +661,14 @@
         {
             while ( true )
             {
-                if ( StringTools.isCharASCII( string, pos.end, '\\' ) )
+                if ( StringTools.isCharASCII( bytes, pos.end, '\\' ) )
                 {
                     // '\' <pairchar> <pairs-or-strings>
                     pos.end++;
 
                     int nbChars = 0;
                     
-                    if ( ( nbChars = DNUtils.isPairChar( string, pos.end ) ) == DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR )
                     {
                         return false;
                     }
@@ -691,17 +682,17 @@
                     int nbChars = 0;
 
                     // <stringchar> <pairs-or-strings>
-                    if ( ( nbChars = DNUtils.isStringChar( string, pos.end ) ) != DNUtils.PARSING_ERROR )
+                    if ( ( nbChars = DNUtils.isStringChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR )
                     {
                         // A special case : if we have some spaces before the
                         // '+' character,
                         // we MUST skip them.
-                        if ( StringTools.isCharASCII( string, pos.end, '+' ) )
+                        if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
                         {
                             //StringTools.trimLeft( string, pos );
 
-                            if ( ( DNUtils.isStringChar( string, pos.end ) == DNUtils.PARSING_ERROR )
-                                && ( StringTools.isCharASCII( string, pos.end, '\\' ) == false ) )
+                            if ( ( DNUtils.isStringChar( bytes, pos.end ) == DNUtils.PARSING_ERROR )
+                                && ( StringTools.isCharASCII( bytes, pos.end, '\\' ) == false ) )
                             {
                                 // Ok, we are done with the stringchar.
                                 return true;
@@ -734,14 +725,12 @@
      * &lt;attributeValue&gt; &lt;nameComponents&gt; | e
      * </p>
      *
-     * @param chars
-     *            The char buffer to parse
-     * @param pos
-     *            The current position in the byte buffer
-     * @return The new position in the char buffer, or PARSING_ERROR if the rule
-     *         does not apply to the char buffer
+     * @param bytes The byte buffer to parse
+     * @param pos The current position in the byte buffer
+     * @return The new position in the byte buffer, or PARSING_ERROR if the rule
+     *         does not apply to the byte buffer
      */
-    private static int parseNameComponents( String string, Position pos, Rdn rdn ) throws InvalidNameException
+    private static int parseNameComponents( byte[] bytes, Position pos, Rdn rdn ) throws InvalidNameException
     {
         int newStart = 0;
         String type = null;
@@ -749,9 +738,9 @@
 
         while ( true )
         {
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( StringTools.isCharASCII( string, pos.end, '+' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
             {
                 pos.start++;
             }
@@ -762,18 +751,18 @@
                 return DNUtils.PARSING_OK;
             }
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( ( type = parseAttributeType( string, pos ) ) == null )
+            if ( ( type = parseAttributeType( bytes, pos ) ) == null )
             {
                 return DNUtils.PARSING_ERROR;
             }
 
             pos.start = pos.end;
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( StringTools.isCharASCII( string, pos.end, '=' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '=' ) )
             {
                 pos.start++;
             }
@@ -782,9 +771,9 @@
                 return DNUtils.PARSING_ERROR;
             }
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            value = parseAttributeValue( string, pos );
+            value = parseAttributeValue( bytes, pos );
 
             newStart = pos.end;
 
@@ -810,21 +799,19 @@
      * &lt;attributeValue&gt; &lt;nameComponents&gt; | e
      * </p>
      *
-     * @param chars
-     *            The char buffer to parse
-     * @param pos
-     *            The current position in the byte buffer
+     * @param bytes The byte buffer to parse
+     * @param pos The current position in the byte buffer
      * @return <code>true</code> if the rule is valid
      */
-    private static boolean isValidNameComponents( String string, Position pos, boolean isFirstRdn )
+    private static boolean isValidNameComponents( byte[] bytes, Position pos, boolean isFirstRdn )
     {
         int newStart = 0;
 
         while ( true )
         {
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( StringTools.isCharASCII( string, pos.end, '+' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '+' ) )
             {
                 pos.start++;
             }
@@ -834,18 +821,18 @@
                 return true;
             }
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( !isValidAttributeType( string, pos ) )
+            if ( !isValidAttributeType( bytes, pos ) )
             {
                 return false;
             }
 
             pos.start = pos.end;
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( StringTools.isCharASCII( string, pos.end, '=' ) )
+            if ( StringTools.isCharASCII( bytes, pos.end, '=' ) )
             {
                 pos.start++;
             }
@@ -854,9 +841,9 @@
                 return false;
             }
 
-            StringTools.trimLeft( string, pos );
+            StringTools.trimLeft( bytes, pos );
 
-            if ( !isValidAttributeValue( string, pos ) )
+            if ( !isValidAttributeValue( bytes, pos ) )
             {
                 return false;
             }
@@ -867,35 +854,23 @@
         }
     }
 
+
     /**
-     * Unescape pairChars.
-     * 
-     * A PairChar can be a char if it's 
+     * Parse a NameComponent : <br>
+     * <p>
+     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt; '='
+     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
+     * </p>
      *
-     * @param value The value to modify
-     * @param pos
-     *            The current position in the char array
+     * @param dn The String to parse
+     * @param pos The current position in the buffer
+     * @param rdn The constructed RDN
      * @return The new position in the char array, or PARSING_ERROR if the rule
      *         does not apply to the char array
      */
-    private static Object unescapeValue( String value ) throws IllegalArgumentException
+    public static int parse( String dn, Position pos, Rdn rdn ) throws InvalidNameException
     {
-        byte[] bytes = new byte[value.length()];
-        int pos = 0;
-
-        for ( int i = 0; i < value.length(); i++ ) 
-        {
-            bytes[pos++] = (byte)value.charAt( i );
-        }
-        
-        try
-        {
-            return new String( bytes, "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            return bytes;
-        }
+        return parse( StringTools.getBytesUtf8( dn ), pos, rdn );
     }
 
 
@@ -906,13 +881,13 @@
      * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
      * </p>
      *
-     * @param dn The String to parse
+     * @param dn The byte array to parse
      * @param pos The current position in the buffer
      * @param rdn The constructed RDN
-     * @return The new position in the char array, or PARSING_ERROR if the rule
-     *         does not apply to the char array
+     * @return The new position in the byte array, or PARSING_ERROR if the rule
+     *         does not apply to the byte array
      */
-    public static int parse( String dn, Position pos, Rdn rdn ) throws InvalidNameException
+    public static int parse( byte[] dn, Position pos, Rdn rdn ) throws InvalidNameException
     {
         String type = null;
         Object value = null;
@@ -967,11 +942,12 @@
             return DNUtils.PARSING_ERROR;
         }
         
-        rdn.setUpName( dn.substring( start, pos.end ) );
+        rdn.setUpName( StringTools.utf8ToString( dn, start, pos.end - start ) );
         pos.start = pos.end;
         return DNUtils.PARSING_OK;
     }
 
+
     /**
      * Validate a NameComponent : <br>
      * <p>
@@ -985,6 +961,23 @@
      */
     public static boolean isValid( String dn, Position pos, boolean isfirstRdn )
     {
+        return isValid( StringTools.getBytesUtf8( dn ), pos, isfirstRdn );
+    }
+
+
+    /**
+     * Validate a NameComponent : <br>
+     * <p>
+     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt; '='
+     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
+     * </p>
+     *
+     * @param dn The byte array to parse
+     * @param pos The current position in the buffer
+     * @return <code>true</code> if the RDN is valid
+     */
+    public static boolean isValid( byte[] dn, Position pos, boolean isfirstRdn )
+    {
         StringTools.trimLeft( dn, pos );
 
         pos.end = pos.start;
@@ -1029,6 +1022,7 @@
         return true;
     }
 
+
     /**
      * Parse a NameComponent : <br>
      * <p>
@@ -1036,16 +1030,13 @@
      * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
      * </p>
      *
-     * @param string
-     *            The buffer to parse
-     * @param rdn
-     *            The RDN to fill. Beware that if the RDN is not empty, the new
+     * @param dn The String to parse
+     * @param rdn The RDN to fill. Beware that if the RDN is not empty, the new
      *            AttributeTypeAndValue will be added.
      */
-    public static void parse( String string, Rdn rdn ) throws InvalidNameException
+    public static void parse( String dn, Rdn rdn ) throws InvalidNameException
     {
-        parse( string, new Position(), rdn );
-        rdn.normalize();
+        parse( StringTools.getBytesUtf8( dn ), new Position(), rdn );
     }
 
     /**
@@ -1055,12 +1046,11 @@
      * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
      * </p>
      *
-     * @param string
-     *            The buffer to parse
+     * @param dn The string to parse
      * @return <code>true</code> if the RDN is valid
      */
-    public static boolean isValid( String string )
+    public static boolean isValid( String dn )
     {
-        return isValid( string, new Position(), false );
+        return isValid( StringTools.getBytesUtf8( dn ), new Position(), false );
     }
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=591493&r1=591492&r2=591493&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Fri Nov  2 15:08:03 2007
@@ -188,21 +188,19 @@
      * [0x3D-0x7F] &lt;safe-chars&gt; ::= &lt;safe-char&gt; &lt;safe-chars&gt; | &lt;safe-char&gt; ::=
      * [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes The buffer which contains the data
+     * @param index Current position in the buffer
      * @return The position of the first character which is not a Safe Char
      */
-    public static int parseSafeString( byte[] byteArray, int index )
+    public static int parseSafeString( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return -1;
         }
         else
         {
-            byte c = byteArray[index];
+            byte c = bytes[index];
 
             if ( ( ( c | 0x7F ) != 0x7F ) || ( SAFE_INIT_CHAR[c] == false ) )
             {
@@ -211,9 +209,9 @@
 
             index++;
 
-            while ( index < byteArray.length )
+            while ( index < bytes.length )
             {
-                c = byteArray[index];
+                c = bytes[index];
 
                 if ( ( ( c | 0x7F ) != 0x7F ) || ( SAFE_CHAR[c] == false ) )
                 {
@@ -232,21 +230,19 @@
      * Walk the buffer while characters are Alpha characters : &lt;alpha&gt; ::=
      * [0x41-0x5A] | [0x61-0x7A]
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes 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( byte[] byteArray, int index )
+    public static int parseAlphaASCII( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return -1;
         }
         else
         {
-            byte b = byteArray[index++];
+            byte b = bytes[index++];
 
             if ( StringTools.isAlpha( b ) == false )
             {
@@ -261,56 +257,22 @@
 
 
     /**
-     * Walk the buffer while characters are Alpha characters : &lt;alpha&gt; ::=
-     * [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 ( StringTools.isAlpha( c ) == false )
-            {
-                return PARSING_ERROR;
-            }
-            else
-            {
-                return index;
-            }
-        }
-    }
-
-
-    /**
      * Check if the current character is a Pair Char &lt;pairchar&gt; ::= ',' | '=' |
      * '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes 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( byte[] byteArray, int index )
+    public static boolean isPairChar( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return false;
         }
         else
         {
-            byte c = byteArray[index];
+            byte c = bytes[index];
 
             if ( ( ( c | 0x7F ) != 0x7F )  || ( PAIR_CHAR[c] == false ) )
             {
@@ -318,9 +280,9 @@
             }
             else
             {
-                if ( StringTools.isHex( byteArray, index++ ) )
+                if ( StringTools.isHex( bytes, index++ ) )
                 {
-                    return StringTools.isHex( byteArray, index );
+                    return StringTools.isHex( bytes, index );
                 }
                 else
                 {
@@ -332,63 +294,23 @@
 
 
     /**
-     * Check if the current character is a Pair Char &lt;pairchar&gt; ::= ',' | '=' |
-     * '+' | '<' | '>' | '#' | ';' | '\' | '"' | [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 | 0x7F ) != 0x7F )  || ( PAIR_CHAR[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                if ( StringTools.isHex( charArray, index++ ) )
-                {
-                    return StringTools.isHex( charArray, index );
-                }
-                else
-                {
-                    return true;
-                }
-            }
-        }
-    }
-
-    /**
      * Check if the current character is a Pair Char 
      * 
      * &lt;pairchar&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | 
      *                  '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
      * 
-     * @param string
-     *            The string which contains the data
-     * @param index
-     *            Current position in the string
-     * @return <code>true</code> if the current character is a Pair Char
+     * @param bytes The byte array which contains the data
+     * @param index Current position in the byte array
+     * @return <code>true</code> if the current byte is a Pair Char
      */
-    public static int isPairChar( String string, int index )
+    public static int countPairChar( byte[] bytes, int index )
     {
-        if ( string == null )
+        if ( bytes == null )
         {
             return PARSING_ERROR;
         }
 
-        int length = string.length();
+        int length = bytes.length;
         
         if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
         {
@@ -396,7 +318,7 @@
         }
         else
         {
-            char c = string.charAt( index );
+            byte c = bytes[index];
 
             if ( ( ( c | 0x7F ) != 0x7F )  || ( PAIR_CHAR[c] == false ) )
             {
@@ -404,9 +326,9 @@
             }
             else
             {
-                if ( StringTools.isHex( string, index++ ) )
+                if ( StringTools.isHex( bytes, index++ ) )
                 {
-                    return StringTools.isHex( string, index ) ? 2 : PARSING_ERROR;
+                    return StringTools.isHex( bytes, index ) ? 2 : PARSING_ERROR;
                 }
                 else
                 {
@@ -421,22 +343,20 @@
      * Check if the current character is a String Char. Chars are Unicode, not
      * ASCII. &lt;stringchar&gt; ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes 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( byte[] byteArray, int index )
+    public static int isStringChar( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return -1;
         }
         else
         {
-            byte c = byteArray[index];
+            byte c = bytes[index];
 
             if ( ( c | 0x3F ) == 0x3F )
             {
@@ -444,80 +364,7 @@
             }
             else
             {
-                return StringTools.countBytesPerChar( byteArray, index );
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is a String Char. Chars are Unicode, not
-     * ASCII. &lt;stringchar&gt; ::= [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 String Char. Chars are Unicode, not
-     * ASCII. &lt;stringchar&gt; ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
-     * 
-     * @param string
-     *            The string which contains the data
-     * @param index
-     *            Current position in the string
-     * @return The current char if it is a String Char, or '#' (this is simpler
-     *         than throwing an exception :)
-     */
-    public static int isStringChar( String string, int index )
-    {
-        if ( string == null )
-        {
-            return PARSING_ERROR;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return PARSING_ERROR;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c | 0x3F) == 0x3F )
-            {
-                return STRING_CHAR[ c ];
-            }
-            else
-            {
-                return ONE_CHAR;
+                return StringTools.countBytesPerChar( bytes, index );
             }
         }
     }
@@ -527,20 +374,20 @@
      * Check if the current character is a Quote Char We are testing Unicode
      * chars &lt;quotechar&gt; ::= [0x00-0xFFFF] - [\"]
      * 
-     * @param byteArray The buffer which contains the data
+     * @param bytes 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( byte[] byteArray, int index )
+    public static int isQuoteChar( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return -1;
         }
         else
         {
-            byte c = byteArray[index];
+            byte c = bytes[index];
 
             if ( ( c == '\\' ) || ( c == '"' ) )
             {
@@ -548,75 +395,7 @@
             }
             else
             {
-                return StringTools.countBytesPerChar( byteArray, index );
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is a Quote Char We are testing Unicode
-     * chars &lt;quotechar&gt; ::= [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;
-            }
-        }
-    }
-
-    /**
-     * Check if the current character is a Quote Char We are testing Unicode
-     * chars &lt;quotechar&gt; ::= [0x00-0xFFFF] - [\"]
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     *
-     * @return <code>true</code> if the current character is a Quote Char
-     */
-    public static int isQuoteChar( String string, int index )
-    {
-        if ( string == null )
-        {
-            return PARSING_ERROR;
-        }
-
-        int length = string.length();
-
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return PARSING_ERROR;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c == '\\' ) || ( c == '"' ) )
-            {
-                return PARSING_ERROR;
-            }
-            else
-            {
-                return ONE_CHAR;
+                return StringTools.countBytesPerChar( bytes, index );
             }
         }
     }
@@ -625,18 +404,16 @@
     /**
      * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes 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( byte[] byteArray, int index )
+    public static int parseHexPair( byte[] bytes, int index )
     {
-        if ( StringTools.isHex( byteArray, index ) )
+        if ( StringTools.isHex( bytes, index ) )
         {
-            if ( StringTools.isHex( byteArray, index + 1 ) )
+            if ( StringTools.isHex( bytes, index + 1 ) )
             {
                 return index + 2;
             }
@@ -655,91 +432,30 @@
     /**
      * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
      * 
-     * @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.
+     * @param bytes The byte array which contains the data
+     * @param index Current position in the byte array
+     * @return The new position, -1 if the byte array does not contain an HexPair,
+     *         -2 if the byte array contains an hex byte but not two.
      */
-    public static int parseHexPair( char[] charArray, int index )
+    private static byte getHexPair( byte[] bytes, int index )
     {
-        if ( StringTools.isHex( charArray, index ) )
-        {
-            if ( StringTools.isHex( charArray, index + 1 ) )
-            {
-                return index + TWO_CHARS;
-            }
-            else
-            {
-                return BAD_HEX_PAIR;
-            }
-        }
-        else
-        {
-            return PARSING_ERROR;
-        }
-    }
-
-    /**
-     * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
-     * 
-     * @param string
-     *            The string which contains the data
-     * @param index
-     *            Current position in the string
-     * @return The new position, -1 if the string does not contain an HexPair,
-     *         -2 if the string contains an hex byte but not two.
-     */
-    public static int parseHexPair( String string, int index )
-    {
-        if ( StringTools.isHex( string, index ) )
-        {
-            if ( StringTools.isHex( string, index + 1 ) )
-            {
-                return index + TWO_CHARS;
-            }
-            else
-            {
-                return BAD_HEX_PAIR;
-            }
-        }
-        else
-        {
-            return PARSING_ERROR;
-        }
-    }
-
-    /**
-     * Parse an hex pair &lt;hexpair&gt; ::= &lt;hex&gt; &lt;hex&gt;
-     * 
-     * @param string
-     *            The string which contains the data
-     * @param index
-     *            Current position in the string
-     * @return The new position, -1 if the string does not contain an HexPair,
-     *         -2 if the string contains an hex byte but not two.
-     */
-    private static byte getHexPair( String string, int index )
-    {
-    	return StringTools.getHexValue( string.charAt( index ), string.charAt( index + 1 ) );
+        return StringTools.getHexValue( bytes[index], bytes[index + 1] );
     }
 
+    
     /**
      * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
      * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | e
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes 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( byte[] byteArray, int index )
+    public static int parseHexString( byte[] bytes, int index )
     {
-        int result = parseHexPair( byteArray, index );
+        int result = parseHexPair( bytes, index );
 
         if ( result < 0 )
         {
@@ -750,7 +466,7 @@
             index += 2;
         }
 
-        while ( ( result = parseHexPair( byteArray, index ) ) >= 0 )
+        while ( ( result = parseHexPair( bytes, index ) ) >= 0 )
         {
             index += 2;
         }
@@ -763,85 +479,18 @@
      * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
      * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | 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 );
-    }
-
-    /**
-     * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
-     * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | e
-     * 
-     * @param string
-     *            The string which contains the data
-     * @param pos
-     *            Current position in the string
-     * @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( String string, Position pos )
-    {
-        pos.end = pos.start;
-        int result = parseHexPair( string, pos.start );
-
-        if ( result < 0 )
-        {
-            return PARSING_ERROR;
-        }
-        else
-        {
-            pos.end += TWO_CHARS;
-        }
-
-        while ( ( result = parseHexPair( string, pos.end ) ) >= 0 )
-        {
-            pos.end += TWO_CHARS;
-        }
-
-        return ( ( result == BAD_HEX_PAIR ) ? PARSING_ERROR : PARSING_OK );
-    }
-
-    /**
-     * Parse an hex string, which is a list of hex pairs &lt;hexstring&gt; ::=
-     * &lt;hexpair&gt; &lt;hexpairs&gt; &lt;hexpairs&gt; ::= &lt;hexpair&gt; &lt;hexpairs&gt; | e
-     * 
-     * @param string The string which contains the data
+     * @param bytes The byte array which contains the data
      * @param hex The result as a byte array
      * @param pos Current position in the string
      * @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( String string, byte[] hex, Position pos )
+    public static int parseHexString( byte[] bytes, byte[] hex, Position pos )
     {
-    	int i = 0;
+        int i = 0;
         pos.end = pos.start;
-        int result = parseHexPair( string, pos.start );
+        int result = parseHexPair( bytes, pos.start );
 
         if ( result < 0 )
         {
@@ -849,40 +498,39 @@
         }
         else
         {
-        	hex[i++] = getHexPair( string, pos.end );
+            hex[i++] = getHexPair( bytes, pos.end );
             pos.end += TWO_CHARS;
         }
 
-        while ( ( result = parseHexPair( string, pos.end ) ) >= 0 )
+        while ( ( result = parseHexPair( bytes, pos.end ) ) >= 0 )
         {
-        	hex[i++] = getHexPair( string, pos.end );
+            hex[i++] = getHexPair( bytes, pos.end );
             pos.end += TWO_CHARS;
         }
 
         return ( ( result == BAD_HEX_PAIR ) ? PARSING_ERROR : PARSING_OK );
     }
 
+    
     /**
      * Walk the buffer while characters are Base64 characters : &lt;base64-string&gt;
      * ::= &lt;base64-char&gt; &lt;base64-chars&gt; &lt;base64-chars&gt; ::= &lt;base64-char&gt;
      * &lt;base64-chars&gt; | &lt;base64-char&gt; ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D |
      * [0x41-0x5A] | [0x61-0x7A]
      * 
-     * @param byteArray
-     *            The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
+     * @param bytes The buffer which contains the data
+     * @param index Current position in the buffer
      * @return The position of the first character which is not a Base64 Char
      */
-    public static int parseBase64String( byte[] byteArray, int index )
+    public static int parseBase64String( byte[] bytes, int index )
     {
-        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) || ( index >= byteArray.length ) )
+        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
         {
             return -1;
         }
         else
         {
-            byte c = byteArray[index];
+            byte c = bytes[index];
 
             if ( ( ( c | 0x7F ) != 0x7F )  || ( BASE64_CHAR[c] == false ) )
             {
@@ -891,9 +539,9 @@
 
             index++;
 
-            while ( index < byteArray.length )
+            while ( index < bytes.length )
             {
-                c = byteArray[index];
+                c = bytes[index];
 
                 if ( ( ( c | 0x7F ) != 0x7F )  || ( BASE64_CHAR[c] == false ) )
                 {