private void escapeValueTo ( final String field , final StringBuilder target ) { if ( field == null ) { target . append ( DETAILS_QUOTE_CHAR ) ; target . append ( DETAILS_QUOTE_CHAR ) ; return ; } target . append ( DETAILS_QUOTE_CHAR ) ; if ( field . indexOf ( DETAILS_ESCAPE_CHAR ) == - 1 && field . indexOf ( DETAILS_QUOTE_CHAR ) == - 1 ) { target . append ( field ) ; } else { final int len = field . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { final char charAt = field . charAt ( i ) ; if ( charAt == DETAILS_ESCAPE_CHAR || charAt == DETAILS_QUOTE_CHAR ) { target . append ( DETAILS_ESCAPE_CHAR ) ; } target . append ( charAt ) ; } } target . append ( DETAILS_QUOTE_CHAR ) ; }
Escapes value for a CSV line and appends it to the target .