private void printWithQuotes()

in src/main/java/org/apache/commons/csv/CSVFormat.java [2175:2212]


    private void printWithQuotes(final Reader reader, final Appendable appendable) throws IOException {

        if (getQuoteMode() == QuoteMode.NONE) {
            printWithEscapes(reader, appendable);
            return;
        }

        int pos = 0;

        final char quote = getQuoteCharacter().charValue();
        final StringBuilder builder = new StringBuilder(IOUtils.DEFAULT_BUFFER_SIZE);

        append(quote, appendable);

        int c;
        while (-1 != (c = reader.read())) {
            builder.append((char) c);
            if (c == quote) {
                // write out segment up until this char
                if (pos > 0) {
                    append(builder.substring(0, pos), appendable);
                    append(quote, appendable);
                    builder.setLength(0);
                    pos = -1;
                }

                append((char) c, appendable);
            }
            pos++;
        }

        // write last segment
        if (pos > 0) {
            append(builder.substring(0, pos), appendable);
        }

        append(quote, appendable);
    }