Skip to content

Commit 699b858

Browse files
committed
Call append once
Better comments
1 parent 5e5e28c commit 699b858

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,28 +2323,32 @@ private void printWithQuotes(final Reader reader, final Appendable appendable) t
23232323
return;
23242324
}
23252325
final char quote = getQuoteCharacter().charValue();
2326+
// (1) Append opening quote
23262327
append(quote, appendable);
2328+
// (2) Append Reader content
23272329
final StringBuilder builder = new StringBuilder(IOUtils.DEFAULT_BUFFER_SIZE);
23282330
int c;
23292331
int pos = 0;
23302332
while (EOF != (c = reader.read())) {
23312333
builder.append((char) c);
23322334
if (c == quote) {
2333-
// write out segment up until this char
2335+
// Append current segment
23342336
if (pos > 0) {
2335-
append(builder.substring(0, pos), appendable);
2336-
append(quote, appendable);
2337+
append(builder.toString(), appendable);
2338+
// Recycle builder
23372339
builder.setLength(0);
23382340
pos = -1;
23392341
}
2340-
append((char) c, appendable);
2342+
// Append nested quote
2343+
append(quote, appendable);
23412344
}
23422345
pos++;
23432346
}
2344-
// write last segment
2347+
// Append last segment
23452348
if (pos > 0) {
23462349
append(builder.substring(0, pos), appendable);
23472350
}
2351+
// (3) Append closing quote
23482352
append(quote, appendable);
23492353
}
23502354

0 commit comments

Comments
 (0)