protected String add_escapes ( String str ) { StringBuffer retval = new StringBuffer ( ) ; char ch ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { switch ( str . charAt ( i ) ) { case 0 : continue ; case ' ' : retval . append ( "\\b" ) ; continue ; case ' ' : retval . append ( "\\t" ) ; continue ; case ' ' : retval . append ( "\\n" ) ; continue ; case ' ' : retval . append ( "\\f" ) ; continue ; case ' ' : retval . append ( "\\r" ) ; continue ; case ' ' : retval . append ( "\\\"" ) ; continue ; case ' ' : retval . append ( "\\\'" ) ; continue ; case ' ' : retval . append ( "\\\\" ) ; continue ; default : if ( ( ch = str . charAt ( i ) ) < 0x20 || ch > 0x7e ) { String s = "0000" + Integer . toString ( ch , 16 ) ; retval . append ( "\\u" + s . substring ( s . length ( ) - 4 , s . length ( ) ) ) ; } else { retval . append ( ch ) ; } continue ; } } return retval . toString ( ) ; }
Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal .