diff --git a/src/java/org/apache/commons/csv/CSVPrinter.java b/src/java/org/apache/commons/csv/CSVPrinter.java index 9d86b366..2193c11e 100644 --- a/src/java/org/apache/commons/csv/CSVPrinter.java +++ b/src/java/org/apache/commons/csv/CSVPrinter.java @@ -124,20 +124,17 @@ public class CSVPrinter { public void print(char[] value, int offset, int len, boolean checkForEscape) throws IOException { if (!checkForEscape) { - if (newLine) { - newLine = false; - } else { - out.write(this.strategy.getDelimiter()); - } + printSep(); out.write(value, offset, len); return; } - if (strategy.getEncapsulator() != (char)-2) { + if (strategy.getEncapsulator() != CSVStrategy.ENCAPSULATOR_DISABLED) { printAndEncapsulate(value, offset, len); - } else if (strategy.getEscape() != (char)-2) { + } else if (strategy.getEscape() != CSVStrategy.ESCAPE_DISABLED) { printAndEscape(value, offset, len); } else { + printSep(); out.write(value, offset, len); } } @@ -155,11 +152,11 @@ public class CSVPrinter { int pos = offset; int end = offset + len; + printSep(); + char delim = this.strategy.getDelimiter(); char escape = this.strategy.getEscape(); - printSep(); - while (pos < end) { char c = value[pos]; if (c == '\r' || c=='\n' || c==delim || c==escape) { @@ -194,11 +191,11 @@ public class CSVPrinter { int pos = offset; int end = offset + len; + printSep(); + char delim = this.strategy.getDelimiter(); char encapsulator = this.strategy.getEncapsulator(); - printSep(); - if (len <= 0) { // always quote an empty token that is the first // on the line, as it may be the only thing on the @@ -285,6 +282,7 @@ public class CSVPrinter { public void print(String value, boolean checkForEscape) throws IOException { if (!checkForEscape) { // write directly from string + printSep(); out.write(value); return; }