directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1062251 [9/13] - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-api/src/main/java/org/apache/director...
Date Sat, 22 Jan 2011 20:08:59 GMT
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=1062251&r1=1062250&r2=1062251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sat Jan 22 20:08:48 2011
@@ -20,27 +20,19 @@
 package org.apache.directory.shared.ldap.util;
 
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileFilter;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
-import javax.naming.InvalidNameException;
-
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.StringValue;
 import org.apache.directory.shared.ldap.schema.syntaxCheckers.UuidSyntaxChecker;
+
+import org.apache.directory.shared.util.Hex;
 import org.apache.directory.shared.util.Strings;
 
 
@@ -60,394 +52,14 @@ public final class StringTools
     {
     }
 
-    /** The default charset, because it's not provided by JDK 1.5 */
-    static String defaultCharset = null;
-    
 
-    
     // ~ Static fields/initializers
     // -----------------------------------------------------------------
 
-    /** Hex chars */
-    public static final byte[] HEX_CHAR = new byte[]
-        { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
-    private static final int UTF8_MULTI_BYTES_MASK = 0x0080;
-
-    private static final int UTF8_TWO_BYTES_MASK = 0x00E0;
-
-    private static final int UTF8_TWO_BYTES = 0x00C0;
-
-    private static final int UTF8_THREE_BYTES_MASK = 0x00F0;
-
-    private static final int UTF8_THREE_BYTES = 0x00E0;
-
-    private static final int UTF8_FOUR_BYTES_MASK = 0x00F8;
-
-    private static final int UTF8_FOUR_BYTES = 0x00F0;
-
-    private static final int UTF8_FIVE_BYTES_MASK = 0x00FC;
-
-    private static final int UTF8_FIVE_BYTES = 0x00F8;
-
-    private static final int UTF8_SIX_BYTES_MASK = 0x00FE;
-
-    private static final int UTF8_SIX_BYTES = 0x00FC;
-
-    /** <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 
-        };
-
-    /** <alpha-lower-case> ::= [0x61-0x7A] */
-    private static final boolean[] ALPHA_LOWER_CASE =
-        { 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, 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 
-        };
-
-    /** <alpha-upper-case> ::= [0x41-0x5A] */
-    private static final boolean[] ALPHA_UPPER_CASE =
-        { 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, 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, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-        };
-
-    /** <alpha-digit> | <digit> */
-    private static final boolean[] ALPHA_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, true,  true,  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 
-        };
-
-    /** %01-%27 %2B-%5B %5D-%7F */
-    private static final boolean[] UNICODE_SUBSET =
-        { 
-            false, true,  true,  true,  true,  true,  true,  true, // '\0'
-            true,  true,  true,  true,  true,  true,  true,  true,
-            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, true,  true,  true,  true,  true, // '(', ')', '*'
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true,
-            true,  true,  true,  true,  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,  true,  true,
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  true,  true,  true,  true,  true,  true,
-        };
-
-    /** '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
-        };
-
-    /** <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 };
-    
-    /** A table containing booleans when the corresponding char is printable */
-    private static final boolean[] IS_PRINTABLE_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, // ---, ---, ---, ---, ---, ---, ---, ---
-        true,  false, false, false, false, false, false, true,  // ' ', ---, ---, ---, ---, ---, ---, "'" 
-        true,  true,  false, true,  true,  true,  true,  true,  // '(', ')', ---, '+', ',', '-', '.', '/'
-        true,  true,  true,  true,  true,  true,  true,  true,  // '0', '1', '2', '3', '4', '5', '6', '7',  
-        true,  true,  true,  false, false, true,  false, true,  // '8', '9', ':', ---, ---, '=', ---, '?'
-        false, true,  true,  true,  true,  true,  true,  true,  // ---, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
-        true,  true,  true,  true,  true,  true,  true,  true,  // 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'
-        true,  true,  true,  true,  true,  true,  true,  true,  // 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W'
-        true,  true,  true,  false, false, false, false, false, // 'X', 'Y', 'Z', ---, ---, ---, ---, ---
-        false, true,  true,  true,  true,  true,  true,  true,  // ---, 'a', 'b', 'c', 'd', 'e', 'f', 'g' 
-        true,  true,  true,  true,  true,  true,  true,  true,  // 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'
-        true,  true,  true,  true,  true,  true,  true,  true,  // 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'
-        true,  true,  true,  false, false, false, false, false  // 'x', 'y', 'z', ---, ---, ---, ---, ---
-        };
-
-
-    /** <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] */
-    private static final byte[] HEX_VALUE =
-        { 
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00 -> 0F
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10 -> 1F
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20 -> 2F
-             0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1, // 30 -> 3F ( 0, 1,2, 3, 4,5, 6, 7, 8, 9 )
-            -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 40 -> 4F ( A, B, C, D, E, F )
-            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 50 -> 5F
-            -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1  // 60 -> 6F ( a, b, c, d, e, f )
-        };
-
-    
-    private static final char[] TO_LOWER_CASE =
-    {
-        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
-        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-        0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
-        ' ',  0x21, 0x22, 0x23, 0x24, 0x25, 0x26, '\'',
-        '(',  ')',  0x2A, '+',  ',',  '-',  '.',  '/',
-        '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',  
-        '8',  '9',  ':',  0x3B, 0x3C, '=',  0x3E, '?',
-        0x40, 'a',  'b',  'c',  'd',  'e',  'f',  'g', 
-        'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
-        'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
-        'x',  'y',  'z',  0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
-        0x60, 'a',  'b',  'c',  'd',  'e',  'f',  'g',
-        'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
-        'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
-        'x',  'y',  'z',  0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
-        0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-        0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
-        0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
-        0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
-        0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
-        0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
-        0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
-        0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
-        0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
-        0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
-        0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
-        0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
-        0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
-        0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
-        0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
-        0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
-    };
-    
-
-    /** upperCase = 'A' .. 'Z', '0'..'9', '-' */
-    private static final char[] UPPER_CASE =
-        { 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0, '-',   0,   0, 
-            '0', '1', '2', '3', '4', '5', '6', '7', 
-            '8', '9',   0,   0,   0,   0,   0,   0, 
-              0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
-            'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
-            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 
-            'X', 'Y', 'Z',   0,   0,   0,   0,   0, 
-              0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
-            'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
-            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 
-            'X', 'Y', 'Z',   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0, 
-              0,   0,   0,   0,   0,   0,   0,   0 
-        };
-    
-    private static final int CHAR_ONE_BYTE_MASK = 0xFFFFFF80;
-
-    private static final int CHAR_TWO_BYTES_MASK = 0xFFFFF800;
-
-    private static final int CHAR_THREE_BYTES_MASK = 0xFFFF0000;
-
-    private static final int CHAR_FOUR_BYTES_MASK = 0xFFE00000;
-
-    private static final int CHAR_FIVE_BYTES_MASK = 0xFC000000;
-
-    private static final int CHAR_SIX_BYTES_MASK = 0x80000000;
-
-    public static final int NOT_EQUAL = -1;
 
     // The following methods are taken from org.apache.commons.lang.StringUtils
 
     /**
-     * The empty String <code>""</code>.
-     * 
-     * @since 2.0
-     */
-    public static final String EMPTY = "";
-
-    /**
-     * The empty byte[]
-     */
-    public static final byte[] EMPTY_BYTES = new byte[]
-        {};
-
-    /**
-     * The empty String[]
-     */
-    public static final String[] EMPTY_STRINGS = new String[]
-        {};
-
-    /**
-     * Rewrote the toLowercase method to improve performances.
-     * In Ldap, attributesType are supposed to use ASCII chars :
-     * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
-     * 
-     * @param value The String to lowercase
-     * @return The lowercase string
-     */
-    public static String toLowerCase( String value )
-    {
-        if ( ( null == value ) || ( value.length() == 0 ) )
-        {
-            return "";
-        }
-        
-        char[] chars = value.toCharArray();
-        
-        for ( int i = 0; i < chars.length; i++ )
-        {
-            chars[i] = TO_LOWER_CASE[ chars[i] ];
-        }
-        
-        return new String( chars );
-    }
-    
-    /**
-     * Rewrote the toLowercase method to improve performances.
-     * In Ldap, attributesType are supposed to use ASCII chars :
-     * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
-     * 
-     * @param value The String to uppercase
-     * @return The uppercase string
-     */
-    public static String toUpperCase( String value )
-    {
-        if ( ( null == value ) || ( value.length() == 0 ) )
-        {
-            return "";
-        }
-        
-        char[] chars = value.toCharArray();
-        
-        for ( int i = 0; i < chars.length; i++ )
-        {
-            chars[i] = UPPER_CASE[ chars[i] ];
-        }
-        
-        return new String( chars );
-    }
-    
-    /**
      * Creates a regular expression from an LDAP substring assertion filter
      * specification.
      * 
@@ -682,2503 +294,43 @@ public final class StringTools
         }
     }
 
-    /**
-     * Return the Unicode char which is coded in the bytes at position 0.
-     * 
-     * @param bytes The byte[] represntation of an Unicode string.
-     * @return The first char found.
-     */
-    public static char bytesToChar( byte[] bytes )
-    {
-        return bytesToChar( bytes, 0 );
-    }
-
-
-    /**
-     * Count the number of bytes needed to return an Unicode char. This can be
-     * from 1 to 6.
-     * 
-     * @param bytes The bytes to read
-     * @param pos Position to start counting. It must be a valid start of a
-     *            encoded char !
-     * @return The number of bytes to create a char, or -1 if the encoding is
-     *         wrong. TODO : Should stop after the third byte, as a char is only
-     *         2 bytes long.
-     */
-    public static int countBytesPerChar( byte[] bytes, int pos )
-    {
-        if ( bytes == null )
-        {
-            return -1;
-        }
-
-        if ( ( bytes[pos] & UTF8_MULTI_BYTES_MASK ) == 0 )
-        {
-            return 1;
-        }
-        else if ( ( bytes[pos] & UTF8_TWO_BYTES_MASK ) == UTF8_TWO_BYTES )
-        {
-            return 2;
-        }
-        else if ( ( bytes[pos] & UTF8_THREE_BYTES_MASK ) == UTF8_THREE_BYTES )
-        {
-            return 3;
-        }
-        else if ( ( bytes[pos] & UTF8_FOUR_BYTES_MASK ) == UTF8_FOUR_BYTES )
-        {
-            return 4;
-        }
-        else if ( ( bytes[pos] & UTF8_FIVE_BYTES_MASK ) == UTF8_FIVE_BYTES )
-        {
-            return 5;
-        }
-        else if ( ( bytes[pos] & UTF8_SIX_BYTES_MASK ) == UTF8_SIX_BYTES )
-        {
-            return 6;
-        }
-        else
-        {
-            return -1;
-        }
-    }
-
-
-    /**
-     * Return the number of bytes that hold an Unicode char.
-     * 
-     * @param car The character to be decoded
-     * @return The number of bytes to hold the char. TODO : Should stop after
-     *         the third byte, as a char is only 2 bytes long.
-     */
-    public static int countNbBytesPerChar( char car )
-    {
-        if ( ( car & CHAR_ONE_BYTE_MASK ) == 0 )
-        {
-            return 1;
-        }
-        else if ( ( car & CHAR_TWO_BYTES_MASK ) == 0 )
-        {
-            return 2;
-        }
-        else if ( ( car & CHAR_THREE_BYTES_MASK ) == 0 )
-        {
-            return 3;
-        }
-        else if ( ( car & CHAR_FOUR_BYTES_MASK ) == 0 )
-        {
-            return 4;
-        }
-        else if ( ( car & CHAR_FIVE_BYTES_MASK ) == 0 )
-        {
-            return 5;
-        }
-        else if ( ( car & CHAR_SIX_BYTES_MASK ) == 0 )
-        {
-            return 6;
-        }
-        else
-        {
-            return -1;
-        }
-    }
-
-
-    /**
-     * Count the number of bytes included in the given char[].
-     * 
-     * @param chars The char array to decode
-     * @return The number of bytes in the char array
-     */
-    public static int countBytes( char[] chars )
-    {
-        if ( chars == null )
-        {
-            return 0;
-        }
-
-        int nbBytes = 0;
-        int currentPos = 0;
-
-        while ( currentPos < chars.length )
-        {
-            int nbb = countNbBytesPerChar( chars[currentPos] );
-
-            // If the number of bytes necessary to encode a character is
-            // above 3, we will need two UTF-16 chars
-            currentPos += ( nbb < 4 ? 1 : 2 );
-            nbBytes += nbb;
-        }
-
-        return nbBytes;
-    }
-
-
-    /**
-     * Return the Unicode char which is coded in the bytes at the given
-     * position.
-     * 
-     * @param bytes The byte[] represntation of an Unicode string.
-     * @param pos The current position to start decoding the char
-     * @return The decoded char, or -1 if no char can be decoded TODO : Should
-     *         stop after the third byte, as a char is only 2 bytes long.
-     */
-    public static char bytesToChar( byte[] bytes, int pos )
-    {
-        if ( bytes == null )
-        {
-            return ( char ) -1;
-        }
 
-        if ( ( bytes[pos] & UTF8_MULTI_BYTES_MASK ) == 0 )
-        {
-            return ( char ) bytes[pos];
-        }
-        else
-        {
-            if ( ( bytes[pos] & UTF8_TWO_BYTES_MASK ) == UTF8_TWO_BYTES )
-            {
-                // Two bytes char
-                return ( char ) ( ( ( bytes[pos] & 0x1C ) << 6 ) + // 110x-xxyy
-                                                                    // 10zz-zzzz
-                                                                    // ->
-                                                                    // 0000-0xxx
-                                                                    // 0000-0000
-                    ( ( bytes[pos] & 0x03 ) << 6 ) + // 110x-xxyy 10zz-zzzz
-                                                        // -> 0000-0000
-                                                        // yy00-0000
-                ( bytes[pos + 1] & 0x3F ) // 110x-xxyy 10zz-zzzz -> 0000-0000
-                                            // 00zz-zzzz
-                ); // -> 0000-0xxx yyzz-zzzz (07FF)
-            }
-            else if ( ( bytes[pos] & UTF8_THREE_BYTES_MASK ) == UTF8_THREE_BYTES )
-            {
-                // Three bytes char
-                return ( char ) (
-                // 1110-tttt 10xx-xxyy 10zz-zzzz -> tttt-0000-0000-0000
-                ( ( bytes[pos] & 0x0F ) << 12 )
-                    // 1110-tttt 10xx-xxyy 10zz-zzzz -> 0000-xxxx-0000-0000
-                    + ( ( bytes[pos + 1] & 0x3C ) << 6 )
-                    // 1110-tttt 10xx-xxyy 10zz-zzzz -> 0000-0000-yy00-0000
-                    + ( ( bytes[pos + 1] & 0x03 ) << 6 )
-                // 1110-tttt 10xx-xxyy 10zz-zzzz -> 0000-0000-00zz-zzzz
-                + ( bytes[pos + 2] & 0x3F )
-                // -> tttt-xxxx yyzz-zzzz (FF FF)
-                );
-            }
-            else if ( ( bytes[pos] & UTF8_FOUR_BYTES_MASK ) == UTF8_FOUR_BYTES )
-            {
-                // Four bytes char
-                return ( char ) (
-                // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 000t-tt00
-                // 0000-0000 0000-0000
-                ( ( bytes[pos] & 0x07 ) << 18 )
-                    // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 0000-00uu
-                    // 0000-0000 0000-0000
-                    + ( ( bytes[pos + 1] & 0x30 ) << 16 )
-                    // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 0000-0000
-                    // vvvv-0000 0000-0000
-                    + ( ( bytes[pos + 1] & 0x0F ) << 12 )
-                    // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 0000-0000
-                    // 0000-xxxx 0000-0000
-                    + ( ( bytes[pos + 2] & 0x3C ) << 6 )
-                    // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 0000-0000
-                    // 0000-0000 yy00-0000
-                    + ( ( bytes[pos + 2] & 0x03 ) << 6 )
-                // 1111-0ttt 10uu-vvvv 10xx-xxyy 10zz-zzzz -> 0000-0000
-                // 0000-0000 00zz-zzzz
-                + ( bytes[pos + 3] & 0x3F )
-                // -> 000t-ttuu vvvv-xxxx yyzz-zzzz (1FFFFF)
-                );
-            }
-            else if ( ( bytes[pos] & UTF8_FIVE_BYTES_MASK ) == UTF8_FIVE_BYTES )
-            {
-                // Five bytes char
-                return ( char ) (
-                // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                // 0000-00tt 0000-0000 0000-0000 0000-0000
-                ( ( bytes[pos] & 0x03 ) << 24 )
-                    // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                    // 0000-0000 uuuu-uu00 0000-0000 0000-0000
-                    + ( ( bytes[pos + 1] & 0x3F ) << 18 )
-                    // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                    // 0000-0000 0000-00vv 0000-0000 0000-0000
-                    + ( ( bytes[pos + 2] & 0x30 ) << 12 )
-                    // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                    // 0000-0000 0000-0000 wwww-0000 0000-0000
-                    + ( ( bytes[pos + 2] & 0x0F ) << 12 )
-                    // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                    // 0000-0000 0000-0000 0000-xxxx 0000-0000
-                    + ( ( bytes[pos + 3] & 0x3C ) << 6 )
-                    // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                    // 0000-0000 0000-0000 0000-0000 yy00-0000
-                    + ( ( bytes[pos + 3] & 0x03 ) << 6 )
-                // 1111-10tt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz ->
-                // 0000-0000 0000-0000 0000-0000 00zz-zzzz
-                + ( bytes[pos + 4] & 0x3F )
-                // -> 0000-00tt uuuu-uuvv wwww-xxxx yyzz-zzzz (03 FF FF FF)
-                );
-            }
-            else if ( ( bytes[pos] & UTF8_FIVE_BYTES_MASK ) == UTF8_FIVE_BYTES )
-            {
-                // Six bytes char
-                return ( char ) (
-                // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz
-                // ->
-                // 0s00-0000 0000-0000 0000-0000 0000-0000
-                ( ( bytes[pos] & 0x01 ) << 30 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz
-                    // ->
-                    // 00tt-tttt 0000-0000 0000-0000 0000-0000
-                    + ( ( bytes[pos + 1] & 0x3F ) << 24 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy
-                    // 10zz-zzzz ->
-                    // 0000-0000 uuuu-uu00 0000-0000 0000-0000
-                    + ( ( bytes[pos + 2] & 0x3F ) << 18 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy
-                    // 10zz-zzzz ->
-                    // 0000-0000 0000-00vv 0000-0000 0000-0000
-                    + ( ( bytes[pos + 3] & 0x30 ) << 12 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy
-                    // 10zz-zzzz ->
-                    // 0000-0000 0000-0000 wwww-0000 0000-0000
-                    + ( ( bytes[pos + 3] & 0x0F ) << 12 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy
-                    // 10zz-zzzz ->
-                    // 0000-0000 0000-0000 0000-xxxx 0000-0000
-                    + ( ( bytes[pos + 4] & 0x3C ) << 6 )
-                    // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy
-                    // 10zz-zzzz ->
-                    // 0000-0000 0000-0000 0000-0000 yy00-0000
-                    + ( ( bytes[pos + 4] & 0x03 ) << 6 )
-                // 1111-110s 10tt-tttt 10uu-uuuu 10vv-wwww 10xx-xxyy 10zz-zzzz
-                // ->
-                // 0000-0000 0000-0000 0000-0000 00zz-zzzz
-                + ( bytes[pos + 5] & 0x3F )
-                // -> 0stt-tttt uuuu-uuvv wwww-xxxx yyzz-zzzz (7F FF FF FF)
-                );
-            }
-            else
-            {
-                return ( char ) -1;
-            }
-        }
-    }
+    // Empty checks
+    // -----------------------------------------------------------------------
 
 
-    /**
-     * Return the Unicode char which is coded in the bytes at the given
-     * position.
-     * 
-     * @param car The character to be transformed to an array of bytes
-     * 
-     * @return The byte array representing the char 
-     * 
-     * TODO : Should stop after the third byte, as a char is only 2 bytes long.
-     */
-    public static byte[] charToBytes( char car )
-    {
-        byte[] bytes = new byte[countNbBytesPerChar( car )];
+    // Case conversion
+    // -----------------------------------------------------------------------
 
-        if ( car <= 0x7F )
-        {
-            // Single byte char
-            bytes[0] = ( byte ) car;
-            return bytes;
-        }
-        else if ( car <= 0x7FF )
-        {
-            // two bytes char
-            bytes[0] = ( byte ) ( 0x00C0 + ( ( car & 0x07C0 ) >> 6 ) );
-            bytes[1] = ( byte ) ( 0x0080 + ( car & 0x3F ) );
-        }
-        else
-        {
-            // Three bytes char
-            bytes[0] = ( byte ) ( 0x00E0 + ( ( car & 0xF000 ) >> 12 ) );
-            bytes[1] = ( byte ) ( 0x0080 + ( ( car & 0x0FC0 ) >> 6 ) );
-            bytes[2] = ( byte ) ( 0x0080 + ( car & 0x3F ) );
-        }
 
-        return bytes;
-    }
+    // Equals
+    // -----------------------------------------------------------------------
 
 
     /**
-     * Count the number of chars included in the given byte[].
-     * 
-     * @param bytes The byte array to decode
-     * @return The number of char in the byte array
+     * Build an AttributeType froma byte array. An AttributeType contains
+     * only chars within [0-9][a-z][A-Z][-.].
+     *  
+     * @param bytes The bytes containing the AttributeType
+     * @return The AttributeType as a String
      */
-    public static int countChars( byte[] bytes )
+    public static String getType( byte[] bytes)
     {
         if ( bytes == null )
         {
-            return 0;
-        }
-
-        int nbChars = 0;
-        int currentPos = 0;
-
-        while ( currentPos < bytes.length )
-        {
-            currentPos += countBytesPerChar( bytes, currentPos );
-            nbChars++;
-        }
-
-        return nbChars;
-    }
-
-
-    /**
-     * Check if a text is present at the current position in a buffer.
-     * 
-     * @param bytes 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( byte[] bytes, int index, String text )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( bytes.length <= index ) || ( index < 0 )
-            || ( text == null ) )
-        {
-            return NOT_EQUAL;
-        }
-        else
-        {
-            try
-            {
-                byte[] data = text.getBytes( "UTF-8" );
-
-                return areEquals( bytes, index, data );
-            }
-            catch ( UnsupportedEncodingException uee )
-            {
-                // if this happens something is really strange
-                throw new RuntimeException( uee );
-            }
-        }
-    }
-
-
-    /**
-     * Check if a text is present at the current position in a buffer.
-     * 
-     * @param chars 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[] chars, int index, String text )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( chars.length <= index ) || ( index < 0 )
-            || ( text == null ) )
-        {
-            return NOT_EQUAL;
-        }
-        else
-        {
-            char[] data = text.toCharArray();
-
-            return areEquals( chars, index, data );
-        }
-    }
-
-
-    /**
-     * Check if a text is present at the current position in a buffer.
-     * 
-     * @param chars The buffer which contains the data
-     * @param index Current position in the buffer
-     * @param chars2 The text we want to check
-     * @return <code>true</code> if the buffer contains the text.
-     */
-    public static int areEquals( char[] chars, int index, char[] chars2 )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( chars.length <= index ) || ( index < 0 )
-            || ( chars2 == null ) || ( chars2.length == 0 )
-            || ( chars2.length > ( chars.length + index ) ) )
-        {
-            return NOT_EQUAL;
-        }
-        else
-        {
-            for ( int i = 0; i < chars2.length; i++ )
-            {
-                if ( chars[index++] != chars2[i] )
-                {
-                    return NOT_EQUAL;
-                }
-            }
-
-            return index;
-        }
-    }
-
-    /**
-     * Check if a text is present at the current position in a buffer.
-     * 
-     * @param bytes The buffer which contains the data
-     * @param index Current position in the buffer
-     * @param bytes2 The text we want to check
-     * @return <code>true</code> if the buffer contains the text.
-     */
-    public static int areEquals( byte[] bytes, int index, byte[] bytes2 )
-    {
-
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( bytes.length <= index ) || ( index < 0 )
-            || ( bytes2 == null ) || ( bytes2.length == 0 )
-            || ( bytes2.length > ( bytes.length + index ) ) )
-        {
-            return NOT_EQUAL;
-        }
-        else
-        {
-            for ( int i = 0; i < bytes2.length; i++ )
-            {
-                if ( bytes[index++] != bytes2[i] )
-                {
-                    return NOT_EQUAL;
-                }
-            }
-
-            return index;
-        }
-    }
-
-
-    /* *
-     * Test if the current character is equal to a specific character.
-     * 
-     * @param chars The buffer which contains the data
-     * @param index
-     *            Current position in the buffer
-     * @param car The character we want to compare with the current buffer position
-     * @return <code>true</code> if the current character equals the given character.
-     */
-    public static boolean isCharASCII( char[] chars, int index, char car )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) )
-        {
-            return false;
+            return null;
         }
-        else
+        
+        char[] chars = new char[bytes.length];
+        int pos = 0;
+        
+        for ( byte b:bytes )
         {
-            return ( ( chars[index] == car ) ? true : false );
-        }
-    }
-
-    /**
-     * Test if the current character is equal to a specific character.
-     * 
-     * @param string The String which contains the data
-     * @param index Current position in the string
-     * @param car The character we want to compare with the current string
-     *            position
-     * @return <code>true</code> if the current character equals the given
-     *         character.
-     */
-    public static boolean isCharASCII( String string, int index, char car )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return string.charAt( index ) == car;
-        }
-    }
-
-
-    /**
-     * Test if the current character is equal to a specific character.
-     * 
-     * @param string The String which contains the data
-     * @param index Current position in the string
-     * @param car The character we want to compare with the current string
-     *            position
-     * @return <code>true</code> if the current character equals the given
-     *         character.
-     */
-    public static boolean isICharASCII( String string, int index, char car )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( string.charAt( index ) | 0x20 ) & car ) == car;
-        }
-    }
-
-
-    /**
-     * Test if the current character is equal to a specific character.
-     * 
-     * @param bytes The String which contains the data
-     * @param index Current position in the string
-     * @param car The character we want to compare with the current string
-     *            position
-     * @return <code>true</code> if the current character equals the given
-     *         character.
-     */
-    public static boolean isICharASCII( byte[] bytes, int index, char car )
-    {
-        if ( bytes == null )
-        {
-            return false;
-        }
-        
-        int length = bytes.length;
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( bytes[ index ] | 0x20 ) & car ) == car;
-        }
-    }
-
-
-    /**
-     * Test if the current character is a bit, ie 0 or 1.
-     * 
-     * @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 bit (0 or 1)
-     */
-    public static boolean isBit( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c =  string.charAt(  index );
-            return ( ( c == '0' ) || ( c == '1' ) );
-        }
-    }
-
-
-    /**
-     * Get the character at a given position in a string, checking fo limits
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     * @return The character ar the given position, or '\0' if something went wrong 
-     */
-    public static char charAt( String string, int index )
-    {
-        if ( string == null )
-        {
-            return '\0';
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return '\0';
-        }
-        else
-        {
-            return string.charAt( index ) ;
-        }
-    }
-
-    
-    /**
-     * Translate two chars to an hex value. The chars must be 
-     * in [a-fA-F0-9]
-     *
-     * @param high The high value 
-     * @param low The low value
-     * @return A byte representation of the two chars
-     */
-    public static byte getHexValue( char high, char low )
-    {
-        if ( ( high > 127 ) || ( low > 127 ) || ( high < 0 ) | ( low < 0 ) )
-        {
-            return -1;
-        }
-        
-        return (byte)( ( HEX_VALUE[high] << 4 ) | HEX_VALUE[low] );
-    }
-
-
-    /**
-     * Translate two bytes to an hex value. The bytes must be 
-     * in [0-9a-fA-F]
-     *
-     * @param high The high value 
-     * @param low The low value
-     * @return A byte representation of the two bytes
-     */
-    public static byte getHexValue( byte high, byte low )
-    {
-        if ( ( high > 127 ) || ( low > 127 ) || ( high < 0 ) | ( low < 0 ) )
-        {
-            return -1;
-        }
-        
-        return (byte)( ( HEX_VALUE[high] << 4 ) | HEX_VALUE[low] );
-    }
-
-    
-    /**
-     * Return an hex value from a sinle char
-     * The char must be in [0-9a-fA-F]
-     *
-     * @param c The char we want to convert
-     * @return A byte between 0 and 15
-     */
-    public static byte getHexValue( char c )
-    {
-        if ( ( c > 127 ) || ( c < 0 ) )
-        {
-            return -1;
-        }
-        
-        return HEX_VALUE[c];
-    }
-
-
-    /**
-     * Check if the current byte is an Hex Char 
-     * &lt;hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
-     * 
-     * @param b The byte we want to check
-     * @return <code>true</code> if the current byte is a Hex byte
-     */
-    public static boolean isHex( byte b )
-    {
-        return ( ( b | 0x7F ) == 0x7F ) || HEX[b];
-    }
-
-
-    /**
-     * Check if the current character is an Hex Char &lt;hex> ::= [0x30-0x39] |
-     * [0x41-0x46] | [0x61-0x66]
-     * 
-     * @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 Hex Char
-     */
-    public static boolean isHex( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F ) || ( HEX[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is an Hex Char &lt;hex> ::= [0x30-0x39] |
-     * [0x41-0x46] | [0x61-0x66]
-     * 
-     * @param chars 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[] chars, int index )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = chars[index];
-
-            if ( ( c > 127 ) || ( HEX[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    /**
-     * Check if the current character is an Hex Char &lt;hex> ::= [0x30-0x39] |
-     * [0x41-0x46] | [0x61-0x66]
-     * 
-     * @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 Hex Char
-     */
-    public static boolean isHex( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( HEX[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-    
-
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @param bytes The buffer which contains the data
-     * @return <code>true</code> if the current character is a Digit
-     */
-    public static boolean isDigit( byte[] bytes )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( ( ( bytes[0] | 0x7F ) != 0x7F ) || !DIGIT[bytes[0]] ) ? false : true );
-        }
-    }
-
-    
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @param car the character to test
-     *            
-     * @return <code>true</code> if the character is a Digit
-     */
-    public static boolean isDigit( char car )
-    {
-        return ( car >= '0' ) && ( car <= '9' );
-    }
-
-    
-    /**
-     * Test if the current byte is an Alpha character : 
-     * &lt;alpha> ::= [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param c The byte to test
-     * 
-     * @return <code>true</code> if the byte is an Alpha
-     *         character
-     */
-    public static boolean isAlpha( byte c )
-    {
-        return ( ( c > 0 ) && ( c <= 127 ) && ALPHA[c] );
-    }
-
-    
-    /**
-     * Test if the current character is an Alpha character : 
-     * &lt;alpha> ::= [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param c The char to test
-     * 
-     * @return <code>true</code> if the character is an Alpha
-     *         character
-     */
-    public static boolean isAlpha( char c )
-    {
-        return ( ( c > 0 ) && ( c <= 127 ) && ALPHA[c] );
-    }
-
-
-    /**
-     * Test if the current character is an Alpha character : &lt;alpha> ::=
-     * [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param bytes 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 isAlphaASCII( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F ) || ( ALPHA[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Test if the current character is an Alpha character : &lt;alpha> ::=
-     * [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param chars 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 isAlphaASCII( char[] chars, int index )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = chars[index];
-
-            if ( ( c > 127 ) || ( ALPHA[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    
-    /**
-     * Test if the current character is an Alpha character : &lt;alpha> ::=
-     * [0x41-0x5A] | [0x61-0x7A]
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     * @return <code>true</code> if the current character is an Alpha
-     *         character
-     */
-    public static boolean isAlphaASCII( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-        
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( ALPHA[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    
-    /**
-     * Test if the current character is a lowercased Alpha character : <br/>
-     * &lt;alpha> ::= [0x61-0x7A]
-     * 
-     * @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 lower Alpha
-     *         character
-     */
-    public static boolean isAlphaLowercaseASCII( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( ALPHA_LOWER_CASE[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    
-    /**
-     * Test if the current character is a uppercased Alpha character : <br/>
-     * &lt;alpha> ::= [0x61-0x7A]
-     * 
-     * @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 lower Alpha
-     *         character
-     */
-    public static boolean isAlphaUppercaseASCII( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( ALPHA_UPPER_CASE[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @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 Digit
-     */
-    public static boolean isDigit( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( ( ( bytes[index] | 0x7F ) !=  0x7F ) || !DIGIT[bytes[index]] ) ? false : true );
-        }
-    }
-
-
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @param chars The buffer which contains the data
-     * @param index Current position in the buffer
-     * @return <code>true</code> if the current character is a Digit
-     */
-    public static boolean isDigit( char[] chars, int index )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( ( chars[index] > 127 ) || !DIGIT[chars[index]] ) ? false : true );
-        }
-    }
-
-    
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @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 Digit
-     */
-    public static boolean isDigit( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt(  index  );
-            return ( ( ( c > 127 ) || !DIGIT[c] ) ? false : true );
-        }
-    }
-
-    
-    /**
-     * Test if the current character is a digit &lt;digit> ::= '0' | '1' | '2' |
-     * '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
-     * @param chars The buffer which contains the data
-     * @return <code>true</code> if the current character is a Digit
-     */
-    public static boolean isDigit( char[] chars )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) )
-        {
-            return false;
-        }
-        else
-        {
-            return ( ( ( chars[0] > 127 ) || !DIGIT[chars[0]] ) ? false : true );
-        }
-    }
-
-    
-    /**
-     * Check if the current character is an 7 bits ASCII CHAR (between 0 and
-     * 127). 
-     * &lt;char> ::= &lt;alpha> | &lt;digit>
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     * @return The position of the next character, if the current one is a CHAR.
-     */
-    public static boolean isAlphaDigit( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( ALPHA_DIGIT[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is an 7 bits ASCII CHAR (between 0 and
-     * 127). &lt;char> ::= &lt;alpha> | &lt;digit> | '-'
-     * 
-     * @param bytes 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 boolean isAlphaDigitMinus( byte[] bytes, int index )
-    {
-        if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            byte c = bytes[index];
-
-            if ( ( ( c | 0x7F ) != 0x7F ) || ( CHAR[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-
-    /**
-     * Check if the current character is an 7 bits ASCII CHAR (between 0 and
-     * 127). &lt;char> ::= &lt;alpha> | &lt;digit> | '-'
-     * 
-     * @param chars 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 boolean isAlphaDigitMinus( char[] chars, int index )
-    {
-        if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = chars[index];
-
-            if ( ( c > 127 ) || ( CHAR[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    
-    /**
-     * Check if the current character is an 7 bits ASCII CHAR (between 0 and
-     * 127). &lt;char> ::= &lt;alpha> | &lt;digit> | '-'
-     * 
-     * @param string The string which contains the data
-     * @param index Current position in the string
-     * @return The position of the next character, if the current one is a CHAR.
-     */
-    public static boolean isAlphaDigitMinus( String string, int index )
-    {
-        if ( string == null )
-        {
-            return false;
-        }
-
-        int length = string.length();
-        
-        if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
-        {
-            return false;
-        }
-        else
-        {
-            char c = string.charAt( index );
-
-            if ( ( c > 127 ) || ( CHAR[c] == false ) )
-            {
-                return false;
-            }
-            else
-            {
-                return true;
-            }
-        }
-    }
-
-    
-    // Empty checks
-    // -----------------------------------------------------------------------
-    /**
-     * <p>
-     * Checks if a String is empty ("") or null.
-     * </p>
-     * 
-     * <pre>
-     *  StringUtils.isEmpty(null)      = true
-     *  StringUtils.isEmpty(&quot;&quot;)        = true
-     *  StringUtils.isEmpty(&quot; &quot;)       = false
-     *  StringUtils.isEmpty(&quot;bob&quot;)     = false
-     *  StringUtils.isEmpty(&quot;  bob  &quot;) = false
-     * </pre>
-     * 
-     * <p>
-     * NOTE: This method changed in Lang version 2.0. It no longer trims the
-     * String. That functionality is available in isBlank().
-     * </p>
-     * 
-     * @param str the String to check, may be null
-     * @return <code>true</code> if the String is empty or null
-     */
-    public static boolean isEmpty( String str )
-    {
-        return str == null || str.length() == 0;
-    }
-
-
-    /**
-     * Checks if a bytes array is empty or null.
-     * 
-     * @param bytes The bytes array to check, may be null
-     * @return <code>true</code> if the bytes array is empty or null
-     */
-    public static boolean isEmpty( byte[] bytes )
-    {
-        return bytes == null || bytes.length == 0;
-    }
-
-
-    /**
-     * <p>
-     * Checks if a String is not empty ("") and not null.
-     * </p>
-     * 
-     * <pre>
-     *  StringUtils.isNotEmpty(null)      = false
-     *  StringUtils.isNotEmpty(&quot;&quot;)        = false
-     *  StringUtils.isNotEmpty(&quot; &quot;)       = true
-     *  StringUtils.isNotEmpty(&quot;bob&quot;)     = true
-     *  StringUtils.isNotEmpty(&quot;  bob  &quot;) = true
-     * </pre>
-     * 
-     * @param str the String to check, may be null
-     * @return <code>true</code> if the String is not empty and not null
-     */
-    public static boolean isNotEmpty( String str )
-    {
-        return str != null && str.length() > 0;
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from both start and ends of this String,
-     * handling <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start and end characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trim(null)          = null
-     *  StringUtils.trim(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trim(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trim(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trim(&quot;    abc    &quot;) = &quot;abc&quot;
-     * </pre>
-     * 
-     * @param str the String to be trimmed, may be null
-     * @return the trimmed string, <code>null</code> if null String input
-     */
-    public static String trim( String str )
-    {
-        return ( isEmpty( str ) ? "" : str.trim() );
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from both start and ends of this bytes
-     * array, handling <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start and end characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trim(null)          = null
-     *  StringUtils.trim(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trim(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trim(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trim(&quot;    abc    &quot;) = &quot;abc&quot;
-     * </pre>
-     * 
-     * @param bytes the byte array to be trimmed, may be null
-     * 
-     * @return the trimmed byte array
-     */
-    public static byte[] trim( byte[] bytes )
-    {
-        if ( isEmpty( bytes ) )
-        {
-            return EMPTY_BYTES;
-        }
-
-        int start = trimLeft( bytes, 0 );
-        int end = trimRight( bytes, bytes.length - 1 );
-
-        int length = end - start + 1;
-
-        if ( length != 0 )
-        {
-            byte[] newBytes = new byte[end - start + 1];
-
-            System.arraycopy( bytes, start, newBytes, 0, length );
-
-            return newBytes;
-        }
-        else
-        {
-            return EMPTY_BYTES;
-        }
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from start of this String, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimLeft(null)          = null
-     *  StringUtils.trimLeft(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimLeft(&quot;    abc    &quot;) = &quot;abc    &quot;
-     * </pre>
-     * 
-     * @param str the String to be trimmed, may be null
-     * @return the trimmed string, <code>null</code> if null String input
-     */
-    public static String trimLeft( String str )
-    {
-        if ( isEmpty( str ) )
-        {
-            return "";
-        }
-
-        int start = 0;
-        int end = str.length();
-        
-        while ( ( start < end ) && ( str.charAt( start ) == ' ' ) )
-        {
-            start++;
-        }
-
-        return ( start == 0 ? str : str.substring( start ) );
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from start of this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimLeft(null)          = null
-     *  StringUtils.trimLeft(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimLeft(&quot;    abc    &quot;) = &quot;abc    &quot;
-     * </pre>
-     * 
-     * @param chars the chars array to be trimmed, may be null
-     * @return the position of the first char which is not a space, or the last
-     *         position of the array.
-     */
-    public static int trimLeft( char[] chars, int pos )
-    {
-        if ( chars == null )
-        {
-            return pos;
-        }
-
-        while ( ( pos < chars.length ) && ( chars[pos] == ' ' ) )
-        {
-            pos++;
-        }
-
-        return pos;
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from a position in this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimLeft(null)          = null
-     *  StringUtils.trimLeft(&quot;&quot;,...)            = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;     &quot;,...)       = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;abc&quot;,...)         = &quot;abc&quot;
-     *  StringUtils.trimLeft(&quot;    abc    &quot;,...) = &quot;abc    &quot;
-     * </pre>
-     * 
-     * @param string the string to be trimmed, may be null
-     * @param pos The starting position
-     */
-    public static void trimLeft( String string, Position pos )
-    {
-        if ( string == null )
-        {
-            return;
-        }
-
-        int length = string.length();
-        
-        while ( ( pos.start < length ) && ( string.charAt( pos.start ) == ' ' ) )
-        {
-            pos.start++;
-        }
-        
-        pos.end = pos.start;
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from a position in this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimLeft(null)          = null
-     *  StringUtils.trimLeft(&quot;&quot;,...)            = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;     &quot;,...)       = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;abc&quot;,...)         = &quot;abc&quot;
-     *  StringUtils.trimLeft(&quot;    abc    &quot;,...) = &quot;abc    &quot;
-     * </pre>
-     * 
-     * @param bytes the byte array to be trimmed, may be null
-     * @param pos The starting position
-     */
-    public static void trimLeft( byte[] bytes, Position pos )
-    {
-        if ( bytes == null )
-        {
-            return;
-        }
-
-        int length = bytes.length;
-        
-        while ( ( pos.start < length ) && ( bytes[ pos.start ] == ' ' ) )
-        {
-            pos.start++;
-        }
-        
-        pos.end = pos.start;
-    }
-
-    
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from start of this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimLeft(null)          = null
-     *  StringUtils.trimLeft(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimLeft(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimLeft(&quot;    abc    &quot;) = &quot;abc    &quot;
-     * </pre>
-     * 
-     * @param bytes the byte array to be trimmed, may be null
-     * @return the position of the first byte which is not a space, or the last
-     *         position of the array.
-     */
-    public static int trimLeft( byte[] bytes, int pos )
-    {
-        if ( bytes == null )
-        {
-            return pos;
-        }
-
-        while ( ( pos < bytes.length ) && ( bytes[pos] == ' ' ) )
-        {
-            pos++;
-        }
-
-        return pos;
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this String, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param str the String to be trimmed, may be null
-     * @return the trimmed string, <code>null</code> if null String input
-     */
-    public static String trimRight( String str )
-    {
-        if ( isEmpty( str ) )
-        {
-            return "";
-        }
-
-        int length = str.length();
-        int end = length;
-        
-        while ( ( end > 0 ) && ( str.charAt( end - 1 ) == ' ' ) )
-        {
-            if ( ( end > 1 ) && ( str.charAt(  end - 2 ) == '\\' ) )
-            {
-                break;
-            }
-            
-            end--;
-        }
-
-        return ( end == length ? str : str.substring( 0, end ) );
-    }
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this String, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param str the String to be trimmed, may be null
-     * @param escapedSpace The last escaped space, if any
-     * @return the trimmed string, <code>null</code> if null String input
-     */
-    public static String trimRight( String str, int escapedSpace )
-    {
-        if ( isEmpty( str ) )
-        {
-            return "";
-        }
-
-        int length = str.length();
-        int end = length;
-        
-        while ( ( end > 0 ) && ( str.charAt( end - 1 ) == ' ' ) && ( end > escapedSpace ) )
-        {
-            if ( ( end > 1 ) && ( str.charAt(  end - 2 ) == '\\' ) )
-            {
-                break;
-            }
-            
-            end--;
-        }
-
-        return ( end == length ? str : str.substring( 0, end ) );
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param chars the chars array to be trimmed, may be null
-     * @return the position of the first char which is not a space, or the last
-     *         position of the array.
-     */
-    public static int trimRight( char[] chars, int pos )
-    {
-        if ( chars == null )
-        {
-            return pos;
-        }
-
-        while ( ( pos >= 0 ) && ( chars[pos - 1] == ' ' ) )
-        {
-            pos--;
-        }
-
-        return pos;
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this string, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param string the string to be trimmed, may be null
-     * @return the position of the first char which is not a space, or the last
-     *         position of the string.
-     */
-    public static String trimRight( String string, Position pos )
-    {
-        if ( string == null )
-        {
-            return "";
-        }
-
-        while ( ( pos.end >= 0 ) && ( string.charAt( pos.end - 1 ) == ' ' ) )
-        {
-            if ( ( pos.end > 1 ) && ( string.charAt(  pos.end - 2 ) == '\\' ) )
-            {
-                break;
-            }
-            
-            pos.end--;
-        }
-
-        return ( pos.end == string.length() ? string : string.substring( 0, pos.end ) );
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this string, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param bytes the byte array to be trimmed, may be null
-     * @return the position of the first char which is not a space, or the last
-     *         position of the byte array.
-     */
-    public static String trimRight( byte[] bytes, Position pos )
-    {
-        if ( bytes == null )
-        {
-            return "";
-        }
-
-        while ( ( pos.end >= 0 ) && ( bytes[pos.end - 1] == ' ' ) )
-        {
-            if ( ( pos.end > 1 ) && ( bytes[pos.end - 2] == '\\' ) )
-            {
-                break;
-            }
-            
-            pos.end--;
-        }
-
-        if ( pos.end == bytes.length )
-        {
-            return StringTools.utf8ToString( bytes );
-        }
-        else
-        {
-            return StringTools.utf8ToString( bytes, pos.end );
-        }
-    }
-
-
-    /**
-     * <p>
-     * Removes spaces (char &lt;= 32) from end of this array, handling
-     * <code>null</code> by returning <code>null</code>.
-     * </p>
-     * Trim removes start characters &lt;= 32.
-     * 
-     * <pre>
-     *  StringUtils.trimRight(null)          = null
-     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
-     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
-     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
-     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
-     * </pre>
-     * 
-     * @param bytes the byte array to be trimmed, may be null
-     * @return the position of the first char which is not a space, or the last
-     *         position of the array.
-     */
-    public static int trimRight( byte[] bytes, int pos )
-    {
-        if ( bytes == null )
-        {
-            return pos;
-        }
-
-        while ( ( pos >= 0 ) && ( bytes[pos] == ' ' ) )
-        {
-            pos--;
-        }
-
-        return pos;
-    }
-
-
-    // Case conversion
-    // -----------------------------------------------------------------------
-    /**
-     * <p>
-     * Converts a String to upper case as per {@link String#toUpperCase()}.
-     * </p>
-     * <p>
-     * A <code>null</code> input String returns <code>null</code>.
-     * </p>
-     * 
-     * <pre>
-     *  StringUtils.upperCase(null)  = null
-     *  StringUtils.upperCase(&quot;&quot;)    = &quot;&quot;
-     *  StringUtils.upperCase(&quot;aBc&quot;) = &quot;ABC&quot;
-     * </pre>
-     * 
-     * @param str the String to upper case, may be null
-     * @return the upper cased String, <code>null</code> if null String input
-     */
-    public static String upperCase( String str )
-    {
-        if ( str == null )
-        {
-            return null;
-        }
-        
-        return str.toUpperCase();
-    }
-
-
-    /**
-     * <p>
-     * Converts a String to lower case as per {@link String#toLowerCase()}.
-     * </p>
-     * <p>
-     * A <code>null</code> input String returns <code>null</code>.
-     * </p>
-     * 
-     * <pre>
-     *  StringUtils.lowerCase(null)  = null
-     *  StringUtils.lowerCase(&quot;&quot;)    = &quot;&quot;
-     *  StringUtils.lowerCase(&quot;aBc&quot;) = &quot;abc&quot;
-     * </pre>
-     * 
-     * @param str the String to lower case, may be null
-     * @return the lower cased String, <code>null</code> if null String input
-     */
-    public static String lowerCase( String str )
-    {
-        if ( str == null )
-        {
-            return null;
-        }
-        
-        return str.toLowerCase();
-    }
-
-    
-    /**
-     * Rewrote the toLowercase method to improve performances.
-     * In Ldap, attributesType are supposed to use ASCII chars :
-     * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only. We will take
-     * care of any other chars either.
-     * 
-     * @param str The String to lowercase
-     * @return The lowercase string
-     */
-    public static String lowerCaseAscii( String str )
-    {
-        if ( str == null )
-        {
-            return null;
-        }
-     
-        char[] chars = str.toCharArray();
-        int pos = 0;
-        
-        for ( char c:chars )
-        {
-            chars[pos++] = TO_LOWER_CASE[c];
-        }
-        
-        return new String( chars );
-    }
-
-    
-    // Equals
-    // -----------------------------------------------------------------------
-    /**
-     * <p>
-     * Compares two Strings, returning <code>true</code> if they are equal.
-     * </p>
-     * <p>
-     * <code>null</code>s are handled without exceptions. Two
-     * <code>null</code> references are considered to be equal. The comparison
-     * is case sensitive.
-     * </p>
-     * 
-     * <pre>
-     *  StringUtils.equals(null, null)   = true
-     *  StringUtils.equals(null, &quot;abc&quot;)  = false
-     *  StringUtils.equals(&quot;abc&quot;, null)  = false
-     *  StringUtils.equals(&quot;abc&quot;, &quot;abc&quot;) = true
-     *  StringUtils.equals(&quot;abc&quot;, &quot;ABC&quot;) = false
-     * </pre>
-     * 
-     * @see java.lang.String#equals(Object)
-     * @param str1 the first String, may be null
-     * @param str2 the second String, may be null
-     * @return <code>true</code> if the Strings are equal, case sensitive, or
-     *         both <code>null</code>
-     */
-    public static boolean equals( String str1, String str2 )
-    {
-        return str1 == null ? str2 == null : str1.equals( str2 );
-    }
-
-
-    /**
-     * Return an UTF-8 encoded String
-     * 
-     * @param bytes The byte array to be transformed to a String
-     * @return A String.
-     */
-    public static String utf8ToString( byte[] bytes )
-    {
-        if ( bytes == null )
-        {
-            return "";
-        }
-
-        try
-        {
-            return new String( bytes, "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            // if this happens something is really strange
-            throw new RuntimeException( uee );
-        }
-    }
-
-
-    /**
-     * Return an UTF-8 encoded String
-     * 
-     * @param bytes The byte array to be transformed to a String
-     * @param length The length of the byte array to be converted
-     * @return A String.
-     */
-    public static String utf8ToString( byte[] bytes, int length )
-    {
-        if ( bytes == null )
-        {
-            return "";
-        }
-
-        try
-        {
-            return new String( bytes, 0, length, "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            // if this happens something is really strange
-            throw new RuntimeException( uee );
-        }
-    }
-
-
-    /**
-     * Return an UTF-8 encoded String
-     * 
-     * @param bytes  The byte array to be transformed to a String
-     * @param start the starting position in the byte array  
-     * @param length The length of the byte array to be converted
-     * @return A String.
-     */
-    public static String utf8ToString( byte[] bytes, int start, int length )
-    {
-        if ( bytes == null )
-        {
-            return "";
-        }
-
-        try
-        {
-            return new String( bytes, start, length, "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            // if this happens something is really strange
-            throw new RuntimeException( uee );
-        }
-    }
-
-
-    /**
-     * Return UTF-8 encoded byte[] representation of a String
-     * 
-     * @param string The string to be transformed to a byte array
-     * @return The transformed byte array
-     */
-    public static byte[] getBytesUtf8( String string )
-    {
-        if ( string == null )
-        {
-            return new byte[0];
-        }
-
-        try
-        {
-            return string.getBytes( "UTF-8" );
-        }
-        catch ( UnsupportedEncodingException uee )
-        {
-            // if this happens something is really strange
-            throw new RuntimeException( uee );
-        }
-    }
-
-
-    /**
-     * Utility method that return a String representation of a list
-     * 
-     * @param list The list to transform to a string
-     * @return A csv string
-     */
-    public static String listToString( List<?> list )
-    {
-        if ( ( list == null ) || ( list.size() == 0 ) )
-        {
-            return "";
-        }
-
-        StringBuilder sb = new StringBuilder();
-        boolean isFirst = true;
-
-        for ( Object elem : list )
-        {
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                sb.append( ", " );
-            }
-
-            sb.append( elem );
-        }
-
-        return sb.toString();
-    }
-
-
-
-
-    /**
-     * Utility method that return a String representation of a set
-     * 
-     * @param set The set to transform to a string
-     * @return A csv string
-     */
-    public static String setToString( Set<?> set )
-    {
-        if ( ( set == null ) || ( set.size() == 0 ) )
-        {
-            return "";
-        }
-
-        StringBuilder sb = new StringBuilder();
-        boolean isFirst = true;
-
-        for ( Object elem : set )
-        {
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                sb.append( ", " );
-            }
-
-            sb.append( elem );
-        }
-
-        return sb.toString();
-    }
-
-
-    /**
-     * Utility method that return a String representation of a list
-     * 
-     * @param list The list to transform to a string
-     * @param tabs The tabs to add in ffront of the elements
-     * @return A csv string
-     */
-    public static String listToString( List<?> list, String tabs )
-    {
-        if ( ( list == null ) || ( list.size() == 0 ) )
-        {
-            return "";
-        }
-
-        StringBuffer sb = new StringBuffer();
-
-        for ( Object elem : list )
-        {
-            sb.append( tabs );
-            sb.append( elem );
-            sb.append( '\n' );
-        }
-
-        return sb.toString();
-    }
-
-
-    /**
-     * Utility method that return a String representation of a map. The elements
-     * will be represented as "key = value"
-     * 
-     * @param map The map to transform to a string
-     * @return A csv string
-     */
-    public static String mapToString( Map<?,?> map )
-    {
-        if ( ( map == null ) || ( map.size() == 0 ) )
-        {
-            return "";
-        }
-
-        StringBuffer sb = new StringBuffer();
-        boolean isFirst = true;
-
-        for ( Map.Entry<?, ?> entry:map.entrySet() )
-        {
-            if ( isFirst )
-            {
-                isFirst = false;
-            }
-            else
-            {
-                sb.append( ", " );
-            }
-
-            sb.append( entry.getKey() );
-            sb.append( " = '" ).append( entry.getValue() ).append( "'" );
-        }
-
-        return sb.toString();
-    }
-
-
-    /**
-     * Utility method that return a String representation of a map. The elements
-     * will be represented as "key = value"
-     * 
-     * @param map The map to transform to a string
-     * @param tabs The tabs to add in ffront of the elements
-     * @return A csv string
-     */
-    public static String mapToString( Map<?,?> map, String tabs )
-    {
-        if ( ( map == null ) || ( map.size() == 0 ) )
-        {
-            return "";
-        }
-
-        StringBuffer sb = new StringBuffer();
-
-        for ( Map.Entry<?, ?> entry:map.entrySet() )
-        {
-            sb.append( tabs );
-            sb.append( entry.getKey() );
-
-            sb.append( " = '" ).append( entry.getValue().toString() ).append( "'\n" );
-        }
-
-        return sb.toString();
-    }
-
-    
-    /**
-     * Get the default charset
-     * 
-     * @return The default charset
-     */
-    public static String getDefaultCharsetName()
-    {
-        if ( null == defaultCharset ) 
-        {
-            try 
-            {
-                // Try with jdk 1.5 method, if we are using a 1.5 jdk :)
-                Method method = Charset.class.getMethod( "defaultCharset", new Class[0] );
-                defaultCharset = ((Charset) method.invoke( null, new Object[0]) ).name();
-            } 
-            catch (NoSuchMethodException e) 
-            {
-                // fall back to old method
-                defaultCharset = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
-            }
-            catch (InvocationTargetException e) 
-            {
-                // fall back to old method
-                defaultCharset = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
-            }
-            catch (IllegalAccessException e) 
-            {
-                // fall back to old method
-                defaultCharset = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
-            }
-        }
-
-        return defaultCharset;
-    }
-    
-    
-    /**
-     * Decodes values of attributes in the DN encoded in hex into a UTF-8 
-     * String.  RFC2253 allows a DN's attribute to be encoded in hex.
-     * The encoded value starts with a # then is followed by an even 
-     * number of hex characters.  
-     * 
-     * @param str the string to decode
-     * @return the decoded string
-     */
-    public static String decodeHexString( String str ) throws InvalidNameException
-    {
-        if ( str == null || str.length() == 0 )
-        {
-            throw new InvalidNameException( I18n.err( I18n.ERR_04431 ) );
-        }
-        
-        char[] chars = str.toCharArray();
-        
-        if ( chars[0] != '#' )
-        {
-            throw new InvalidNameException( I18n.err( I18n.ERR_04432, str ) );
-        }
-        
-        // the bytes representing the encoded string of hex
-        // this should be ( length - 1 )/2 in size

[... 297 lines stripped ...]


Mime
View raw message