directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159950 - directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java
Date Sun, 03 Apr 2005 18:22:23 GMT
Author: elecharny
Date: Sun Apr  3 11:22:22 2005
New Revision: 159950

URL: http://svn.apache.org/viewcvs?view=rev&rev=159950
Log:
- Corrected some metho to handle Unicode encoded bytes 
- reverted from char[] to byte[], as it was before (Unicode again ...)

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java?view=diff&r1=159949&r2=159950
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/utils/DNUtils.java
Sun Apr  3 11:22:22 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1.ldap.codec.utils;
 
+import org.apache.asn1.util.StringUtils;
+
 /**
  * Utility class used by the LdapDN Parser.
  *
@@ -28,176 +30,129 @@
     /** <safe-init-char>    ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39]
| 0x3B | [0x3D-0x7F] */
     private static final boolean[] SAFE_INIT_CHAR =
     {
-        false, true, true,  true, true,  true,  true, true, 
-		true,  true, false, true, true,  false, true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true,
-        false, true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, false, true, false, true,  true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true,
-        true,  true, true,  true, true,  true,  true, true, 
-		true,  true, true,  true, true,  true,  true, true
+        false, true, true, true, true, true, true, true, true, true, false, true, true, false,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, false, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
false,
+        true, false, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true
     };
 
     /** <safe-char>        ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F] */
     private static final boolean[] SAFE_CHAR =
     {
-        false, true, true,  true, true, true,  true, true, 
-		true,  true, false, true, true, false, true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true, 
-        true,  true, true,  true, true, true,  true, true, 
-		true,  true, true,  true, true, true,  true, true 
+        false, true, true, true, true, true, true, true, true, true, false, true, true, false,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true
     };
 
     /** <base64-char>    ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-0x5A] | [0x61-0x7A]
*/
     private static final boolean[] BASE64_CHAR =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false, 
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false, 
-        false, false, false, false, false, false, false, false, 
-		false, false, false, true,  false, false, false, true, 
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  false, false, false, true,  false, false, 
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true, 
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false, 
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true, 
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false 
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, true, false, false, false, true, true, true, true, true,
true,
+        true, true, true, true, true, false, false, false, true, false, false, false, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, false, false, false, false,
false,
+        false, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, false, false,
+        false, false, false
     };
 
     /** <alpha>    ::= [0x41-0x5A] | [0x61-0x7A] */
     private static final boolean[] ALPHA =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, false, false, false,
+        false, false, false, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        false, false, false, false, false
     };
 
     /** <alpha> | <digit> | '-' */
     private static final boolean[] CHAR =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, true,  false, false,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  false, false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  true,  true,  true,  true,  true,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  true,  false, false, false, false, false
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, true, false, false, true, true, true, true,
true,
+        true, true, true, true, true, false, false, false, false, false, false, false, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, false, false, false, false,
false,
+        false, true, true, true, true, true, true, true, true, true, true, true, true, true,
true,
+        true, true, true, true, true, true, true, true, true, true, true, true, false, false,
+        false, false, false
     };
 
     /** '"'  | '#'  | '+'  | ','  | [0-9] | ';'  | '<'  | '='  | '>'  | [A-F] | '\'
| [a-f] 
      * 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E | [0x41-0x46]
| 0x5C | [0x61-0x66] */
     private static final boolean[] PAIR_CHAR =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, true,  true,  false, false, false, false, 
-		false, false, false, true,  true,  false, false, false,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  false, true,  true,  true,  true,  false,
-        false, true,  true,  true,  true,  true,  true,  false, 
-        false, false, false, false, false, false, false, false, 
-        false, false, false, false, false, false, false, false, 
-        false, false, false, false, true,  false, false, false, 
-        false, true,  true,  true,  true,  true,  true,  false, 
-        false, false, false, false, false, false, false, false, 
-        false, false, false, false, false, false, false, false, 
-        false, false, false, false, false, false, false, false 
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, true, true, false, false,
false,
+        false, false, false, false, true, true, false, false, false, true, true, true, true,
true,
+        true, true, true, true, true, false, true, true, true, true, false, false, true,
true,
+        true, true, true, true, false, false, false, false, false, false, false, false, false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
true,
+        false, false, false, false, true, true, true, true, true, true, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false
     };
 
     /** '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' */
     private static final boolean[] DIGIT =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, true, true, true,
true,
+        true, true, true, true, true, true, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false,
     };
 
     /** <hex>    ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] */
     private static final boolean[] HEX =
     {
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        true,  true,  true,  true,  true,  true,  true,  true, 
-		true,  true,  false, false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false,
-        false, true,  true,  true,  true,  true,  true,  false, 
-		false, false, false, false, false, false, false, false,
-        false, false, false, false, false, false, false, false, 
-		false, false, false, false, false, false, false, false
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false, true, true, true,
true,
+        true, true, true, true, true, true, false, false, false, false, false, false, false,
true,
+        true, true, true, true, true, false, false, false, false, false, false, false, false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, true, true, true, true, true, true, false, false,
false,
+        false, false, false, false, false, false, false, false, false, false, false, false,
false,
+        false, false, false, false, false, false, false, false, false
     };
 
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
-     * Test if the current character is equal to a specific character
+     * Test if the current character is equal to a specific character.
+     * This function works only for character between 0 and 127, as it
+     * does compare a byte and a char (which is 16 bits wide)
+     * 
      *
      * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
@@ -205,19 +160,16 @@
      *
      * @return <code>true</code> if the current character equals the given character.
      */
-    public static boolean isChar( char[] charArray, int index, char car )
+    public static boolean isCharASCII( byte[] byteArray, int index, char car )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return false;
         }
         else
         {
-
-            return ( ( charArray[index] == car ) ? true : false );
+            return ( ( byteArray[index] == car ) ? true : false );
         }
     }
 
@@ -230,18 +182,16 @@
      *
      * @return <code>true</code> if the current character is a Digit
      */
-    public static boolean isDigit( char[] charArray, int index )
+    public static boolean isDigit( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return false;
         }
         else
         {
-            return ( ( ( charArray[index] > 127 ) || ! DIGIT[charArray[index]] ) ? false
: true );
+            return ( ( ( byteArray[index] > 127 ) || ! DIGIT[byteArray[index]] ) ? false
: true );
         }
     }
 
@@ -249,22 +199,19 @@
      * Test if the current character is a digit
      * <digit>    ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray The buffer which contains the data
      *
      * @return <code>true</code> if the current character is a Digit
      */
-    public static boolean isDigit( char[] charArray )
+    public static boolean isDigit( byte[] byteArray )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) )
         {
-
             return false;
         }
         else
         {
-
-            return ( ( ( charArray[0] > 127 ) || ! DIGIT[charArray[0]] ) ? false : true
);
+            return ( ( ( byteArray[0] > 127 ) || ! DIGIT[byteArray[0]] ) ? false : true
);
         }
     }
 
@@ -272,38 +219,33 @@
      * Test if the current character is an Alpha character :
      *  <alpha>    ::= [0x41-0x5A] | [0x61-0x7A]
      * 
-     * @param charArray The buffer which contains the data
+     * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
      *
      * @return <code>true</code> if the current character is an Alpha character
      */
-    public static boolean isAlpha( char[] charArray, int index )
+    public static boolean isAlphaASCII( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return false;
         }
         else
         {
-
-            char c = charArray[index++];
+            byte c = byteArray[index++];
 
             if ( ( c > 127 ) || ( ALPHA[c] == false ) )
             {
-
                 return false;
             }
             else
             {
-
                 return true;
             }
         }
     }
-    
+
     /**
      * Walk the buffer while characters are Safe String characters :
      *  <safe-string>    ::= <safe-init-char> <safe-chars>
@@ -311,40 +253,35 @@
      *  <safe-chars>     ::= <safe-char> <safe-chars> |
      *  <safe-char>      ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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( char[] charArray, int index )
+    public static int parseSafeString( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return -1;
         }
         else
         {
-
-            char c = charArray[index];
+            byte c = byteArray[index];
 
             if ( ( c > 127 ) || ( SAFE_INIT_CHAR[c] == false ) )
             {
-
                 return -1;
             }
 
             index++;
 
-            while ( index < charArray.length )
+            while ( index < byteArray.length )
             {
-                c = charArray[index];
+                c = byteArray[index];
 
                 if ( ( c > 127 ) || ( SAFE_CHAR[c] == false ) )
                 {
-
                     break;
                 }
 
@@ -359,33 +296,28 @@
      * Walk the buffer while characters are Alpha characters :
      *  <alpha>    ::= [0x41-0x5A] | [0x61-0x7A]
      * 
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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 parseAlpha( char[] charArray, int index )
+    public static int parseAlphaASCII( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return -1;
         }
         else
         {
-
-            char c = charArray[index++];
+            byte c = byteArray[index++];
 
             if ( ( c > 127 ) || ( ALPHA[c] == false ) )
             {
-
                 return -1;
             }
             else
             {
-
                 return index;
             }
         }
@@ -395,33 +327,28 @@
      * Check if the current character is an Hex Char
      *  <hex>    ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
      * 
-     * @param charArray The buffer which contains the data
+     * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
      *
      * @return <code>true</code> if the current character is a Hex Char
      */
-    public static boolean isHex( char[] charArray, int index )
+    public static boolean isHex( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return false;
         }
         else
         {
-
-            char c = charArray[index];
+            byte c = byteArray[index];
 
             if ( ( c > 127 ) || ( HEX[c] == false ) )
             {
-
                 return false;
             }
             else
             {
-
                 return true;
             }
         }
@@ -431,66 +358,60 @@
      * 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 byteArray 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 )
+    public static boolean isPairChar( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
             return false;
         }
         else
         {
-
-            char c = charArray[index];
+            byte c = byteArray[index];
 
             if ( ( c > 127 ) || ( PAIR_CHAR[c] == false ) )
             {
-
                 return false;
             }
             else
             {
-
-            	if (isHex(charArray, index++)) 
-            	{
-            		return isHex(charArray, index);
-            	} 
-            	else 
-            	{
-            		return true;
-            	}
+                if ( isHex( byteArray, index++ ) )
+                {
+                    return isHex( byteArray, index );
+                }
+                else
+                {
+                    return true;
+                }
             }
         }
     }
 
     /**
-     * Check if the current character is a String Char
-     *  <stringchar>    ::= [0x00-0xFF] - [,=+<>#;\"\n\r]
-     * @param charArray The buffer which contains the data
+     * Check if the current character is a String Char.
+     * Chars are Unicode, not ASCII.
+     *  <stringchar>    ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]
+     * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
      *
-     * @return <code>true</code> if the current character is a String Char
+     * @return The current char if it is a String Char, or '#' (this is
+     * simpler than throwing an exception :)
      */
-    public static boolean isStringChar( char[] charArray, int index )
+    public static int isStringChar( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-
-            return false;
+            return -1;
         }
         else
         {
-
-            char c = charArray[index++];
+            byte c = byteArray[index];
 
             if ( ( c == 0x0A ) ||
                     ( c == 0x0D ) ||
@@ -503,43 +424,43 @@
                     ( c == '=' ) ||
                     ( c == '>' ) )
             {
-                return false;
+                return -1;
             }
             else
             {
-                return true;
+                return StringUtils.countBytesPerChar(byteArray, index);
             }
         }
     }
 
     /**
      * Check if the current character is a Quote Char
-     *  <quotechar>    ::= [0x00-0xFF] - [\"]
+     * We are testing Unicode chars
+     *  <quotechar>    ::= [0x00-0xFFFF] - [\"]
      * 
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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 boolean isQuoteChar( char[] charArray, int index )
+    public static int isQuoteChar( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
-            return false;
+            return -1;
         }
         else
         {
-            char c = charArray[index++];
+            byte c = byteArray[index];
 
             if ( ( c == '\\' ) || ( c == '"' ) )
             {
-                return false;
+                return -1;
             }
             else
             {
-                return true;
+                return StringUtils.countBytesPerChar(byteArray, index);
             }
         }
     }
@@ -548,25 +469,24 @@
      * Parse an hex pair
      *   <hexpair>    ::= <hex> <hex>
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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 )
+    public static int parseHexPair( byte[] byteArray, int index )
     {
-
-        if ( isHex( charArray, index ))
+        if ( isHex( byteArray, index ) )
         {
-        	if (isHex( charArray, index + 1 ))
-        	{
-        		return index + 2;
-        	}
-        	else
-        	{
-        		return -2;
-        	}
+            if ( isHex( byteArray, index + 1 ) )
+            {
+                return index + 2;
+            }
+            else
+            {
+                return -2;
+            }
         }
         else
         {
@@ -579,54 +499,52 @@
      *  <hexstring>    ::= <hexpair> <hexpairs>
      *  <hexpairs>    ::= <hexpair> <hexpairs> | e
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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 )
+    public static int parseHexString( byte[] byteArray, int index )
     {
+        int result = parseHexPair( byteArray, index );
 
-    	int result = parseHexPair( charArray, index );
-    	
-    	if (result < 0) 
-    	{
-    		return -1;
-		}
-    	else
-    	{
-			index += 2;
-    	}
+        if ( result < 0 )
+        {
+            return -1;
+        }
+        else
+        {
+            index += 2;
+        }
 
-        while ((result = parseHexPair( charArray, index )) >= 0 )
+        while ( ( result = parseHexPair( byteArray, index ) ) >= 0 )
         {
             index += 2;
         }
 
-        return (result == -2 ? -1 : index);
+        return ( ( result == -2 ) ? -1 : index );
     }
 
     /**
-     * Check if the current character is a CHAR.
+     * Check if the current character is an 7 bits ASCII CHAR (between 0 and 127).
      *   <char>    ::= <alpha> | <digit> | '-'
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
      *
      * @return The position of the next character, if the current one is a CHAR.
      */
-    public static int parseChar( char[] charArray, int index )
+    public static int parseCharASCII( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
             return -1;
         }
         else
         {
-            char c = charArray[index++];
+            byte c = byteArray[index++];
 
             if ( ( c > 127 ) || ( CHAR[c] == false ) )
             {
@@ -641,27 +559,25 @@
 
     /**
      * Walk the buffer while characters are Base64 characters : 
-     * 	<base64-string>      ::= <base64-char> <base64-chars>
+     *     <base64-string>      ::= <base64-char> <base64-chars>
      *  <base64-chars>       ::= <base64-char> <base64-chars> |
      *  <base64-char>        ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-0x5A] | [0x61-0x7A]
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray 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( char[] charArray, int index )
+    public static int parseBase64String( byte[] byteArray, int index )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( index < 0 ) ||
-                ( index >= charArray.length ) )
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( index < 0 ) ||
+                ( index >= byteArray.length ) )
         {
             return -1;
         }
         else
         {
-
-            char c = charArray[index];
+            byte c = byteArray[index];
 
             if ( ( c > 127 ) || ( BASE64_CHAR[c] == false ) )
             {
@@ -670,9 +586,9 @@
 
             index++;
 
-            while ( index < charArray.length )
+            while ( index < byteArray.length )
             {
-                c = charArray[index];
+                c = byteArray[index];
 
                 if ( ( c > 127 ) || ( BASE64_CHAR[c] == false ) )
                 {
@@ -689,27 +605,24 @@
     /**
      * Check if a text is present at the current position in a buffer.
      *
-     * @param charArray The buffer which contains the data
+     * @param byteArray The buffer which contains the data
      * @param index Current position in the buffer
      * @param text The text we want to check
      *
      * @return <code>true</code> if the buffer contains the text.
      */
-    public static int areEquals( char[] charArray, int index, String text )
+    public static int areEquals( byte[] byteArray, int index, String text )
     {
-
-        if ( ( charArray == null ) || ( charArray.length == 0 ) || ( charArray.length <=
index ) ||
+        if ( ( byteArray == null ) || ( byteArray.length == 0 ) || ( byteArray.length <=
index ) ||
                 ( index < 0 ) || ( text == null ) )
         {
-
             return -1;
         }
         else
         {
-        	char[] data = new char[text.length()];
-        	
-        	text.getChars(0, text.length(), data, 0);
-        	return areEquals(charArray, index, data);
+            byte[] data = text.getBytes();
+
+            return areEquals( byteArray, index, data );
         }
     }
 
@@ -725,26 +638,58 @@
     public static int areEquals( char[] charArray, int index, char[] charArray2 )
     {
 
-        if ( ( charArray == null ) || 
-        		( charArray.length == 0 ) || 
-				( charArray.length <= index ) ||
-                ( index < 0 ) || 
-				( charArray2 == null ) || 
-				( charArray2.length == 0 ) || 
-				( charArray2.length > charArray.length + index ) )
+        if ( ( charArray == null ) ||
+                ( charArray.length == 0 ) ||
+                ( charArray.length <= index ) ||
+                ( index < 0 ) ||
+                ( charArray2 == null ) ||
+                ( charArray2.length == 0 ) ||
+                ( charArray2.length > ( charArray.length + index ) ) )
         {
-
             return -1;
         }
         else
         {
-
             for ( int i = 0; i < charArray2.length; i++ )
             {
-
                 if ( charArray[index++] != charArray2[i] )
                 {
+                    return -1;
+                }
+            }
+
+            return index;
+        }
+    }
 
+    /**
+     * Check if a text is present at the current position in a buffer.
+     *
+     * @param byteArray The buffer which contains the data
+     * @param index Current position in the buffer
+     * @param byteArray2 The text we want to check
+     *
+     * @return <code>true</code> if the buffer contains the text.
+     */
+    public static int areEquals( byte[] byteArray, int index, byte[] byteArray2 )
+    {
+
+        if ( ( byteArray == null ) ||
+                ( byteArray.length == 0 ) ||
+                ( byteArray.length <= index ) ||
+                ( index < 0 ) ||
+                ( byteArray2 == null ) ||
+                ( byteArray2.length == 0 ) ||
+                ( byteArray2.length > ( byteArray.length + index ) ) )
+        {
+            return -1;
+        }
+        else
+        {
+            for ( int i = 0; i < byteArray2.length; i++ )
+            {
+                if ( byteArray[index++] != byteArray2[i] )
+                {
                     return -1;
                 }
             }



Mime
View raw message