static public String nameDecode ( String value ) throws BadLdapGrammarException { if ( value == null ) return null ; // make buffer same size StringBuilder decoded = new StringBuilder ( value . length ( ) ) ; int i = 0 ; while ( i < value . length ( ) ) { char currentChar = value . charAt ( i ) ; if ( currentChar == ' ' ) { if ( value . length ( ) <= i + 1 ) { // Ending with a single backslash is not allowed throw new BadLdapGrammarException ( "Unexpected end of value " + "unterminated '\\'" ) ; } else { char nextChar = value . charAt ( i + 1 ) ; if ( nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' || nextChar == ' ' ) { // Normal backslash escape decoded . append ( nextChar ) ; i += 2 ; } else { if ( value . length ( ) <= i + 2 ) { throw new BadLdapGrammarException ( "Unexpected end of value " + "expected special or hex, found '" + nextChar + "'" ) ; } else { // This should be a hex value String hexString = "" + nextChar + value . charAt ( i + 2 ) ; decoded . append ( ( char ) Integer . parseInt ( hexString , HEX ) ) ; i += 3 ; } } } } else { // This character wasn't escaped - just append it decoded . append ( currentChar ) ; i ++ ; } } return decoded . toString ( ) ; }
Decodes a value . Converts escaped chars to ordinary chars .