Skip to content

Commit 75bd702

Browse files
committed
CSV-74 - CSVFormat definitions are difficult to read and maintain
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1303488 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9fb2b4f commit 75bd702

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,23 @@ public class CSVFormat implements Serializable {
5151
*/
5252
static final char DISABLED = '\ufffe';
5353

54+
/**
55+
* Starting format with no settings defined; used for creating other formats from scratch.
56+
*/
57+
private static CSVFormat PRISTINE =
58+
new CSVFormat(DISABLED, DISABLED, DISABLED, DISABLED, false, false, false, null, null);
59+
5460
/** Standard comma separated format as defined by <a href="http://tools.ietf.org/html/rfc4180">RFC 4180</a>. */
55-
public static final CSVFormat DEFAULT = new CSVFormat(',', '"', DISABLED, DISABLED, true, true, true, CRLF, null);
61+
public static final CSVFormat DEFAULT =
62+
PRISTINE.
63+
withDelimiter(',')
64+
.withEncapsulator('"')
65+
.withLeadingSpacesIgnored(true)
66+
.withTrailingSpacesIgnored(true)
67+
.withEmptyLinesIgnored(true)
68+
.withLineSeparator(CRLF)
69+
;
70+
5671

5772
/**
5873
* Excel file format (using a comma as the value delimiter).
@@ -65,10 +80,23 @@ public class CSVFormat implements Serializable {
6580
*
6681
* <pre>CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';');</pre>
6782
*/
68-
public static final CSVFormat EXCEL = new CSVFormat(',', '"', DISABLED, DISABLED, false, false, false, CRLF, null);
83+
public static final CSVFormat EXCEL =
84+
PRISTINE
85+
.withDelimiter(',')
86+
.withEncapsulator('"')
87+
.withLineSeparator(CRLF)
88+
;
6989

7090
/** Tab-delimited format, with quote; leading and trailing spaces ignored. */
71-
public static final CSVFormat TDF = new CSVFormat('\t', '"', DISABLED, DISABLED, true, true, true, CRLF, null);
91+
public static final CSVFormat TDF =
92+
PRISTINE
93+
.withDelimiter('\t')
94+
.withEncapsulator('"')
95+
.withLeadingSpacesIgnored(true)
96+
.withTrailingSpacesIgnored(true)
97+
.withEmptyLinesIgnored(true)
98+
.withLineSeparator(CRLF)
99+
;
72100

73101
/**
74102
* Default MySQL format used by the <tt>SELECT INTO OUTFILE</tt> and
@@ -78,7 +106,12 @@ public class CSVFormat implements Serializable {
78106
*
79107
* @see <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
80108
*/
81-
public static final CSVFormat MYSQL = new CSVFormat('\t', DISABLED, DISABLED, '\\', false, false, false, "\n", null);
109+
public static final CSVFormat MYSQL =
110+
PRISTINE
111+
.withDelimiter('\t')
112+
.withEscape('\\')
113+
.withLineSeparator("\n")
114+
;
82115

83116

84117
/**

0 commit comments

Comments
 (0)