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