static String debugEncode(String input){
  final int n=input.length();
  StringBuilder buf=new StringBuilder(n * 2);
  for (int i=0; i < n; ++i) {
    char ch=input.charAt(i);
switch (ch) {
case '\\':
      buf.append("\\\\");
    break;
case '\'':
  buf.append("\\\'");
break;
case '\"':
buf.append("\\\"");
break;
case '\r':
buf.append("\\r");
break;
case '\n':
buf.append("\\n");
break;
case '\t':
buf.append("\\t");
break;
default :
if (' ' <= ch && ch <= '~') {
buf.append(ch);
}
 else {
buf.append(String.format("\\u%04x",(int)ch));
}
break;
}
}
return buf.toString();
}

static String debugEncode ( String input ) { final int n = input . length ( ) ; StringBuilder buf = new StringBuilder ( n * 2 ) ; for ( int i = 0 ; i < n ; ++ i ) { char ch = input . charAt ( i ) ; switch ( ch ) { case '\\' : buf . append ( "\\\\" ) ; break ; case '\'' : buf . append ( "\\\'" ) ; break ; case '\"' : buf . append ( "\\\"" ) ; break ; case '\r' : buf . append ( "\\r" ) ; break ; case '\n' : buf . append ( "\\n" ) ; break ; case '\t' : buf . append ( "\\t" ) ; break ; default : if ( ' ' <= ch && ch <= '~' ) { buf . append ( ch ) ; } else { buf . append ( String . format ( "\\u%04x" , ( int ) ch ) ) ; } break ; } } return buf . toString ( ) ; }
java / javascript - style encoder for helping debug unit test results . we should not rely upon the code being tested for helping - - not that it would hurt the testing , only it might effect coverage metrics .
