question: private static String quote ( String value ) { boolean needsQuotes = false ; int length = value . length ( ) ; for ( int i = 0 ; ( i < length ) && ! needsQuotes ; ++ i ) { needsQuotes = ! isTokenChar ( value . charAt ( i ) ) ; } if ( needsQuotes ) { StringBuilder buffer = new StringBuilder ( ( int ) ( length * 1.5 ) ) ; buffer . append ( '"' ) ; for ( int i = 0 ; i < length ; ++ i ) { char c = value . charAt ( i ) ; if ( ( c == '\\' ) || ( c == '"' ) ) { buffer . append ( '\\' ) ; } buffer . append ( c ) ; } buffer . append ( '"' ) ; return buffer . toString ( ) ; } else { return value ; } }
target:  A routine that knows how and when to quote and escape the given value.