You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/05/07 11:09:11 UTC
svn commit: r1479823 -
/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
Author: sebb
Date: Tue May 7 09:09:11 2013
New Revision: 1479823
URL: http://svn.apache.org/r1479823
Log:
Simplify code so delimiter only printed in one place
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java?rev=1479823&r1=1479822&r2=1479823&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java Tue May 7 09:09:11 2013
@@ -163,35 +163,28 @@ public class CSVPrinter implements Flush
private void print(final Object object, final CharSequence value,
final int offset, final int len) throws IOException {
+ if (!newRecord) {
+ out.append(format.getDelimiter());
+ }
if (format.isQuoting()) {
// the original object is needed so can check for Number
printAndQuote(object, value, offset, len);
} else if (format.isEscaping()) {
printAndEscape(value, offset, len);
} else {
- printDelimiter();
out.append(value, offset, offset + len);
}
- }
-
- void printDelimiter() throws IOException {
- if (newRecord) {
- newRecord = false;
- } else {
- out.append(format.getDelimiter());
- }
+ newRecord = false;
}
/*
* Note: must only be called if escaping is enabled, otherwise will generate NPE
*/
- void printAndEscape(final CharSequence value, final int offset, final int len) throws IOException {
+ private void printAndEscape(final CharSequence value, final int offset, final int len) throws IOException {
int start = offset;
int pos = offset;
final int end = offset + len;
- printDelimiter();
-
final char delim = format.getDelimiter();
final char escape = format.getEscape().charValue();
@@ -227,16 +220,13 @@ public class CSVPrinter implements Flush
* Note: must only be called if quoting is enabled, otherwise will generate NPE
*/
// the original object is needed so can check for Number
- void printAndQuote(final Object object, final CharSequence value,
+ private void printAndQuote(final Object object, final CharSequence value,
final int offset, final int len) throws IOException {
- final boolean first = newRecord; // is this the first value on this line?
boolean quote = false;
int start = offset;
int pos = offset;
final int end = offset + len;
- printDelimiter();
-
final char delimChar = format.getDelimiter();
final char quoteChar = format.getQuoteChar().charValue();
@@ -259,14 +249,14 @@ public class CSVPrinter implements Flush
// on the line, as it may be the only thing on the
// line. If it were not quoted in that case,
// an empty line has no tokens.
- if (first) {
+ if (newRecord) {
quote = true;
}
} else {
char c = value.charAt(pos);
// Hmmm, where did this rule come from?
- if (first && (c < '0' || (c > '9' && c < 'A') || (c > 'Z' && c < 'a') || (c > 'z'))) {
+ if (newRecord && (c < '0' || (c > '9' && c < 'A') || (c > 'Z' && c < 'a') || (c > 'z'))) {
quote = true;
// } else if (c == ' ' || c == '\f' || c == '\t') {
} else if (c <= COMMENT) {