Skip to content

Commit

Permalink
optmize code
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Dec 24, 2023
1 parent b2d90ec commit c5be766
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/src/main/java/de/siegmar/fastcsv/writer/CsvWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,18 @@ private static void writeEscaped(final Writer w, final String value, final char
throws IOException {

int startPos = 0;
while (true) {
final int nextDelimPos = value.indexOf(quoteChar, startPos);
int nextDelimPos = value.indexOf(quoteChar, startPos);

if (nextDelimPos == -1) {
w.write(value, startPos, value.length() - startPos);
break;
}

final int len = nextDelimPos - startPos + 1;
w.write(value, startPos, len);
while (nextDelimPos != -1) {
// Write up to and including the delimiter
w.write(value, startPos, nextDelimPos - startPos + 1);
w.write(quoteChar);
startPos += len;
startPos = nextDelimPos + 1;
nextDelimPos = value.indexOf(quoteChar, startPos);
}

// Write the rest of the string
w.write(value, startPos, value.length() - startPos);
}

/**
Expand Down Expand Up @@ -229,7 +228,7 @@ private void writeCommentInternal(final String comment) throws IOException {

int startPos = 0;
boolean lastCharWasCR = false;
for (int i = 0; i < comment.length(); i++) {
for (int i = 0; i < length; i++) {
final char c = comment.charAt(i);
if (c == CR) {
final int len = i - startPos;
Expand Down

0 comments on commit c5be766

Please sign in to comment.