protected String addEscapes ( final String str ) { final StringBuilder sb = new StringBuilder ( ) ; char ch ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { ch = str . charAt ( i ) ; switch ( ch ) { case 0 : continue ; case ' ' : sb . append ( "\\b" ) ; continue ; case ' ' : sb . append ( "\\t" ) ; continue ; case ' ' : sb . append ( "\\n" ) ; continue ; case ' ' : sb . append ( "\\f" ) ; continue ; case ' ' : sb . append ( "\\r" ) ; continue ; case ' ' : sb . append ( "\\\"" ) ; continue ; case ' ' : sb . append ( "\\\'" ) ; continue ; case ' ' : sb . append ( "\\\\" ) ; continue ; default : if ( ch < 0x20 || ch > 0x7e ) { final String s = "0000" + Integer . toString ( ch , 16 ) ; sb . append ( "\\u" + s . substring ( s . length ( ) - 4 , s . length ( ) ) ) ; } else { sb . append ( ch ) ; } continue ; } } return sb . toString ( ) ; }
Escapes some chars in the given string .