From 0d63758e095d2a671d0ba10fc8cae141add29a45 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Tue, 20 Jul 2010 21:16:37 +0000 Subject: [PATCH] SANDBOX-322: remember to print separators everywhere git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@966014 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVPrinter.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) 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; }