public static String quote ( String s , String nullResult ) { if ( s == null ) { return nullResult ; } StringBuffer result = new StringBuffer ( ) ; result . append ( ' ' ) ; int length = s . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { char c = s . charAt ( i ) ; switch ( c ) { case ' ' : { result . append ( "\\b" ) ; break ; } case ' ' : { result . append ( "\\f" ) ; break ; } case ' ' : { result . append ( "\\n" ) ; break ; } case ' ' : { result . append ( "\\r" ) ; break ; } case ' ' : { result . append ( "\\t" ) ; break ; } case ' ' : { result . append ( "\\\\" ) ; break ; } case ' ' : { result . append ( "\\\"" ) ; break ; } default : { if ( c < ' ' || c >= ' ' ) { String n = Integer . toHexString ( c ) ; result . append ( "\\u" ) ; result . append ( "0000" . substring ( n . length ( ) ) ) ; result . append ( n ) ; } else { result . append ( c ) ; } } } } result . append ( ' ' ) ; return result . toString ( ) ; }
Returns a quoted version of a given string i . e . as a Java String Literal .