private String makeEscaped(String name){
  int length=name.length();
  if (length == 0) {
    return name;
  }
  StringBuilder buf=new StringBuilder(length * 2);
  for (int index=0; index < length; index++) {
    char ch=name.charAt(index);
switch (ch) {
case ' ':
      if (index == 0 || index == (length - 1)) {
        buf.append('\\');
      }
    buf.append(' ');
  break;
case '"':
case '\\':
hasQE=true;
buf.append('\\');
buf.append(ch);
break;
case ',':
case '+':
case '<':
case '>':
case ';':
case '#':
case '=':
buf.append('\\');
buf.append(ch);
break;
default :
buf.append(ch);
break;
}
}
return buf.toString();
}

private String makeEscaped ( String name ) { int length = name . length ( ) ; if ( length == 0 ) { return name ; } StringBuilder buf = new StringBuilder ( length * 2 ) ; for ( int index = 0 ; index < length ; index ++ ) { char ch = name . charAt ( index ) ; switch ( ch ) { case ' ' : if ( index == 0 || index == ( length - 1 ) ) { buf . append ( '\\' ) ; } buf . append ( ' ' ) ; break ; case '"' : case '\\' : hasQE = true ; buf . append ( '\\' ) ; buf . append ( ch ) ; break ; case ',' : case '+' : case '<' : case '>' : case ';' : case '#' : case '=' : buf . append ( '\\' ) ; buf . append ( ch ) ; break ; default : buf . append ( ch ) ; break ; } } return buf . toString ( ) ; }
escapes : 1 ) chars " , " , " + " , " " " , " \ " , " < " , " > " , " ; " ( rfc 2253 ) 2 ) chars " # " , " = " ( required by rfc 1779 ) 3 ) a space char at the beginning or end 4 ) according to the requirement to be rfc 1779 compatible : ' # ' char is escaped in any position
