public static void appendString ( final StringBuffer buf , final String s ) { buf . append ( ' ' ) ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; if ( c == ' ' ) { buf . append ( "\\n" ) ; } else if ( c == ' ' ) { buf . append ( "\\r" ) ; } else if ( c == ' ' ) { buf . append ( "\\\\" ) ; } else if ( c == ' ' ) { buf . append ( "\\\"" ) ; } else if ( c < 0x20 || c > 0x7f ) { buf . append ( "\\u" ) ; if ( c < 0x10 ) { buf . append ( "000" ) ; } else if ( c < 0x100 ) { buf . append ( "00" ) ; } else if ( c < 0x1000 ) { buf . append ( ' ' ) ; } buf . append ( Integer . toString ( c , 16 ) ) ; } else { buf . append ( c ) ; } } buf . append ( ' ' ) ; }
Appends a quoted string to a given buffer .