public static String escape ( char c ) { switch ( c ) { case ' ' : return "\\b" ; case ' ' : return "\\t" ; case ' ' : return "\\n" ; case ' ' : return "\\f" ; case ' ' : return "\\r" ; case ' ' : return "\\\"" ; case ' ' : return "\\'" ; case ' ' : return "\\\\" ; default : if ( c < 32 || c == 127 ) { return String . format ( "\\%03o" , ( int ) c ) ; } else if ( ! isConsolePrintable ( c ) || isHighSurrogate ( c ) || isLowSurrogate ( c ) ) { return String . format ( "\\u%04x" , ( int ) c ) ; } return String . valueOf ( c ) ; } }
Escape a single character . It is escaped into a string as it may become more than one char when escaped .